summaryrefslogtreecommitdiff
path: root/tests/aggregation_regress
diff options
context:
space:
mode:
authorNick Pope <nick@nickpope.me.uk>2022-02-22 09:29:38 +0000
committerGitHub <noreply@github.com>2022-02-22 10:29:38 +0100
commit847f46e9bf88964484c8b76a10af753ea1018311 (patch)
tree13aced534cbae373f47cce8fce1444ad0e8e01d3 /tests/aggregation_regress
parent7ba6ebe9149ae38257d70100e8bfbfd0da189862 (diff)
downloaddjango-847f46e9bf88964484c8b76a10af753ea1018311.tar.gz
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_regress')
-rw-r--r--tests/aggregation_regress/tests.py16
1 files changed, 6 insertions, 10 deletions
diff --git a/tests/aggregation_regress/tests.py b/tests/aggregation_regress/tests.py
index 7b92b6d271..9582d90a96 100644
--- a/tests/aggregation_regress/tests.py
+++ b/tests/aggregation_regress/tests.py
@@ -471,12 +471,8 @@ class AggregationTests(TestCase):
def test_aggregate_annotation(self):
# Aggregates can be composed over annotations.
# The return type is derived from the composed aggregate
- vals = (
- Book.objects.all()
- .annotate(num_authors=Count("authors__id"))
- .aggregate(
- Max("pages"), Max("price"), Sum("num_authors"), Avg("num_authors")
- )
+ vals = Book.objects.annotate(num_authors=Count("authors__id")).aggregate(
+ Max("pages"), Max("price"), Sum("num_authors"), Avg("num_authors")
)
self.assertEqual(
vals,
@@ -588,10 +584,10 @@ class AggregationTests(TestCase):
"pubdate, publisher, publisher_id, rating, store, tags"
)
with self.assertRaisesMessage(FieldError, msg):
- Book.objects.all().aggregate(num_authors=Count("foo"))
+ Book.objects.aggregate(num_authors=Count("foo"))
with self.assertRaisesMessage(FieldError, msg):
- Book.objects.all().annotate(num_authors=Count("foo"))
+ Book.objects.annotate(num_authors=Count("foo"))
msg = (
"Cannot resolve keyword 'foo' into field. Choices are: authors, "
@@ -599,7 +595,7 @@ class AggregationTests(TestCase):
"pages, price, pubdate, publisher, publisher_id, rating, store, tags"
)
with self.assertRaisesMessage(FieldError, msg):
- Book.objects.all().annotate(num_authors=Count("authors__id")).aggregate(
+ Book.objects.annotate(num_authors=Count("authors__id")).aggregate(
Max("foo")
)
@@ -932,7 +928,7 @@ class AggregationTests(TestCase):
"the default name for another annotation."
)
with self.assertRaisesMessage(ValueError, msg):
- Book.objects.all().annotate(
+ Book.objects.annotate(
Avg("authors__age"), authors__age__avg=Avg("authors__age")
)