#36883 new Cleanup/optimization

Split up aggregation_regress.tests.AggregationTests.test_more_more, test_more_more_more

Reported by: Tim Graham Owned by:
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

These tests are extremely long and most queries are independent and test different functionality. While working on the MongoDB backend, I found that only parts of the test need to be skipped (e.g. QuerySet.extra()), so I split up the test like this so the entire thing doesn't need to be skipped. Use this patch as a starting point, but give the tests more meaningful names.

  • tests/aggregation_regress/tests.py

    diff --git a/tests/aggregation_regress/tests.py b/tests/aggregation_regress/tests.py
    index c7d9271dd8..e2169be69d 100644
    a b class AggregationTests(TestCase):  
    849848            ],
    850849        )
    851850
    852     def test_more_more(self):
     851    def test_more_more1(self):
    853852        # Regression for #10113 - Fields mentioned in order_by() must be
    854853        # included in the GROUP BY. This only becomes a problem when the
    855854        # order_by introduces a new join.
    class AggregationTests(TestCase):  
    869868            lambda b: b.name,
    870869        )
    871870
     871    def test_more_more2(self):
    872872        # Regression for #10127 - Empty select_related() works with annotate
    873873        qs = (
    874874            Book.objects.filter(rating__lt=4.5)
    class AggregationTests(TestCase):  
    897897            lambda b: (b.name, b.authors__age__avg, b.publisher.name, b.contact.name),
    898898        )
    899899
     900    def test_more_more3(self):
    900901        # Regression for #10132 - If the values() clause only mentioned extra
    901902        # (select=) columns, those columns are used for grouping
    902903        qs = (
    class AggregationTests(TestCase):  
    931932            ],
    932933        )
    933934
     935    def test_more_more4(self):
    934936        # Regression for #10182 - Queries with aggregate calls are correctly
    935937        # realiased when used in a subquery
    936938        ids = (
    class AggregationTests(TestCase):  
    947949            lambda b: b.name,
    948950        )
    949951
     952    def test_more_more5(self):
    950953        # Regression for #15709 - Ensure each group_by field only exists once
    951954        # per query
    952955        qstr = str(
    class AggregationTests(TestCase):  
    10461049            query,
    10471050        )
    10481051
    1049     def test_more_more_more(self):
     1052    def test_more_more_more1(self):
    10501053        # Regression for #10199 - Aggregate calls clone the original query so
    10511054        # the original query can still be used
    10521055        books = Book.objects.all()
    class AggregationTests(TestCase):  
    10651068            lambda b: b.name,
    10661069        )
    10671070
     1071    def test_more_more_more2(self):
    10681072        # Regression for #10248 - Annotations work with dates()
    10691073        qs = (
    10701074            Book.objects.annotate(num_authors=Count("authors"))
    class AggregationTests(TestCase):  
    10791083            ],
    10801084        )
    10811085
     1086    def test_more_more_more3(self):
    10821087        # Regression for #10290 - extra selects with parameters can be used for
    10831088        # grouping.
    10841089        qs = (
    class AggregationTests(TestCase):  
    10911096            qs, [150, 175, 224, 264, 473, 566], lambda b: int(b["sheets"])
    10921097        )
    10931098
     1099    def test_more_more_more4(self):
    10941100        # Regression for 10425 - annotations don't get in the way of a count()
    10951101        # clause
    10961102        self.assertEqual(
    class AggregationTests(TestCase):  
    11001106            Book.objects.annotate(Count("publisher")).values("publisher").count(), 6
    11011107        )
    11021108
     1109    def test_more_more_more5(self):
    11031110        # Note: intentionally no order_by(), that case needs tests, too.
    11041111        publishers = Publisher.objects.filter(id__in=[self.p1.id, self.p2.id])
    11051112        self.assertEqual(sorted(p.name for p in publishers), ["Apress", "Sams"])
    class AggregationTests(TestCase):  
    11231130        )
    11241131        self.assertEqual(sorted(p.name for p in publishers), ["Apress", "Sams"])
    11251132
     1133    def test_more_more_more6(self):
    11261134        # Regression for 10666 - inherited fields work with annotations and
    11271135        # aggregations
    11281136        self.assertEqual(
    class AggregationTests(TestCase):  
    11751183            ],
    11761184        )
    11771185
     1186    def test_more_more_more7(self):
    11781187        # Regression for #10766 - Shouldn't be able to reference an aggregate
    11791188        # fields in an aggregate() call.
    11801189        msg = "Cannot compute Avg('mean_age'): 'mean_age' is an aggregate"

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top