Replaced HAS_SPATIAL_DB by testing database feature
Refs #22632. This should be the base for using more database features to exclude specific backends in GIS tests. Thanks Tim Graham for the review.
This commit is contained in:
parent
3569536491
commit
6295ea0027
|
@ -9,6 +9,10 @@ from django.utils import six
|
||||||
from django.utils.encoding import python_2_unicode_compatible
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
|
|
||||||
|
|
||||||
|
class BaseSpatialFeatures(object):
|
||||||
|
gis_enabled = True
|
||||||
|
|
||||||
|
|
||||||
class BaseSpatialOperations(object):
|
class BaseSpatialOperations(object):
|
||||||
"""
|
"""
|
||||||
This module holds the base `BaseSpatialBackend` object, which is
|
This module holds the base `BaseSpatialBackend` object, which is
|
||||||
|
|
|
@ -1,12 +1,21 @@
|
||||||
from django.db.backends.mysql.base import DatabaseWrapper as MySQLDatabaseWrapper
|
from django.db.backends.mysql.base import (
|
||||||
|
DatabaseWrapper as MySQLDatabaseWrapper,
|
||||||
|
DatabaseFeatures as MySQLDatabaseFeatures,
|
||||||
|
)
|
||||||
|
from django.contrib.gis.db.backends.base import BaseSpatialFeatures
|
||||||
from django.contrib.gis.db.backends.mysql.creation import MySQLCreation
|
from django.contrib.gis.db.backends.mysql.creation import MySQLCreation
|
||||||
from django.contrib.gis.db.backends.mysql.introspection import MySQLIntrospection
|
from django.contrib.gis.db.backends.mysql.introspection import MySQLIntrospection
|
||||||
from django.contrib.gis.db.backends.mysql.operations import MySQLOperations
|
from django.contrib.gis.db.backends.mysql.operations import MySQLOperations
|
||||||
|
|
||||||
|
|
||||||
|
class DatabaseFeatures(BaseSpatialFeatures, MySQLDatabaseFeatures):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DatabaseWrapper(MySQLDatabaseWrapper):
|
class DatabaseWrapper(MySQLDatabaseWrapper):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(DatabaseWrapper, self).__init__(*args, **kwargs)
|
super(DatabaseWrapper, self).__init__(*args, **kwargs)
|
||||||
|
self.features = DatabaseFeatures(self)
|
||||||
self.creation = MySQLCreation(self)
|
self.creation = MySQLCreation(self)
|
||||||
self.ops = MySQLOperations(self)
|
self.ops = MySQLOperations(self)
|
||||||
self.introspection = MySQLIntrospection(self)
|
self.introspection = MySQLIntrospection(self)
|
||||||
|
|
|
@ -1,12 +1,21 @@
|
||||||
from django.db.backends.oracle.base import DatabaseWrapper as OracleDatabaseWrapper
|
from django.db.backends.oracle.base import (
|
||||||
|
DatabaseWrapper as OracleDatabaseWrapper,
|
||||||
|
DatabaseFeatures as OracleDatabaseFeatures,
|
||||||
|
)
|
||||||
|
from django.contrib.gis.db.backends.base import BaseSpatialFeatures
|
||||||
from django.contrib.gis.db.backends.oracle.creation import OracleCreation
|
from django.contrib.gis.db.backends.oracle.creation import OracleCreation
|
||||||
from django.contrib.gis.db.backends.oracle.introspection import OracleIntrospection
|
from django.contrib.gis.db.backends.oracle.introspection import OracleIntrospection
|
||||||
from django.contrib.gis.db.backends.oracle.operations import OracleOperations
|
from django.contrib.gis.db.backends.oracle.operations import OracleOperations
|
||||||
|
|
||||||
|
|
||||||
|
class DatabaseFeatures(BaseSpatialFeatures, OracleDatabaseFeatures):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DatabaseWrapper(OracleDatabaseWrapper):
|
class DatabaseWrapper(OracleDatabaseWrapper):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(DatabaseWrapper, self).__init__(*args, **kwargs)
|
super(DatabaseWrapper, self).__init__(*args, **kwargs)
|
||||||
|
self.features = DatabaseFeatures(self)
|
||||||
self.ops = OracleOperations(self)
|
self.ops = OracleOperations(self)
|
||||||
self.creation = OracleCreation(self)
|
self.creation = OracleCreation(self)
|
||||||
self.introspection = OracleIntrospection(self)
|
self.introspection = OracleIntrospection(self)
|
||||||
|
|
|
@ -1,15 +1,24 @@
|
||||||
from django.db.backends.creation import NO_DB_ALIAS
|
from django.db.backends.creation import NO_DB_ALIAS
|
||||||
from django.db.backends.postgresql_psycopg2.base import DatabaseWrapper as Psycopg2DatabaseWrapper
|
from django.db.backends.postgresql_psycopg2.base import (
|
||||||
|
DatabaseWrapper as Psycopg2DatabaseWrapper,
|
||||||
|
DatabaseFeatures as Psycopg2DatabaseFeatures
|
||||||
|
)
|
||||||
|
from django.contrib.gis.db.backends.base import BaseSpatialFeatures
|
||||||
from django.contrib.gis.db.backends.postgis.creation import PostGISCreation
|
from django.contrib.gis.db.backends.postgis.creation import PostGISCreation
|
||||||
from django.contrib.gis.db.backends.postgis.introspection import PostGISIntrospection
|
from django.contrib.gis.db.backends.postgis.introspection import PostGISIntrospection
|
||||||
from django.contrib.gis.db.backends.postgis.operations import PostGISOperations
|
from django.contrib.gis.db.backends.postgis.operations import PostGISOperations
|
||||||
from django.contrib.gis.db.backends.postgis.schema import PostGISSchemaEditor
|
from django.contrib.gis.db.backends.postgis.schema import PostGISSchemaEditor
|
||||||
|
|
||||||
|
|
||||||
|
class DatabaseFeatures(BaseSpatialFeatures, Psycopg2DatabaseFeatures):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DatabaseWrapper(Psycopg2DatabaseWrapper):
|
class DatabaseWrapper(Psycopg2DatabaseWrapper):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(DatabaseWrapper, self).__init__(*args, **kwargs)
|
super(DatabaseWrapper, self).__init__(*args, **kwargs)
|
||||||
if kwargs.get('alias', '') != NO_DB_ALIAS:
|
if kwargs.get('alias', '') != NO_DB_ALIAS:
|
||||||
|
self.features = DatabaseFeatures(self)
|
||||||
self.creation = PostGISCreation(self)
|
self.creation = PostGISCreation(self)
|
||||||
self.ops = PostGISOperations(self)
|
self.ops = PostGISOperations(self)
|
||||||
self.introspection = PostGISIntrospection(self)
|
self.introspection = PostGISIntrospection(self)
|
||||||
|
|
|
@ -4,7 +4,9 @@ from django.conf import settings
|
||||||
|
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.db.backends.sqlite3.base import (Database,
|
from django.db.backends.sqlite3.base import (Database,
|
||||||
DatabaseWrapper as SQLiteDatabaseWrapper, SQLiteCursorWrapper)
|
DatabaseWrapper as SQLiteDatabaseWrapper,
|
||||||
|
DatabaseFeatures as SQLiteDatabaseFeatures, SQLiteCursorWrapper)
|
||||||
|
from django.contrib.gis.db.backends.base import BaseSpatialFeatures
|
||||||
from django.contrib.gis.db.backends.spatialite.client import SpatiaLiteClient
|
from django.contrib.gis.db.backends.spatialite.client import SpatiaLiteClient
|
||||||
from django.contrib.gis.db.backends.spatialite.creation import SpatiaLiteCreation
|
from django.contrib.gis.db.backends.spatialite.creation import SpatiaLiteCreation
|
||||||
from django.contrib.gis.db.backends.spatialite.introspection import SpatiaLiteIntrospection
|
from django.contrib.gis.db.backends.spatialite.introspection import SpatiaLiteIntrospection
|
||||||
|
@ -13,6 +15,10 @@ from django.contrib.gis.db.backends.spatialite.schema import SpatialiteSchemaEdi
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
|
||||||
|
|
||||||
|
class DatabaseFeatures(BaseSpatialFeatures, SQLiteDatabaseFeatures):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DatabaseWrapper(SQLiteDatabaseWrapper):
|
class DatabaseWrapper(SQLiteDatabaseWrapper):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
# Before we get too far, make sure pysqlite 2.5+ is installed.
|
# Before we get too far, make sure pysqlite 2.5+ is installed.
|
||||||
|
@ -33,6 +39,7 @@ class DatabaseWrapper(SQLiteDatabaseWrapper):
|
||||||
'SPATIALITE_LIBRARY_PATH in your settings.'
|
'SPATIALITE_LIBRARY_PATH in your settings.'
|
||||||
)
|
)
|
||||||
super(DatabaseWrapper, self).__init__(*args, **kwargs)
|
super(DatabaseWrapper, self).__init__(*args, **kwargs)
|
||||||
|
self.features = DatabaseFeatures(self)
|
||||||
self.ops = SpatiaLiteOperations(self)
|
self.ops = SpatiaLiteOperations(self)
|
||||||
self.client = SpatiaLiteClient(self)
|
self.client = SpatiaLiteClient(self)
|
||||||
self.creation = SpatiaLiteCreation(self)
|
self.creation = SpatiaLiteCreation(self)
|
||||||
|
|
|
@ -7,23 +7,24 @@ from django.db.models import Q
|
||||||
from django.contrib.gis.geos import HAS_GEOS
|
from django.contrib.gis.geos import HAS_GEOS
|
||||||
from django.contrib.gis.measure import D # alias for Distance
|
from django.contrib.gis.measure import D # alias for Distance
|
||||||
from django.contrib.gis.tests.utils import (
|
from django.contrib.gis.tests.utils import (
|
||||||
HAS_SPATIAL_DB, mysql, oracle, postgis, spatialite, no_oracle, no_spatialite
|
mysql, oracle, postgis, spatialite, no_oracle, no_spatialite
|
||||||
)
|
)
|
||||||
from django.test import TestCase
|
from django.test import TestCase, skipUnlessDBFeature
|
||||||
|
|
||||||
if HAS_GEOS and HAS_SPATIAL_DB:
|
if HAS_GEOS:
|
||||||
from django.contrib.gis.geos import GEOSGeometry, LineString
|
from django.contrib.gis.geos import GEOSGeometry, LineString
|
||||||
|
|
||||||
from .models import (AustraliaCity, Interstate, SouthTexasInterstate,
|
from .models import (AustraliaCity, Interstate, SouthTexasInterstate,
|
||||||
SouthTexasCity, SouthTexasCityFt, CensusZipcode, SouthTexasZipcode)
|
SouthTexasCity, SouthTexasCityFt, CensusZipcode, SouthTexasZipcode)
|
||||||
|
|
||||||
|
|
||||||
@skipUnless(HAS_GEOS and HAS_SPATIAL_DB and not mysql,
|
@skipUnless(HAS_GEOS and not mysql,
|
||||||
"Geos and spatial db (not mysql) are required.")
|
"GEOS and spatial db (not mysql) are required.")
|
||||||
|
@skipUnlessDBFeature("gis_enabled")
|
||||||
class DistanceTest(TestCase):
|
class DistanceTest(TestCase):
|
||||||
fixtures = ['initial']
|
fixtures = ['initial']
|
||||||
|
|
||||||
if HAS_GEOS and HAS_SPATIAL_DB:
|
if HAS_GEOS:
|
||||||
# A point we are testing distances with -- using a WGS84
|
# A point we are testing distances with -- using a WGS84
|
||||||
# coordinate that'll be implicitly transformed to that to
|
# coordinate that'll be implicitly transformed to that to
|
||||||
# the coordinate system of the field, EPSG:32140 (Texas South Central
|
# the coordinate system of the field, EPSG:32140 (Texas South Central
|
||||||
|
|
|
@ -1,19 +1,16 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from unittest import skipUnless
|
|
||||||
|
|
||||||
from django.contrib.gis.geos import HAS_GEOS
|
from django.contrib.gis.geos import HAS_GEOS
|
||||||
from django.contrib.gis.tests.utils import HAS_SPATIAL_DB
|
from django.test import TestCase, override_settings, skipUnlessDBFeature
|
||||||
from django.test import TestCase, override_settings
|
|
||||||
|
|
||||||
if HAS_GEOS and HAS_SPATIAL_DB:
|
if HAS_GEOS:
|
||||||
from django.contrib.gis import admin
|
from django.contrib.gis import admin
|
||||||
from django.contrib.gis.geos import Point
|
from django.contrib.gis.geos import Point
|
||||||
|
|
||||||
from .models import City
|
from .models import City
|
||||||
|
|
||||||
|
|
||||||
@skipUnless(HAS_GEOS and HAS_SPATIAL_DB, "Geos and spatial db are required.")
|
@skipUnlessDBFeature("gis_enabled")
|
||||||
@override_settings(ROOT_URLCONF='django.contrib.gis.tests.geoadmin.urls')
|
@override_settings(ROOT_URLCONF='django.contrib.gis.tests.geoadmin.urls')
|
||||||
class GeoAdminTest(TestCase):
|
class GeoAdminTest(TestCase):
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,9 @@ from xml.dom import minidom
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
from django.contrib.gis.geos import HAS_GEOS
|
from django.contrib.gis.geos import HAS_GEOS
|
||||||
from django.contrib.gis.tests.utils import HAS_SPATIAL_DB
|
from django.test import (
|
||||||
from django.test import TestCase, modify_settings, override_settings
|
TestCase, modify_settings, override_settings, skipUnlessDBFeature
|
||||||
|
)
|
||||||
|
|
||||||
if HAS_GEOS:
|
if HAS_GEOS:
|
||||||
from .models import City
|
from .models import City
|
||||||
|
@ -15,7 +16,7 @@ if HAS_GEOS:
|
||||||
|
|
||||||
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.sites'})
|
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.sites'})
|
||||||
@override_settings(ROOT_URLCONF='django.contrib.gis.tests.geoapp.urls')
|
@override_settings(ROOT_URLCONF='django.contrib.gis.tests.geoapp.urls')
|
||||||
@skipUnless(HAS_GEOS and HAS_SPATIAL_DB, "Geos and spatial db are required.")
|
@skipUnlessDBFeature("gis_enabled")
|
||||||
class GeoFeedTest(TestCase):
|
class GeoFeedTest(TestCase):
|
||||||
fixtures = ['initial']
|
fixtures = ['initial']
|
||||||
|
|
||||||
|
|
|
@ -7,15 +7,14 @@ from unittest import skipUnless
|
||||||
from django.contrib.gis.geos import HAS_GEOS
|
from django.contrib.gis.geos import HAS_GEOS
|
||||||
from django.contrib.gis.tests.utils import no_mysql, no_spatialite
|
from django.contrib.gis.tests.utils import no_mysql, no_spatialite
|
||||||
from django.contrib.gis.shortcuts import render_to_kmz
|
from django.contrib.gis.shortcuts import render_to_kmz
|
||||||
from django.contrib.gis.tests.utils import HAS_SPATIAL_DB
|
|
||||||
from django.db.models import Count, Min
|
from django.db.models import Count, Min
|
||||||
from django.test import TestCase
|
from django.test import TestCase, skipUnlessDBFeature
|
||||||
|
|
||||||
if HAS_GEOS:
|
if HAS_GEOS:
|
||||||
from .models import City, PennsylvaniaCity, State, Truth
|
from .models import City, PennsylvaniaCity, State, Truth
|
||||||
|
|
||||||
|
|
||||||
@skipUnless(HAS_GEOS and HAS_SPATIAL_DB, "Geos and spatial db are required.")
|
@skipUnlessDBFeature("gis_enabled")
|
||||||
class GeoRegressionTests(TestCase):
|
class GeoRegressionTests(TestCase):
|
||||||
fixtures = ['initial']
|
fixtures = ['initial']
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,10 @@ import zipfile
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.gis.geos import HAS_GEOS
|
from django.contrib.gis.geos import HAS_GEOS
|
||||||
from django.contrib.gis.tests.utils import HAS_SPATIAL_DB
|
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
from django.test import TestCase, modify_settings, override_settings
|
from django.test import (
|
||||||
|
TestCase, modify_settings, override_settings, skipUnlessDBFeature
|
||||||
|
)
|
||||||
from django.utils.deprecation import RemovedInDjango20Warning
|
from django.utils.deprecation import RemovedInDjango20Warning
|
||||||
|
|
||||||
if HAS_GEOS:
|
if HAS_GEOS:
|
||||||
|
@ -19,7 +20,7 @@ if HAS_GEOS:
|
||||||
|
|
||||||
@modify_settings(INSTALLED_APPS={'append': ['django.contrib.sites', 'django.contrib.sitemaps']})
|
@modify_settings(INSTALLED_APPS={'append': ['django.contrib.sites', 'django.contrib.sitemaps']})
|
||||||
@override_settings(ROOT_URLCONF='django.contrib.gis.tests.geoapp.urls')
|
@override_settings(ROOT_URLCONF='django.contrib.gis.tests.geoapp.urls')
|
||||||
@skipUnless(HAS_GEOS and HAS_SPATIAL_DB, "Geos and spatial db are required.")
|
@skipUnlessDBFeature("gis_enabled")
|
||||||
class GeoSitemapTest(TestCase):
|
class GeoSitemapTest(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
|
@ -8,9 +8,8 @@ from django.db import connection
|
||||||
from django.contrib.gis import gdal
|
from django.contrib.gis import gdal
|
||||||
from django.contrib.gis.geos import HAS_GEOS
|
from django.contrib.gis.geos import HAS_GEOS
|
||||||
from django.contrib.gis.tests.utils import (
|
from django.contrib.gis.tests.utils import (
|
||||||
HAS_SPATIAL_DB, no_mysql, no_oracle, no_spatialite,
|
no_mysql, no_oracle, no_spatialite, mysql, oracle, postgis, spatialite)
|
||||||
mysql, oracle, postgis, spatialite)
|
from django.test import TestCase, skipUnlessDBFeature
|
||||||
from django.test import TestCase
|
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
|
||||||
if HAS_GEOS:
|
if HAS_GEOS:
|
||||||
|
@ -28,7 +27,7 @@ def postgis_bug_version():
|
||||||
return spatial_version and (2, 0, 0) <= spatial_version <= (2, 0, 1)
|
return spatial_version and (2, 0, 0) <= spatial_version <= (2, 0, 1)
|
||||||
|
|
||||||
|
|
||||||
@skipUnless(HAS_GEOS and HAS_SPATIAL_DB, "Geos and spatial db are required.")
|
@skipUnlessDBFeature("gis_enabled")
|
||||||
class GeoModelTest(TestCase):
|
class GeoModelTest(TestCase):
|
||||||
fixtures = ['initial']
|
fixtures = ['initial']
|
||||||
|
|
||||||
|
@ -205,7 +204,7 @@ class GeoModelTest(TestCase):
|
||||||
self.assertIsInstance(cities2[0].point, Point)
|
self.assertIsInstance(cities2[0].point, Point)
|
||||||
|
|
||||||
|
|
||||||
@skipUnless(HAS_GEOS and HAS_SPATIAL_DB, "Geos and spatial db are required.")
|
@skipUnlessDBFeature("gis_enabled")
|
||||||
class GeoLookupTest(TestCase):
|
class GeoLookupTest(TestCase):
|
||||||
fixtures = ['initial']
|
fixtures = ['initial']
|
||||||
|
|
||||||
|
@ -397,7 +396,7 @@ class GeoLookupTest(TestCase):
|
||||||
self.assertEqual('Lawrence', City.objects.get(point__relate=(ks.poly, intersects_mask)).name)
|
self.assertEqual('Lawrence', City.objects.get(point__relate=(ks.poly, intersects_mask)).name)
|
||||||
|
|
||||||
|
|
||||||
@skipUnless(HAS_GEOS and HAS_SPATIAL_DB, "Geos and spatial db are required.")
|
@skipUnlessDBFeature("gis_enabled")
|
||||||
class GeoQuerySetTest(TestCase):
|
class GeoQuerySetTest(TestCase):
|
||||||
fixtures = ['initial']
|
fixtures = ['initial']
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from unittest import skipUnless
|
|
||||||
|
|
||||||
from django.contrib.gis.tests.utils import HAS_SPATIAL_DB
|
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.test import override_settings, override_system_checks, TransactionTestCase
|
from django.test import (
|
||||||
|
override_settings, override_system_checks, skipUnlessDBFeature,
|
||||||
|
TransactionTestCase
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@skipUnlessDBFeature("gis_enabled")
|
||||||
class MigrateTests(TransactionTestCase):
|
class MigrateTests(TransactionTestCase):
|
||||||
"""
|
"""
|
||||||
Tests running the migrate command in Geodjango.
|
Tests running the migrate command in Geodjango.
|
||||||
|
@ -26,7 +27,6 @@ class MigrateTests(TransactionTestCase):
|
||||||
with connection.cursor() as cursor:
|
with connection.cursor() as cursor:
|
||||||
self.assertNotIn(table, connection.introspection.get_table_list(cursor))
|
self.assertNotIn(table, connection.introspection.get_table_list(cursor))
|
||||||
|
|
||||||
@skipUnless(HAS_SPATIAL_DB, "Spatial db is required.")
|
|
||||||
@override_system_checks([])
|
@override_system_checks([])
|
||||||
@override_settings(MIGRATION_MODULES={"gis": "django.contrib.gis.tests.gis_migrations.migrations"})
|
@override_settings(MIGRATION_MODULES={"gis": "django.contrib.gis.tests.gis_migrations.migrations"})
|
||||||
def test_migrate_gis(self):
|
def test_migrate_gis(self):
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from unittest import skipUnless
|
|
||||||
|
|
||||||
from django.contrib.gis.tests.utils import HAS_SPATIAL_DB
|
|
||||||
from django.db import connection, migrations, models
|
from django.db import connection, migrations, models
|
||||||
from django.db.migrations.migration import Migration
|
from django.db.migrations.migration import Migration
|
||||||
from django.db.migrations.state import ProjectState
|
from django.db.migrations.state import ProjectState
|
||||||
from django.test import TransactionTestCase
|
from django.test import skipUnlessDBFeature, TransactionTestCase
|
||||||
|
|
||||||
if HAS_SPATIAL_DB:
|
if connection.features.gis_enabled:
|
||||||
from django.contrib.gis.db.models import fields
|
from django.contrib.gis.db.models import fields
|
||||||
try:
|
try:
|
||||||
GeometryColumns = connection.ops.geometry_columns()
|
GeometryColumns = connection.ops.geometry_columns()
|
||||||
|
@ -17,7 +14,7 @@ if HAS_SPATIAL_DB:
|
||||||
HAS_GEOMETRY_COLUMNS = False
|
HAS_GEOMETRY_COLUMNS = False
|
||||||
|
|
||||||
|
|
||||||
@skipUnless(HAS_SPATIAL_DB, "Spatial db is required.")
|
@skipUnlessDBFeature("gis_enabled")
|
||||||
class OperationTests(TransactionTestCase):
|
class OperationTests(TransactionTestCase):
|
||||||
available_apps = ["django.contrib.gis.tests.gis_migrations"]
|
available_apps = ["django.contrib.gis.tests.gis_migrations"]
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,9 @@ from unittest import skipUnless
|
||||||
|
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
from django.db import connections
|
from django.db import connections
|
||||||
from django.test import TestCase
|
from django.test import TestCase, skipUnlessDBFeature
|
||||||
from django.contrib.gis.gdal import HAS_GDAL
|
from django.contrib.gis.gdal import HAS_GDAL
|
||||||
from django.contrib.gis.geometry.test_data import TEST_DATA
|
from django.contrib.gis.geometry.test_data import TEST_DATA
|
||||||
from django.contrib.gis.tests.utils import HAS_SPATIAL_DB
|
|
||||||
from django.utils.six import StringIO
|
from django.utils.six import StringIO
|
||||||
|
|
||||||
if HAS_GDAL:
|
if HAS_GDAL:
|
||||||
|
@ -18,7 +17,8 @@ if HAS_GDAL:
|
||||||
from .models import AllOGRFields
|
from .models import AllOGRFields
|
||||||
|
|
||||||
|
|
||||||
@skipUnless(HAS_GDAL and HAS_SPATIAL_DB, "GDAL and spatial db are required.")
|
@skipUnless(HAS_GDAL, "InspectDbTests needs GDAL support")
|
||||||
|
@skipUnlessDBFeature("gis_enabled")
|
||||||
class InspectDbTests(TestCase):
|
class InspectDbTests(TestCase):
|
||||||
def test_geom_columns(self):
|
def test_geom_columns(self):
|
||||||
"""
|
"""
|
||||||
|
@ -34,7 +34,8 @@ class InspectDbTests(TestCase):
|
||||||
self.assertIn('objects = models.GeoManager()', output)
|
self.assertIn('objects = models.GeoManager()', output)
|
||||||
|
|
||||||
|
|
||||||
@skipUnless(HAS_GDAL and HAS_SPATIAL_DB, "GDAL and spatial db are required.")
|
@skipUnless(HAS_GDAL, "OGRInspectTest needs GDAL support")
|
||||||
|
@skipUnlessDBFeature("gis_enabled")
|
||||||
class OGRInspectTest(TestCase):
|
class OGRInspectTest(TestCase):
|
||||||
maxDiff = 1024
|
maxDiff = 1024
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,10 @@ import unittest
|
||||||
from unittest import skipUnless
|
from unittest import skipUnless
|
||||||
|
|
||||||
from django.contrib.gis.gdal import HAS_GDAL
|
from django.contrib.gis.gdal import HAS_GDAL
|
||||||
from django.contrib.gis.tests.utils import HAS_SPATIAL_DB, mysql
|
from django.contrib.gis.tests.utils import mysql
|
||||||
from django.db import router
|
from django.db import router
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.test import TestCase
|
from django.test import TestCase, skipUnlessDBFeature
|
||||||
from django.utils._os import upath
|
from django.utils._os import upath
|
||||||
|
|
||||||
if HAS_GDAL:
|
if HAS_GDAL:
|
||||||
|
@ -36,7 +36,8 @@ NUMS = [1, 2, 1, 19, 1] # Number of polygons for each.
|
||||||
STATES = ['Texas', 'Texas', 'Texas', 'Hawaii', 'Colorado']
|
STATES = ['Texas', 'Texas', 'Texas', 'Hawaii', 'Colorado']
|
||||||
|
|
||||||
|
|
||||||
@skipUnless(HAS_GDAL and HAS_SPATIAL_DB, "GDAL and spatial db are required.")
|
@skipUnless(HAS_GDAL, "LayerMapTest needs GDAL support")
|
||||||
|
@skipUnlessDBFeature("gis_enabled")
|
||||||
class LayerMapTest(TestCase):
|
class LayerMapTest(TestCase):
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
|
@ -319,7 +320,8 @@ class OtherRouter(object):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@skipUnless(HAS_GDAL and HAS_SPATIAL_DB, "GDAL and spatial db are required.")
|
@skipUnless(HAS_GDAL, "LayerMapRouterTest needs GDAL support")
|
||||||
|
@skipUnlessDBFeature("gis_enabled")
|
||||||
class LayerMapRouterTest(TestCase):
|
class LayerMapRouterTest(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from unittest import skipUnless
|
|
||||||
|
|
||||||
from django.contrib.gis.geos import HAS_GEOS
|
from django.contrib.gis.geos import HAS_GEOS
|
||||||
from django.contrib.gis.tests.utils import HAS_SPATIAL_DB, mysql, no_mysql, no_oracle, no_spatialite
|
from django.contrib.gis.tests.utils import mysql, no_mysql, no_oracle, no_spatialite
|
||||||
from django.test import TestCase
|
from django.test import TestCase, skipUnlessDBFeature
|
||||||
|
|
||||||
if HAS_GEOS:
|
if HAS_GEOS:
|
||||||
from django.contrib.gis.db.models import Collect, Count, Extent, F, Union
|
from django.contrib.gis.db.models import Collect, Count, Extent, F, Union
|
||||||
|
@ -14,7 +12,7 @@ if HAS_GEOS:
|
||||||
from .models import City, Location, DirectoryEntry, Parcel, Book, Author, Article
|
from .models import City, Location, DirectoryEntry, Parcel, Book, Author, Article
|
||||||
|
|
||||||
|
|
||||||
@skipUnless(HAS_GEOS and HAS_SPATIAL_DB, "Geos and spatial db are required.")
|
@skipUnlessDBFeature("gis_enabled")
|
||||||
class RelatedGeoModelTest(TestCase):
|
class RelatedGeoModelTest(TestCase):
|
||||||
fixtures = ['initial']
|
fixtures = ['initial']
|
||||||
|
|
||||||
|
|
|
@ -2,17 +2,17 @@ from unittest import skipUnless
|
||||||
|
|
||||||
from django.forms import ValidationError
|
from django.forms import ValidationError
|
||||||
from django.contrib.gis.gdal import HAS_GDAL
|
from django.contrib.gis.gdal import HAS_GDAL
|
||||||
from django.contrib.gis.tests.utils import HAS_SPATIAL_DB
|
from django.test import SimpleTestCase, skipUnlessDBFeature
|
||||||
from django.test import SimpleTestCase
|
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
|
|
||||||
if HAS_SPATIAL_DB:
|
if HAS_GDAL:
|
||||||
from django.contrib.gis import forms
|
from django.contrib.gis import forms
|
||||||
from django.contrib.gis.geos import GEOSGeometry
|
from django.contrib.gis.geos import GEOSGeometry
|
||||||
|
|
||||||
|
|
||||||
@skipUnless(HAS_GDAL and HAS_SPATIAL_DB, "GeometryFieldTest needs gdal support and a spatial database")
|
@skipUnless(HAS_GDAL, "GeometryFieldTest needs GDAL support")
|
||||||
|
@skipUnlessDBFeature("gis_enabled")
|
||||||
class GeometryFieldTest(SimpleTestCase):
|
class GeometryFieldTest(SimpleTestCase):
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
|
@ -90,8 +90,8 @@ class GeometryFieldTest(SimpleTestCase):
|
||||||
self.assertFalse(form.has_changed())
|
self.assertFalse(form.has_changed())
|
||||||
|
|
||||||
|
|
||||||
@skipUnless(HAS_GDAL and HAS_SPATIAL_DB,
|
@skipUnless(HAS_GDAL, "SpecializedFieldTest needs GDAL support")
|
||||||
"SpecializedFieldTest needs gdal support and a spatial database")
|
@skipUnlessDBFeature("gis_enabled")
|
||||||
class SpecializedFieldTest(SimpleTestCase):
|
class SpecializedFieldTest(SimpleTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.geometries = {
|
self.geometries = {
|
||||||
|
@ -258,8 +258,8 @@ class SpecializedFieldTest(SimpleTestCase):
|
||||||
self.assertFalse(GeometryForm(data={'g': invalid.wkt}).is_valid())
|
self.assertFalse(GeometryForm(data={'g': invalid.wkt}).is_valid())
|
||||||
|
|
||||||
|
|
||||||
@skipUnless(HAS_GDAL and HAS_SPATIAL_DB,
|
@skipUnless(HAS_GDAL, "OSMWidgetTest needs GDAL support")
|
||||||
"OSMWidgetTest needs gdal support and a spatial database")
|
@skipUnlessDBFeature("gis_enabled")
|
||||||
class OSMWidgetTest(SimpleTestCase):
|
class OSMWidgetTest(SimpleTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.geometries = {
|
self.geometries = {
|
||||||
|
@ -300,8 +300,8 @@ class OSMWidgetTest(SimpleTestCase):
|
||||||
rendered)
|
rendered)
|
||||||
|
|
||||||
|
|
||||||
@skipUnless(HAS_GDAL and HAS_SPATIAL_DB,
|
@skipUnless(HAS_GDAL, "CustomGeometryWidgetTest needs GDAL support")
|
||||||
"CustomGeometryWidgetTest needs gdal support and a spatial database")
|
@skipUnlessDBFeature("gis_enabled")
|
||||||
class CustomGeometryWidgetTest(SimpleTestCase):
|
class CustomGeometryWidgetTest(SimpleTestCase):
|
||||||
|
|
||||||
def test_custom_serialization_widget(self):
|
def test_custom_serialization_widget(self):
|
||||||
|
|
|
@ -49,12 +49,3 @@ elif spatialite:
|
||||||
else:
|
else:
|
||||||
HAS_SPATIALREFSYS = False
|
HAS_SPATIALREFSYS = False
|
||||||
SpatialRefSys = None
|
SpatialRefSys = None
|
||||||
|
|
||||||
|
|
||||||
def has_spatial_db():
|
|
||||||
# All databases must have spatial backends to run GeoDjango tests.
|
|
||||||
spatial_dbs = [name for name, db_dict in settings.DATABASES.items()
|
|
||||||
if db_dict['ENGINE'].startswith('django.contrib.gis')]
|
|
||||||
return len(spatial_dbs) == len(settings.DATABASES)
|
|
||||||
|
|
||||||
HAS_SPATIAL_DB = has_spatial_db()
|
|
||||||
|
|
|
@ -474,6 +474,7 @@ class BaseDatabaseWrapper(object):
|
||||||
|
|
||||||
|
|
||||||
class BaseDatabaseFeatures(object):
|
class BaseDatabaseFeatures(object):
|
||||||
|
gis_enabled = False
|
||||||
allows_group_by_pk = False
|
allows_group_by_pk = False
|
||||||
# True if django.db.backends.utils.typecast_timestamp is used on values
|
# True if django.db.backends.utils.typecast_timestamp is used on values
|
||||||
# returned from dates() calls.
|
# returned from dates() calls.
|
||||||
|
|
|
@ -60,13 +60,12 @@ ALWAYS_MIDDLEWARE_CLASSES = (
|
||||||
|
|
||||||
|
|
||||||
def get_test_modules():
|
def get_test_modules():
|
||||||
from django.contrib.gis.tests.utils import HAS_SPATIAL_DB
|
|
||||||
modules = []
|
modules = []
|
||||||
discovery_paths = [
|
discovery_paths = [
|
||||||
(None, RUNTESTS_DIR),
|
(None, RUNTESTS_DIR),
|
||||||
(CONTRIB_MODULE_PATH, CONTRIB_DIR)
|
(CONTRIB_MODULE_PATH, CONTRIB_DIR)
|
||||||
]
|
]
|
||||||
if HAS_SPATIAL_DB:
|
if connection.features.gis_enabled:
|
||||||
discovery_paths.append(
|
discovery_paths.append(
|
||||||
('django.contrib.gis.tests', os.path.join(CONTRIB_DIR, 'gis', 'tests'))
|
('django.contrib.gis.tests', os.path.join(CONTRIB_DIR, 'gis', 'tests'))
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue