Code

Ticket #18174: ticket_18174_tests.diff

File ticket_18174_tests.diff, 2.4 KB (added by akaariai, 21 months ago)
Line 
1diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py
2index 8c34b50..40270c3 100644
3--- a/tests/regressiontests/queries/models.py
4+++ b/tests/regressiontests/queries/models.py
5@@ -357,3 +357,22 @@ class NullableName(models.Model):
6 
7     class Meta:
8         ordering = ['id']
9+
10+
11+class Base1(models.Model):
12+    b1_id = models.AutoField(primary_key=True)
13+    b1_desc = models.CharField(max_length=100, null=True)
14+
15+class Base2(models.Model):
16+    b2_id = models.AutoField(primary_key=True)
17+    b2_desc = models.CharField(max_length=100, null=True)
18+
19+class Base3(models.Model):
20+    b3_id = models.AutoField(primary_key=True)
21+    b3_desc = models.CharField(max_length=100, null=True)
22+
23+class Middle(Base1, Base2, Base3):
24+    m_desc = models.CharField(max_length=100, null=True)
25+
26+class Top(Middle):
27+    t_desc = models.CharField(max_length=100)
28diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py
29index 9bb3a29..d09e422 100644
30--- a/tests/regressiontests/queries/tests.py
31+++ b/tests/regressiontests/queries/tests.py
32@@ -23,7 +23,7 @@ from .models import (Annotation, Article, Author, Celebrity, Child, Cover,
33     Ranking, Related, Report, ReservedName, Tag, TvChef, Valid, X, Food, Eaten,
34     Node, ObjectA, ObjectB, ObjectC, CategoryItem, SimpleCategory,
35     SpecialCategory, OneToOneCategory, NullableName, ProxyCategory,
36-    SingleObject, RelatedObject)
37+    SingleObject, RelatedObject, Top, Base1)
38 
39 
40 class BaseQuerysetTest(TestCase):
41@@ -847,6 +847,24 @@ class Queries1Tests(BaseQuerysetTest):
42         )
43         Tag._meta.ordering = original_ordering
44 
45+    def test_ticket18174(self):
46+        """
47+        Check that in a model like this:
48+                         / Base1
49+            Top -> Middle- Base2
50+                         \ Base3
51+
52+        The joins are done from Top to Middle to Base1, Base2, Base3.
53+        """
54+        Base1.objects.create()
55+        Top.objects.create(t_desc='foo')
56+        qs = Top.objects.all()
57+        # The joins to the parent tables are added only when the query is
58+        # evaluated.
59+        results = list(qs)
60+        self.assertEqual(qs.query.alias_map['queries_base1'].lhs_alias, 'queries_middle')
61+        self.assertEqual(len(results), 1)
62+
63     def test_exclude(self):
64         self.assertQuerysetEqual(
65             Item.objects.exclude(tags__name='t4'),