summaryrefslogtreecommitdiff
path: root/tests/expressions_case
diff options
context:
space:
mode:
authorMark Lavin <markdlavin@gmail.com>2015-06-05 10:48:57 -0400
committerTim Graham <timograham@gmail.com>2015-06-05 12:22:43 -0400
commit541f4ea546ad3065852db816769ba6b584e3f373 (patch)
treebfd7489250bc0aab3ccfd0547fdea7ed05231796 /tests/expressions_case
parentf0450c9b1298bf5f39e229aec76c9bf7d57d4479 (diff)
downloaddjango-541f4ea546ad3065852db816769ba6b584e3f373.tar.gz
Fixed #24924 -- Join promotion for multiple Case expressions
Diffstat (limited to 'tests/expressions_case')
-rw-r--r--tests/expressions_case/tests.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/expressions_case/tests.py b/tests/expressions_case/tests.py
index 31ec88c7ec..2b269b5893 100644
--- a/tests/expressions_case/tests.py
+++ b/tests/expressions_case/tests.py
@@ -1060,6 +1060,48 @@ class CaseExpressionTests(TestCase):
lambda x: (x, x.foo)
)
+ def test_join_promotion_multiple_annonations(self):
+ o = CaseTestModel.objects.create(integer=1, integer2=1, string='1')
+ # Testing that:
+ # 1. There isn't any object on the remote side of the fk_rel
+ # relation. If the query used inner joins, then the join to fk_rel
+ # would remove o from the results. So, in effect we are testing that
+ # we are promoting the fk_rel join to a left outer join here.
+ # 2. The default value of 3 is generated for the case expression.
+ self.assertQuerysetEqual(
+ CaseTestModel.objects.filter(pk=o.pk).annotate(
+ foo=Case(
+ When(fk_rel__pk=1, then=2),
+ default=3,
+ output_field=models.IntegerField()
+ ),
+ bar=Case(
+ When(fk_rel__pk=1, then=4),
+ default=5,
+ output_field=models.IntegerField()
+ ),
+ ),
+ [(o, 3, 5)],
+ lambda x: (x, x.foo, x.bar)
+ )
+ # Now 2 should be generated, as the fk_rel is null.
+ self.assertQuerysetEqual(
+ CaseTestModel.objects.filter(pk=o.pk).annotate(
+ foo=Case(
+ When(fk_rel__isnull=True, then=2),
+ default=3,
+ output_field=models.IntegerField()
+ ),
+ bar=Case(
+ When(fk_rel__isnull=True, then=4),
+ default=5,
+ output_field=models.IntegerField()
+ ),
+ ),
+ [(o, 2, 4)],
+ lambda x: (x, x.foo, x.bar)
+ )
+
def test_m2m_exclude(self):
CaseTestModel.objects.create(integer=10, integer2=1, string='1')
qs = CaseTestModel.objects.values_list('id', 'integer').annotate(