1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

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.
This commit is contained in:
Nick Pope
2022-02-22 09:29:38 +00:00
committed by GitHub
parent 7ba6ebe914
commit 847f46e9bf
47 changed files with 184 additions and 209 deletions

View File

@@ -690,7 +690,7 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
)
def test_diff_intersection_union(self):
geom = Point(5, 23, srid=4326)
qs = Country.objects.all().annotate(
qs = Country.objects.annotate(
difference=functions.Difference("mpoly", geom),
sym_difference=functions.SymDifference("mpoly", geom),
union=functions.Union("mpoly", geom),

View File

@@ -21,12 +21,12 @@ class GeoJSONSerializerTests(TestCase):
self.assertIn("geojson", public_formats)
def test_serialization_base(self):
geojson = serializers.serialize("geojson", City.objects.all().order_by("name"))
geojson = serializers.serialize("geojson", City.objects.order_by("name"))
geodata = json.loads(geojson)
self.assertEqual(len(geodata["features"]), len(City.objects.all()))
self.assertEqual(geodata["features"][0]["geometry"]["type"], "Point")
self.assertEqual(geodata["features"][0]["properties"]["name"], "Chicago")
first_city = City.objects.all().order_by("name").first()
first_city = City.objects.order_by("name").first()
self.assertEqual(geodata["features"][0]["properties"]["pk"], str(first_city.pk))
def test_geometry_field_option(self):
@@ -81,7 +81,7 @@ class GeoJSONSerializerTests(TestCase):
def test_srid_option(self):
geojson = serializers.serialize(
"geojson", City.objects.all().order_by("name"), srid=2847
"geojson", City.objects.order_by("name"), srid=2847
)
geodata = json.loads(geojson)
coordinates = geodata["features"][0]["geometry"]["coordinates"]

View File

@@ -217,7 +217,7 @@ class GeoModelTest(TestCase):
Test a dumpdata/loaddata cycle with geographic data.
"""
out = StringIO()
original_data = list(City.objects.all().order_by("name"))
original_data = list(City.objects.order_by("name"))
call_command("dumpdata", "geoapp.City", stdout=out)
result = out.getvalue()
houston = City.objects.get(name="Houston")
@@ -228,7 +228,7 @@ class GeoModelTest(TestCase):
tmp.write(result)
tmp.seek(0)
call_command("loaddata", tmp.name, verbosity=0)
self.assertEqual(original_data, list(City.objects.all().order_by("name")))
self.assertEqual(original_data, list(City.objects.order_by("name")))
@skipUnlessDBFeature("supports_empty_geometries")
def test_empty_geometries(self):
@@ -623,7 +623,7 @@ class GeoQuerySetTest(TestCase):
"""
Testing if extent supports limit.
"""
extent1 = City.objects.all().aggregate(Extent("point"))["point__extent"]
extent1 = City.objects.aggregate(Extent("point"))["point__extent"]
extent2 = City.objects.all()[:3].aggregate(Extent("point"))["point__extent"]
self.assertNotEqual(extent1, extent2)
@@ -633,7 +633,7 @@ class GeoQuerySetTest(TestCase):
"""
if not connection.features.supports_make_line_aggr:
with self.assertRaises(NotSupportedError):
City.objects.all().aggregate(MakeLine("point"))
City.objects.aggregate(MakeLine("point"))
return
# MakeLine on an inappropriate field returns simply None

View File

@@ -108,7 +108,7 @@ class RelatedGeoModelTest(TestCase):
select_related on a query over a model with an FK to a model subclass.
"""
# Regression test for #9752.
list(DirectoryEntry.objects.all().select_related())
list(DirectoryEntry.objects.select_related())
def test06_f_expressions(self):
"Testing F() expressions on GeometryFields."