Ticket #18174: ticket_18174_tests.diff

File ticket_18174_tests.diff, 2.4 KB (added by akaariai, 3 years ago)
  • tests/regressiontests/queries/models.py

    diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py
    index 8c34b50..40270c3 100644
    a b class NullableName(models.Model): 
    357357
    358358    class Meta:
    359359        ordering = ['id']
     360
     361
     362class Base1(models.Model):
     363    b1_id = models.AutoField(primary_key=True)
     364    b1_desc = models.CharField(max_length=100, null=True)
     365
     366class Base2(models.Model):
     367    b2_id = models.AutoField(primary_key=True)
     368    b2_desc = models.CharField(max_length=100, null=True)
     369
     370class Base3(models.Model):
     371    b3_id = models.AutoField(primary_key=True)
     372    b3_desc = models.CharField(max_length=100, null=True)
     373
     374class Middle(Base1, Base2, Base3):
     375    m_desc = models.CharField(max_length=100, null=True)
     376
     377class Top(Middle):
     378    t_desc = models.CharField(max_length=100)
  • tests/regressiontests/queries/tests.py

    diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py
    index 9bb3a29..d09e422 100644
    a b from .models import (Annotation, Article, Author, Celebrity, Child, Cover, 
    2323    Ranking, Related, Report, ReservedName, Tag, TvChef, Valid, X, Food, Eaten,
    2424    Node, ObjectA, ObjectB, ObjectC, CategoryItem, SimpleCategory,
    2525    SpecialCategory, OneToOneCategory, NullableName, ProxyCategory,
    26     SingleObject, RelatedObject)
     26    SingleObject, RelatedObject, Top, Base1)
    2727
    2828
    2929class BaseQuerysetTest(TestCase):
    class Queries1Tests(BaseQuerysetTest): 
    847847        )
    848848        Tag._meta.ordering = original_ordering
    849849
     850    def test_ticket18174(self):
     851        """
     852        Check that in a model like this:
     853                         / Base1
     854            Top -> Middle- Base2
     855                         \ Base3
     856
     857        The joins are done from Top to Middle to Base1, Base2, Base3.
     858        """
     859        Base1.objects.create()
     860        Top.objects.create(t_desc='foo')
     861        qs = Top.objects.all()
     862        # The joins to the parent tables are added only when the query is
     863        # evaluated.
     864        results = list(qs)
     865        self.assertEqual(qs.query.alias_map['queries_base1'].lhs_alias, 'queries_middle')
     866        self.assertEqual(len(results), 1)
     867
    850868    def test_exclude(self):
    851869        self.assertQuerysetEqual(
    852870            Item.objects.exclude(tags__name='t4'),
Back to Top