Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions django/contrib/gis/db/backends/base/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ class BaseSpatialFeatures:
# for empty results?
empty_intersection_returns_none = True

@property
def supports_bbcontains_lookup(self):
return "bbcontains" in self.connection.ops.gis_operators

@property
def supports_contained_lookup(self):
return "contained" in self.connection.ops.gis_operators

@property
def supports_crosses_lookup(self):
return "crosses" in self.connection.ops.gis_operators
Expand All @@ -78,10 +70,6 @@ def supports_crosses_lookup(self):
def supports_distances_lookups(self):
return self.has_Distance_function

@property
def supports_dwithin_lookup(self):
return "dwithin" in self.connection.ops.gis_operators

@property
def supports_relate_lookup(self):
return "relate" in self.connection.ops.gis_operators
Expand Down
11 changes: 7 additions & 4 deletions tests/gis_tests/distapp/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature

from ..utils import FuncTestMixin
from ..utils import FuncTestMixin, skipUnlessGISLookup
from .models import (
AustraliaCity,
CensusZipcode,
Expand Down Expand Up @@ -65,7 +65,8 @@ def test_init(self):
self.assertEqual(1, Interstate.objects.count())
self.assertEqual(1, SouthTexasInterstate.objects.count())

@skipUnlessDBFeature("supports_dwithin_lookup")
@skipUnlessGISLookup("dwithin")
@skipUnlessDBFeature("has_Transform_function")
def test_dwithin(self):
"""
Test the `dwithin` lookup type.
Expand Down Expand Up @@ -322,7 +323,8 @@ def test_mysql_geodetic_distance_error(self):
point__distance_lte=(Point(0, 0), D(m=100))
).exists()

@skipUnlessDBFeature("supports_dwithin_lookup")
@skipUnlessGISLookup("dwithin")
@skipUnlessDBFeature("has_Transform_function")
def test_dwithin_subquery(self):
"""dwithin lookup in a subquery using OuterRef as a parameter."""
qs = CensusZipcode.objects.annotate(
Expand All @@ -334,7 +336,8 @@ def test_dwithin_subquery(self):
).filter(annotated_value=True)
self.assertEqual(self.get_names(qs), ["77002", "77025", "77401"])

@skipUnlessDBFeature("supports_dwithin_lookup", "supports_dwithin_distance_expr")
@skipUnlessGISLookup("dwithin")
@skipUnlessDBFeature("supports_dwithin_distance_expr")
def test_dwithin_with_expression_rhs(self):
# LineString of Wollongong and Adelaide coords.
ls = LineString(((150.902, -34.4245), (138.6, -34.9258)), srid=4326)
Expand Down
2 changes: 2 additions & 0 deletions tests/gis_tests/geoapp/test_regress.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.db.models import Count, Min
from django.test import TestCase, skipUnlessDBFeature

from ..utils import skipUnlessGISLookup
from .models import City, PennsylvaniaCity, State, Truth


Expand Down Expand Up @@ -66,6 +67,7 @@ def test_unicode_date(self):
founded, PennsylvaniaCity.objects.aggregate(Min("founded"))["founded__min"]
)

@skipUnlessGISLookup("contains")
def test_empty_count(self):
"""
Testing that PostGISAdapter.__eq__ does check empty strings. See
Expand Down
37 changes: 22 additions & 15 deletions tests/gis_tests/geoapp/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ def test_geometrycollectionfield(self):
class GeoLookupTest(TestCase):
fixtures = ["initial"]

@skipUnlessGISLookup("disjoint")
def test_disjoint_lookup(self):
"Testing the `disjoint` lookup type."
ptown = City.objects.get(name="Pueblo")
Expand All @@ -327,22 +328,22 @@ def test_disjoint_lookup(self):
self.assertEqual(1, qs2.count())
self.assertEqual("Kansas", qs2[0].name)

def test_contains_contained_lookups(self):
"Testing the 'contained', 'contains', and 'bbcontains' lookup types."
@skipUnlessGISLookup("contained")
def test_contained(self):
# Getting Texas, yes we were a country -- once ;)
texas = Country.objects.get(name="Texas")

# Seeing what cities are in Texas, should get Houston and Dallas,
# and Oklahoma City because 'contained' only checks on the
# _bounding box_ of the Geometries.
if connection.features.supports_contained_lookup:
qs = City.objects.filter(point__contained=texas.mpoly)
self.assertEqual(3, qs.count())
cities = ["Houston", "Dallas", "Oklahoma City"]
for c in qs:
self.assertIn(c.name, cities)

# Pulling out some cities.
qs = City.objects.filter(point__contained=texas.mpoly)
self.assertEqual(3, qs.count())
cities = ["Houston", "Dallas", "Oklahoma City"]
for c in qs:
self.assertIn(c.name, cities)

@skipUnlessGISLookup("contains")
def test_contains(self):
houston = City.objects.get(name="Houston")
wellington = City.objects.get(name="Wellington")
pueblo = City.objects.get(name="Pueblo")
Expand Down Expand Up @@ -371,13 +372,15 @@ def test_contains_contained_lookups(self):
len(Country.objects.filter(mpoly__contains=okcity.point.wkt)), 0
) # Query w/WKT

