diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2017-06-29 18:25:36 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-06-29 18:25:36 +0200 |
| commit | 6e228d0b659c9779da7d392a75c7d2fbb42fb3cb (patch) | |
| tree | 5b3b59b7ec5f9e4f89fabf4e8a2ce7d4a294f4e3 /tests | |
| parent | f7f5edd50d03e8482f8a6da5fb5202b895d68cd6 (diff) | |
Fixed #28277 -- Added validation of QuerySet.annotate() and aggregate() args.
Thanks Tim Graham and Nick Pope for reviews.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/aggregation/tests.py | 9 | ||||
| -rw-r--r-- | tests/annotations/tests.py | 9 |
2 files changed, 18 insertions, 0 deletions
diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py index 8cf0596347..c3f7998f60 100644 --- a/tests/aggregation/tests.py +++ b/tests/aggregation/tests.py @@ -1186,3 +1186,12 @@ class AggregateTestCase(TestCase): ).filter(rating_or_num_awards__gt=F('num_awards')).order_by('num_awards') self.assertQuerysetEqual( qs2, [1, 3], lambda v: v.num_awards) + + def test_arguments_must_be_expressions(self): + msg = 'QuerySet.aggregate() received non-expression(s): %s.' + with self.assertRaisesMessage(TypeError, msg % FloatField()): + Book.objects.aggregate(FloatField()) + with self.assertRaisesMessage(TypeError, msg % True): + Book.objects.aggregate(is_book=True) + with self.assertRaisesMessage(TypeError, msg % ', '.join([str(FloatField()), 'True'])): + Book.objects.aggregate(FloatField(), Avg('price'), is_book=True) diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py index 981e73e43e..1714076e1d 100644 --- a/tests/annotations/tests.py +++ b/tests/annotations/tests.py @@ -508,3 +508,12 @@ class NonAggregateAnnotationTestCase(TestCase): self.assertIs(book.is_book, True) self.assertIs(book.is_pony, False) self.assertIsNone(book.is_none) + + def test_arguments_must_be_expressions(self): + msg = 'QuerySet.annotate() received non-expression(s): %s.' + with self.assertRaisesMessage(TypeError, msg % BooleanField()): + Book.objects.annotate(BooleanField()) + with self.assertRaisesMessage(TypeError, msg % True): + Book.objects.annotate(is_book=True) + with self.assertRaisesMessage(TypeError, msg % ', '.join([str(BooleanField()), 'True'])): + Book.objects.annotate(BooleanField(), Value(False), is_book=True) |
