summaryrefslogtreecommitdiff
path: root/tests/expressions_case
diff options
context:
space:
mode:
authorAnssi Kääriäinen <akaariai@gmail.com>2015-05-11 10:02:41 +0300
committerTim Graham <timograham@gmail.com>2015-05-11 11:16:16 -0400
commitbe9d645346a20a6c394bf70d47b1b1d5c81ff530 (patch)
tree85e6fc477d04e97c9d0fad9399fb6f2a15e70e63 /tests/expressions_case
parent8e86d9d3dfd68bebbfd1dd5006e0c25696855269 (diff)
downloaddjango-be9d645346a20a6c394bf70d47b1b1d5c81ff530.tar.gz
Fixed #24766 -- Added join promotion for Case expressions
Diffstat (limited to 'tests/expressions_case')
-rw-r--r--tests/expressions_case/tests.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/expressions_case/tests.py b/tests/expressions_case/tests.py
index 2c3186f10e..3479932865 100644
--- a/tests/expressions_case/tests.py
+++ b/tests/expressions_case/tests.py
@@ -1016,6 +1016,38 @@ class CaseExpressionTests(TestCase):
transform=attrgetter('integer', 'test')
)
+ def test_join_promotion(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()
+ ),
+ ),
+ [(o, 3)],
+ lambda x: (x, x.foo)
+ )
+ # 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()
+ ),
+ ),
+ [(o, 2)],
+ lambda x: (x, x.foo)
+ )
+
class CaseDocumentationExamples(TestCase):
@classmethod