diff options
| author | Edward Henderson <kutenai@me.com> | 2015-04-14 08:51:48 -0600 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-04-14 18:56:50 -0400 |
| commit | 910638fc4e4f83bda31dd91db5017acb06dfc8d2 (patch) | |
| tree | fd6dee49c489fcebbbaae9ce938b7008816f40da /tests | |
| parent | d72e0178e9930c9967c6fe6cd8c94b3413a240f9 (diff) | |
Refs #24385 -- Added tests for distinct sum issue fixed in c7fd9b242d2d63406f1de6cc3204e35aaa025233
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/aggregation/tests.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py index 424b7a7ccc..3e2bc2eb30 100644 --- a/tests/aggregation/tests.py +++ b/tests/aggregation/tests.py @@ -441,6 +441,20 @@ class AggregateTestCase(TestCase): vals = Book.objects.annotate(num_authors=Count("authors__id")).aggregate(Avg("num_authors")) self.assertEqual(vals, {"num_authors__avg": Approximate(1.66, places=1)}) + def test_sum_distinct_aggregate(self): + """ + Sum on a distict() QuerySet should aggregate only the distinct items. + """ + authors = Author.objects.filter(book__in=[5, 6]) + self.assertEqual(authors.count(), 3) + + distinct_authors = authors.distinct() + self.assertEqual(distinct_authors.count(), 2) + + # Selected author ages are 57 and 46 + age_sum = distinct_authors.aggregate(Sum('age')) + self.assertEqual(age_sum['age__sum'], 103) + def test_filtering(self): p = Publisher.objects.create(name='Expensive Publisher', num_awards=0) Book.objects.create( |
