summaryrefslogtreecommitdiff
path: root/tests/expressions_case
diff options
context:
space:
mode:
authorTom <tom@tomforb.es>2017-04-22 16:44:51 +0100
committerTim Graham <timograham@gmail.com>2017-08-12 17:58:28 -0400
commitb78d100fa62cd4fbbc70f2bae77c192cb36c1ccd (patch)
treebe1f272298c15c6a261e33dff7486b0c3727b407 /tests/expressions_case
parent489421b01562494ab506de5d30ea97d7b6b5df30 (diff)
Fixed #27849 -- Added filtering support to aggregates.
Diffstat (limited to 'tests/expressions_case')
-rw-r--r--tests/expressions_case/tests.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/expressions_case/tests.py b/tests/expressions_case/tests.py
index 20d1e801ec..090607e8b8 100644
--- a/tests/expressions_case/tests.py
+++ b/tests/expressions_case/tests.py
@@ -1255,6 +1255,15 @@ class CaseDocumentationExamples(TestCase):
)
self.assertEqual(
Client.objects.aggregate(
+ regular=models.Count('pk', filter=Q(account_type=Client.REGULAR)),
+ gold=models.Count('pk', filter=Q(account_type=Client.GOLD)),
+ platinum=models.Count('pk', filter=Q(account_type=Client.PLATINUM)),
+ ),
+ {'regular': 2, 'gold': 1, 'platinum': 3}
+ )
+ # This was the example before the filter argument was added.
+ self.assertEqual(
+ Client.objects.aggregate(
regular=models.Sum(Case(
When(account_type=Client.REGULAR, then=1),
output_field=models.IntegerField(),