diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/aggregation_regress/tests.py | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/tests/regressiontests/aggregation_regress/tests.py b/tests/regressiontests/aggregation_regress/tests.py index 33e37d6a9a..ec2603fe1e 100644 --- a/tests/regressiontests/aggregation_regress/tests.py +++ b/tests/regressiontests/aggregation_regress/tests.py @@ -4,8 +4,8 @@ from decimal import Decimal from operator import attrgetter from django.core.exceptions import FieldError +from django.db.models import Count, Max, Avg, Sum, StdDev, Variance, F, Q from django.test import TestCase, Approximate, skipUnlessDBFeature -from django.db.models import Count, Max, Avg, Sum, StdDev, Variance, F from models import Author, Book, Publisher, Clues, Entries, HardbackBook @@ -673,6 +673,58 @@ class AggregationTests(TestCase): list(qs), list(Book.objects.values_list("name", flat=True)) ) + def test_annotation_disjunction(self): + qs = Book.objects.annotate(n_authors=Count("authors")).filter( + Q(n_authors=2) | Q(name="Python Web Development with Django") + ) + self.assertQuerysetEqual( + qs, [ + "Artificial Intelligence: A Modern Approach", + "Python Web Development with Django", + "The Definitive Guide to Django: Web Development Done Right", + ], + attrgetter("name") + ) + + qs = Book.objects.annotate(n_authors=Count("authors")).filter( + Q(name="The Definitive Guide to Django: Web Development Done Right") | (Q(name="Artificial Intelligence: A Modern Approach") & Q(n_authors=3)) + ) + self.assertQuerysetEqual( + qs, [ + "The Definitive Guide to Django: Web Development Done Right", + ], + attrgetter("name") + ) + + qs = Publisher.objects.annotate( + rating_sum=Sum("book__rating"), + book_count=Count("book") + ).filter( + Q(rating_sum__gt=5.5) | Q(rating_sum__isnull=True) + ).order_by('pk') + self.assertQuerysetEqual( + qs, [ + "Apress", + "Prentice Hall", + "Jonno's House of Books", + ], + attrgetter("name") + ) + + qs = Publisher.objects.annotate( + rating_sum=Sum("book__rating"), + book_count=Count("book") + ).filter( + Q(pk__lt=F("book_count")) | Q(rating_sum=None) + ).order_by("pk") + self.assertQuerysetEqual( + qs, [ + "Apress", + "Jonno's House of Books", + ], + attrgetter("name") + ) + @skipUnlessDBFeature('supports_stddev') def test_stddev(self): self.assertEqual( |
