mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Removed redundant database vendor helpers in gis_tests/utils.py.
This commit is contained in:
committed by
Mariusz Felisiak
parent
9f91122ed8
commit
e3ece0144a
@@ -1,12 +1,9 @@
|
||||
from unittest import skipUnless
|
||||
|
||||
from django.contrib.gis.db.models import F, GeometryField, Value, functions
|
||||
from django.contrib.gis.geos import Point, Polygon
|
||||
from django.db import connection
|
||||
from django.db.models import Count, Min
|
||||
from django.test import TestCase, skipUnlessDBFeature
|
||||
|
||||
from ..utils import postgis
|
||||
from .models import City, ManyPointModel, MultiFields
|
||||
|
||||
|
||||
@@ -25,7 +22,7 @@ class GeoExpressionsTests(TestCase):
|
||||
self.assertTrue(point.equals_exact(p.transform(4326, clone=True), 10 ** -5))
|
||||
self.assertEqual(point.srid, 4326)
|
||||
|
||||
@skipUnless(postgis, 'Only postgis has geography fields.')
|
||||
@skipUnlessDBFeature('supports_geography')
|
||||
def test_geography_value(self):
|
||||
p = Polygon(((1, 1), (1, 2), (2, 2), (2, 1), (1, 1)))
|
||||
area = City.objects.annotate(a=functions.Area(Value(p, GeometryField(srid=4326, geography=True)))).first().a
|
||||
|
||||
@@ -12,7 +12,7 @@ from django.db import NotSupportedError, connection
|
||||
from django.db.models import IntegerField, Sum, Value
|
||||
from django.test import TestCase, skipUnlessDBFeature
|
||||
|
||||
from ..utils import FuncTestMixin, mariadb, mysql, oracle, postgis
|
||||
from ..utils import FuncTestMixin
|
||||
from .models import City, Country, CountryWebMercator, State, Track
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
|
||||
# WHERE "geoapp_city"."name" = 'Chicago';
|
||||
# Finally, we set every available keyword.
|
||||
# MariaDB doesn't limit the number of decimals in bbox.
|
||||
if mariadb:
|
||||
if connection.ops.mariadb:
|
||||
chicago_json['bbox'] = [-87.650175, 41.850385, -87.650175, 41.850385]
|
||||
self.assertJSONEqual(
|
||||
City.objects.annotate(
|
||||
@@ -105,7 +105,7 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
|
||||
qs.annotate(gml=functions.AsGML('name'))
|
||||
ptown = City.objects.annotate(gml=functions.AsGML('point', precision=9)).get(name='Pueblo')
|
||||
|
||||
if oracle:
|
||||
if connection.ops.oracle:
|
||||
# No precision parameter for Oracle :-/
|
||||
gml_regex = re.compile(
|
||||
r'^<gml:Point srsName="EPSG:4326" xmlns:gml="http://www.opengis.net/gml">'
|
||||
@@ -167,7 +167,7 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
|
||||
wkt = City.objects.annotate(
|
||||
wkt=functions.AsWKT(Point(1, 2, srid=4326)),
|
||||
).first().wkt
|
||||
self.assertEqual(wkt, 'POINT (1.0 2.0)' if oracle else 'POINT(1 2)')
|
||||
self.assertEqual(wkt, 'POINT (1.0 2.0)' if connection.ops.oracle else 'POINT(1 2)')
|
||||
|
||||
@skipUnlessDBFeature("has_Azimuth_function")
|
||||
def test_azimuth(self):
|
||||
@@ -184,11 +184,11 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
|
||||
# num_seg is the number of segments per quarter circle.
|
||||
return (4 * num_seg) + 1
|
||||
|
||||
expected_areas = (169, 136) if postgis else (171, 126)
|
||||
expected_areas = (169, 136) if connection.ops.postgis else (171, 126)
|
||||
qs = Country.objects.annotate(circle=functions.BoundingCircle('mpoly')).order_by('name')
|
||||
self.assertAlmostEqual(qs[0].circle.area, expected_areas[0], 0)
|
||||
self.assertAlmostEqual(qs[1].circle.area, expected_areas[1], 0)
|
||||
if postgis:
|
||||
if connection.ops.postgis:
|
||||
# By default num_seg=48.
|
||||
self.assertEqual(qs[0].circle.num_points, circle_num_points(48))
|
||||
self.assertEqual(qs[1].circle.num_points, circle_num_points(48))
|
||||
@@ -199,7 +199,7 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
|
||||
qs = Country.objects.annotate(
|
||||
circle=functions.BoundingCircle('mpoly', num_seg=num_seq),
|
||||
).order_by('name')
|
||||
if postgis:
|
||||
if connection.ops.postgis:
|
||||
self.assertGreater(qs[0].circle.area, 168.4, 0)
|
||||
self.assertLess(qs[0].circle.area, 169.5, 0)
|
||||
self.assertAlmostEqual(qs[1].circle.area, 136, 0)
|
||||
@@ -212,7 +212,7 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
|
||||
@skipUnlessDBFeature("has_Centroid_function")
|
||||
def test_centroid(self):
|
||||
qs = State.objects.exclude(poly__isnull=True).annotate(centroid=functions.Centroid('poly'))
|
||||
tol = 1.8 if mysql else (0.1 if oracle else 0.00001)
|
||||
tol = 1.8 if connection.ops.mysql else (0.1 if connection.ops.oracle else 0.00001)
|
||||
for state in qs:
|
||||
self.assertTrue(state.poly.centroid.equals_exact(state.centroid, tol))
|
||||
|
||||
@@ -224,7 +224,7 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
|
||||
geom = Point(5, 23, srid=4326)
|
||||
qs = Country.objects.annotate(diff=functions.Difference('mpoly', geom))
|
||||
# Oracle does something screwy with the Texas geometry.
|
||||
if oracle:
|
||||
if connection.ops.oracle:
|
||||
qs = qs.exclude(name='Texas')
|
||||
|
||||
for c in qs:
|
||||
@@ -236,7 +236,7 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
|
||||
geom = Point(556597.4, 2632018.6, srid=3857) # Spherical Mercator
|
||||
qs = Country.objects.annotate(difference=functions.Difference('mpoly', geom))
|
||||
# Oracle does something screwy with the Texas geometry.
|
||||
if oracle:
|
||||
if connection.ops.oracle:
|
||||
qs = qs.exclude(name='Texas')
|
||||
for c in qs:
|
||||
self.assertTrue(c.mpoly.difference(geom).equals(c.difference))
|
||||
@@ -396,9 +396,9 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
|
||||
|
||||
qs = City.objects.filter(point__isnull=False).annotate(num_geom=functions.NumGeometries('point'))
|
||||
for city in qs:
|
||||
# Oracle and PostGIS return 1 for the number of geometries on
|
||||
# non-collections, whereas MySQL returns None.
|
||||
if mysql:
|
||||
# The results for the number of geometries on non-collections
|
||||
# depends on the database.
|
||||
if connection.ops.mysql or connection.ops.mariadb:
|
||||
self.assertIsNone(city.num_geom)
|
||||
else:
|
||||
self.assertEqual(1, city.num_geom)
|
||||
@@ -519,7 +519,7 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
|
||||
geom = Point(5, 23, srid=4326)
|
||||
qs = Country.objects.annotate(sym_difference=functions.SymDifference('mpoly', geom))
|
||||
# Oracle does something screwy with the Texas geometry.
|
||||
if oracle:
|
||||
if connection.ops.oracle:
|
||||
qs = qs.exclude(name='Texas')
|
||||
for country in qs:
|
||||
self.assertTrue(country.mpoly.sym_difference(geom).equals(country.sym_difference))
|
||||
@@ -562,7 +562,7 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
|
||||
intersection=functions.Intersection('mpoly', geom),
|
||||
)
|
||||
|
||||
if oracle:
|
||||
if connection.ops.oracle:
|
||||
# Should be able to execute the queries; however, they won't be the same
|
||||
# as GEOS (because Oracle doesn't use GEOS internally like PostGIS or
|
||||
# SpatiaLite).
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
from unittest import skipUnless
|
||||
|
||||
from django.db import connection
|
||||
from django.db.models import Index
|
||||
from django.test import TransactionTestCase
|
||||
|
||||
from ..utils import mysql, oracle, postgis
|
||||
from .models import City
|
||||
|
||||
|
||||
@@ -22,17 +19,18 @@ class SchemaIndexesTests(TransactionTestCase):
|
||||
}
|
||||
|
||||
def has_spatial_indexes(self, table):
|
||||
if mysql:
|
||||
if connection.ops.mysql:
|
||||
with connection.cursor() as cursor:
|
||||
return connection.introspection.supports_spatial_index(cursor, table)
|
||||
elif oracle:
|
||||
elif connection.ops.oracle:
|
||||
# Spatial indexes in Meta.indexes are not supported by the Oracle
|
||||
# backend (see #31252).
|
||||
return False
|
||||
return True
|
||||
|
||||
@skipUnless(postgis, 'This is a PostGIS-specific test.')
|
||||
def test_using_sql(self):
|
||||
if not connection.ops.postgis:
|
||||
self.skipTest('This is a PostGIS-specific test.')
|
||||
index = Index(fields=['point'])
|
||||
editor = connection.schema_editor()
|
||||
self.assertIn(
|
||||
|
||||
@@ -13,9 +13,7 @@ from django.db.models import F, OuterRef, Subquery
|
||||
from django.test import TestCase, skipUnlessDBFeature
|
||||
from django.test.utils import CaptureQueriesContext
|
||||
|
||||
from ..utils import (
|
||||
mariadb, mysql, oracle, postgis, skipUnlessGISLookup, spatialite,
|
||||
)
|
||||
from ..utils import skipUnlessGISLookup
|
||||
from .models import (
|
||||
City, Country, Feature, MinusOneSRID, MultiFields, NonConcreteModel,
|
||||
PennsylvaniaCity, State, Track,
|
||||
@@ -109,7 +107,7 @@ class GeoModelTest(TestCase):
|
||||
# Constructing & querying with a point from a different SRID. Oracle
|
||||
# `SDO_OVERLAPBDYINTERSECT` operates differently from
|
||||
# `ST_Intersects`, so contains is used instead.
|
||||
if oracle:
|
||||
if connection.ops.oracle:
|
||||
tx = Country.objects.get(mpoly__contains=other_srid_pnt)
|
||||
else:
|
||||
tx = Country.objects.get(mpoly__intersects=other_srid_pnt)
|
||||
@@ -299,7 +297,7 @@ class GeoLookupTest(TestCase):
|
||||
invalid_geom = fromstr('POLYGON((0 0, 0 1, 1 1, 1 0, 1 1, 1 0, 0 0))')
|
||||
State.objects.create(name='invalid', poly=invalid_geom)
|
||||
qs = State.objects.all()
|
||||
if oracle or (mysql and connection.mysql_version < (8, 0, 0)):
|
||||
if connection.ops.oracle or (connection.ops.mysql and connection.mysql_version < (8, 0, 0)):
|
||||
# Kansas has adjacent vertices with distance 6.99244813842e-12
|
||||
# which is smaller than the default Oracle tolerance.
|
||||
# It's invalid on MySQL < 8 also.
|
||||
@@ -453,12 +451,11 @@ class GeoLookupTest(TestCase):
|
||||
with self.assertRaises(e):
|
||||
qs.count()
|
||||
|
||||
# Relate works differently for the different backends.
|
||||
if postgis or spatialite or mariadb:
|
||||
contains_mask = 'T*T***FF*'
|
||||
within_mask = 'T*F**F***'
|
||||
intersects_mask = 'T********'
|
||||
elif oracle:
|
||||
contains_mask = 'T*T***FF*'
|
||||
within_mask = 'T*F**F***'
|
||||
intersects_mask = 'T********'
|
||||
# Relate works differently on Oracle.
|
||||
if connection.ops.oracle:
|
||||
contains_mask = 'contains'
|
||||
within_mask = 'inside'
|
||||
# TODO: This is not quite the same as the PostGIS mask above
|
||||
@@ -477,7 +474,7 @@ class GeoLookupTest(TestCase):
|
||||
self.assertEqual('Lawrence', City.objects.get(point__relate=(ks.poly, within_mask)).name)
|
||||
|
||||
# Testing intersection relation mask.
|
||||
if not oracle:
|
||||
if not connection.ops.oracle:
|
||||
if connection.features.supports_transform:
|
||||
self.assertEqual(
|
||||
Country.objects.get(mpoly__relate=(pnt1, intersects_mask)).name,
|
||||
@@ -487,7 +484,7 @@ class GeoLookupTest(TestCase):
|
||||
self.assertEqual('Lawrence', City.objects.get(point__relate=(ks.poly, intersects_mask)).name)
|
||||
|
||||
# With a complex geometry expression
|
||||
mask = 'anyinteract' if oracle else within_mask
|
||||
mask = 'anyinteract' if connection.ops.oracle else within_mask
|
||||
self.assertFalse(City.objects.exclude(point__relate=(functions.Union('point', 'point'), mask)))
|
||||
|
||||
def test_gis_lookups_with_complex_expressions(self):
|
||||
|
||||
Reference in New Issue
Block a user