Ticket #16603: 16603_tests.patch

File 16603_tests.patch, 993 bytes (added by akaariai, 4 years ago)
  • tests/regressiontests/aggregation_regress/tests.py

    diff --git a/tests/regressiontests/aggregation_regress/tests.py b/tests/regressiontests/aggregation_regress/tests.py
    index 49e1e61..0c59391 100644
    a b class AggregationTests(TestCase): 
    861861            ['Peter Norvig'],
    862862            lambda b: b.name
    863863        )
     864
     865    def test_reverse_filter(self):
     866        # foreign key
     867        qs = Author.objects.annotate(
     868            contact_book_pages=Sum('book_contact_set__pages'))
     869        qs = qs.filter(name='Peter Norvig')
     870        qs2 = qs.filter(book_contact_set__pages__gte=0)
     871        self.assertEquals(qs[0].contact_book_pages, qs2[0].contact_book_pages)
     872        # m2m
     873        qs = Author.objects.annotate(pages_written=Sum('book__pages'))
     874        qs = qs.filter(name='Peter Norvig')
     875        qs2 = qs.filter(book__pubdate__lt='2011-01-01')
     876        self.assertEquals(qs[0].pages_written, qs2[0].pages_written)
Back to Top