diff options
| author | Josh Smeaton <josh.smeaton@gmail.com> | 2014-07-11 16:55:49 +1000 |
|---|---|---|
| committer | Anssi Kääriäinen <akaariai@gmail.com> | 2014-08-12 14:58:10 +0300 |
| commit | 5b0375ec3e7473fcc29c21003fef80c0d0be183f (patch) | |
| tree | dc8609cb7647827030adcb12c16a0d3de754f2df /tests | |
| parent | 954e7b8aad3f3925e63a0a156b7df7466895e073 (diff) | |
Fixed #23001 -- Fixed mixing defer and annotations
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/aggregation/tests.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py index 6ea10278f2..b1b6199ffa 100644 --- a/tests/aggregation/tests.py +++ b/tests/aggregation/tests.py @@ -88,6 +88,31 @@ class BaseAggregateTestCase(TestCase): ) self.assertEqual(b.mean_age, 34.5) + def test_annotate_defer(self): + qs = Book.objects.annotate( + page_sum=Sum("pages")).defer('name').filter(pk=1) + + rows = [ + (1, "159059725", 447, "The Definitive Guide to Django: Web Development Done Right") + ] + self.assertQuerysetEqual( + qs.order_by('pk'), rows, + lambda r: (r.id, r.isbn, r.page_sum, r.name) + ) + + def test_annotate_defer_select_related(self): + qs = Book.objects.select_related('contact').annotate( + page_sum=Sum("pages")).defer('name').filter(pk=1) + + rows = [ + (1, "159059725", 447, "Adrian Holovaty", + "The Definitive Guide to Django: Web Development Done Right") + ] + self.assertQuerysetEqual( + qs.order_by('pk'), rows, + lambda r: (r.id, r.isbn, r.page_sum, r.contact.name, r.name) + ) + def test_annotate_m2m(self): books = Book.objects.filter(rating__lt=4.5).annotate(Avg("authors__age")).order_by("name") self.assertQuerysetEqual( |
