diff options
| author | Nick Pope <nick@nickpope.me.uk> | 2022-02-22 09:29:38 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-22 10:29:38 +0100 |
| commit | 847f46e9bf88964484c8b76a10af753ea1018311 (patch) | |
| tree | 13aced534cbae373f47cce8fce1444ad0e8e01d3 /tests/aggregation | |
| parent | 7ba6ebe9149ae38257d70100e8bfbfd0da189862 (diff) | |
Removed redundant QuerySet.all() calls in docs and tests.
Most QuerySet methods are mapped onto the Manager and, in general,
it isn't necessary to call .all() on the manager.
Diffstat (limited to 'tests/aggregation')
| -rw-r--r-- | tests/aggregation/tests.py | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py index c71fedec1b..4ca8729a4b 100644 --- a/tests/aggregation/tests.py +++ b/tests/aggregation/tests.py @@ -178,7 +178,7 @@ class AggregateTestCase(TestCase): s3.books.add(cls.b3, cls.b4, cls.b6) def test_empty_aggregate(self): - self.assertEqual(Author.objects.all().aggregate(), {}) + self.assertEqual(Author.objects.aggregate(), {}) def test_aggregate_in_order_by(self): msg = ( @@ -209,11 +209,7 @@ class AggregateTestCase(TestCase): vals = Book.objects.filter(rating__lt=4.5).aggregate(Avg("authors__age")) self.assertEqual(vals, {"authors__age__avg": Approximate(38.2857, places=2)}) - vals = ( - Author.objects.all() - .filter(name__contains="a") - .aggregate(Avg("book__rating")) - ) + vals = Author.objects.filter(name__contains="a").aggregate(Avg("book__rating")) self.assertEqual(vals, {"book__rating__avg": 4.0}) vals = Book.objects.aggregate(Sum("publisher__num_awards")) @@ -1016,7 +1012,7 @@ class AggregateTestCase(TestCase): """ Aggregation over sliced queryset works correctly. """ - qs = Book.objects.all().order_by("-rating")[0:3] + qs = Book.objects.order_by("-rating")[0:3] vals = qs.aggregate(average_top3_rating=Avg("rating"))["average_top3_rating"] self.assertAlmostEqual(vals, 4.5, places=2) @@ -1026,8 +1022,7 @@ class AggregateTestCase(TestCase): select_related() stuff. """ qs = ( - Book.objects.all() - .select_for_update() + Book.objects.select_for_update() .order_by("pk") .select_related("publisher") .annotate(max_pk=Max("pk")) @@ -2047,14 +2042,14 @@ class AggregateTestCase(TestCase): self.assertEqual(result["num_awards__sum"], 20) def test_exists_none_with_aggregate(self): - qs = Book.objects.all().annotate( + qs = Book.objects.annotate( count=Count("id"), exists=Exists(Author.objects.none()), ) self.assertEqual(len(qs), 6) def test_exists_extra_where_with_aggregate(self): - qs = Book.objects.all().annotate( + qs = Book.objects.annotate( count=Count("id"), exists=Exists(Author.objects.extra(where=["1=0"])), ) |