@skipUnlessGISLookup("bbcontains")
def test_bbcontains(self):
# OK City is contained w/in bounding box of Texas.
if connection.features.supports_bbcontains_lookup:
qs = Country.objects.filter(mpoly__bbcontains=okcity.point)
self.assertEqual(1, len(qs))
self.assertEqual("Texas", qs[0].name)
okcity = City.objects.get(name="Oklahoma City")
qs = Country.objects.filter(mpoly__bbcontains=okcity.point)
self.assertEqual(1, len(qs))
self.assertEqual("Texas", qs[0].name)

@skipUnlessDBFeature("supports_crosses_lookup")
@skipUnlessGISLookup("crosses")
def test_crosses_lookup(self):
Track.objects.create(name="Line1", line=LineString([(-95, 29), (-60, 0)]))
self.assertEqual(
Expand Down Expand Up @@ -470,6 +473,7 @@ def test_strictly_above_below_lookups(self):
lambda b: b.name,
)

@skipUnlessGISLookup("same_as", "equals")
def test_equals_lookups(self):
"Testing the 'same_as' and 'equals' lookup types."
pnt = fromstr("POINT (-95.363151 29.763374)", srid=4326)
Expand Down Expand Up @@ -658,6 +662,7 @@ def test_relate_lookup(self):
)
)

@skipUnlessDBFeature("has_Union_function")
def test_gis_lookups_with_complex_expressions(self):
multiple_arg_lookups = {
"dwithin",
Expand All @@ -671,6 +676,7 @@ def test_gis_lookups_with_complex_expressions(self):
**{"point__" + lookup: functions.Union("point", "point")}
).exists()

@skipUnlessGISLookup("within")
def test_subquery_annotation(self):
multifields = MultiFields.objects.create(
city=City.objects.create(point=Point(1, 1)),
Expand Down Expand Up @@ -825,6 +831,7 @@ def test_unionagg_tolerance_escaping(self):
Union("point", tolerance="0.05))), (((1"),
)

@skipUnlessGISLookup("within")
def test_within_subquery(self):
"""
Using a queryset inside a geo lookup is working (using a subquery)
Expand Down
3 changes: 3 additions & 0 deletions tests/gis_tests/relatedapp/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.test.utils import override_settings
from django.utils import timezone

from ..utils import skipUnlessGISLookup
from .models import Article, Author, Book, City, DirectoryEntry, Event, Location, Parcel


Expand Down Expand Up @@ -117,6 +118,7 @@ def test05_select_related_fk_to_subclass(self):
# Regression test for #9752.
list(DirectoryEntry.objects.select_related())

@skipUnlessGISLookup("within")
def test06_f_expressions(self):
"Testing F() expressions on GeometryFields."
# Constructing a dummy parcel border and getting the City instance for
Expand Down Expand Up @@ -229,6 +231,7 @@ def test09_pk_relations(self):
self.assertEqual(val_dict["id"], c_id)
self.assertEqual(val_dict["location__id"], l_id)

@skipUnlessGISLookup("within")
def test10_combine(self):
"Testing the combination of two QuerySets (#10807)."
buf1 = City.objects.get(name="Aurora").location.point.buffer(0.1)
Expand Down