Opened 108 minutes ago
#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): 849 848 ], 850 849 ) 851 850 852 def test_more_more (self):851 def test_more_more1(self): 853 852 # Regression for #10113 - Fields mentioned in order_by() must be 854 853 # included in the GROUP BY. This only becomes a problem when the 855 854 # order_by introduces a new join. … … class AggregationTests(TestCase): 869 868 lambda b: b.name, 870 869 ) 871 870 871 def test_more_more2(self): 872 872 # Regression for #10127 - Empty select_related() works with annotate 873 873 qs = ( 874 874 Book.objects.filter(rating__lt=4.5) … … class AggregationTests(TestCase): 897 897 lambda b: (b.name, b.authors__age__avg, b.publisher.name, b.contact.name), 898 898 ) 899 899 900 def test_more_more3(self): 900 901 # Regression for #10132 - If the values() clause only mentioned extra 901 902 # (select=) columns, those columns are used for grouping 902 903 qs = ( … … class AggregationTests(TestCase): 931 932 ], 932 933 ) 933 934 935 def test_more_more4(self): 934 936 # Regression for #10182 - Queries with aggregate calls are correctly 935 937 # realiased when used in a subquery 936 938 ids = ( … … class AggregationTests(TestCase): 947 949 lambda b: b.name, 948 950 ) 949 951 952 def test_more_more5(self): 950 953 # Regression for #15709 - Ensure each group_by field only exists once 951 954 # per query 952 955 qstr = str( … … class AggregationTests(TestCase): 1046 1049 query, 1047 1050 ) 1048 1051 1049 def test_more_more_more (self):1052 def test_more_more_more1(self): 1050 1053 # Regression for #10199 - Aggregate calls clone the original query so 1051 1054 # the original query can still be used 1052 1055 books = Book.objects.all() … … class AggregationTests(TestCase): 1065 1068 lambda b: b.name, 1066 1069 ) 1067 1070 1071 def test_more_more_more2(self): 1068 1072 # Regression for #10248 - Annotations work with dates() 1069 1073 qs = ( 1070 1074 Book.objects.annotate(num_authors=Count("authors")) … … class AggregationTests(TestCase): 1079 1083 ], 1080 1084 ) 1081 1085 1086 def test_more_more_more3(self): 1082 1087 # Regression for #10290 - extra selects with parameters can be used for 1083 1088 # grouping. 1084 1089 qs = ( … … class AggregationTests(TestCase): 1091 1096 qs, [150, 175, 224, 264, 473, 566], lambda b: int(b["sheets"]) 1092 1097 ) 1093 1098 1099 def test_more_more_more4(self): 1094 1100 # Regression for 10425 - annotations don't get in the way of a count() 1095 1101 # clause 1096 1102 self.assertEqual( … … class AggregationTests(TestCase): 1100 1106 Book.objects.annotate(Count("publisher")).values("publisher").count(), 6 1101 1107 ) 1102 1108 1109 def test_more_more_more5(self): 1103 1110 # Note: intentionally no order_by(), that case needs tests, too. 1104 1111 publishers = Publisher.objects.filter(id__in=[self.p1.id, self.p2.id]) 1105 1112 self.assertEqual(sorted(p.name for p in publishers), ["Apress", "Sams"]) … … class AggregationTests(TestCase): 1123 1130 ) 1124 1131 self.assertEqual(sorted(p.name for p in publishers), ["Apress", "Sams"]) 1125 1132 1133 def test_more_more_more6(self): 1126 1134 # Regression for 10666 - inherited fields work with annotations and 1127 1135 # aggregations 1128 1136 self.assertEqual( … … class AggregationTests(TestCase): 1175 1183 ], 1176 1184 ) 1177 1185 1186 def test_more_more_more7(self): 1178 1187 # Regression for #10766 - Shouldn't be able to reference an aggregate 1179 1188 # fields in an aggregate() call. 1180 1189 msg = "Cannot compute Avg('mean_age'): 'mean_age' is an aggregate"
Note:
See TracTickets
for help on using tickets.