Skip to content

Commit

Permalink
Replaced HAS_SPATIAL_DB by testing database feature
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
claudep committed Aug 19, 2014
1 parent 3569536 commit 6295ea0
Show file tree
Hide file tree
Showing 20 changed files with 101 additions and 76 deletions.
4 changes: 4 additions & 0 deletions django/contrib/gis/db/backends/base.py
Expand Up @@ -9,6 +9,10 @@
from django.utils.encoding import python_2_unicode_compatible


class BaseSpatialFeatures(object):
gis_enabled = True


class BaseSpatialOperations(object):
"""
This module holds the base `BaseSpatialBackend` object, which is
Expand Down
11 changes: 10 additions & 1 deletion django/contrib/gis/db/backends/mysql/base.py
@@ -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.introspection import MySQLIntrospection
from django.contrib.gis.db.backends.mysql.operations import MySQLOperations


class DatabaseFeatures(BaseSpatialFeatures, MySQLDatabaseFeatures):
pass


class DatabaseWrapper(MySQLDatabaseWrapper):
def __init__(self, *args, **kwargs):
super(DatabaseWrapper, self).__init__(*args, **kwargs)
self.features = DatabaseFeatures(self)
self.creation = MySQLCreation(self)
self.ops = MySQLOperations(self)
self.introspection = MySQLIntrospection(self)
11 changes: 10 additions & 1 deletion django/contrib/gis/db/backends/oracle/base.py
@@ -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.introspection import OracleIntrospection
from django.contrib.gis.db.backends.oracle.operations import OracleOperations


class DatabaseFeatures(BaseSpatialFeatures, OracleDatabaseFeatures):
pass


class DatabaseWrapper(OracleDatabaseWrapper):
def __init__(self, *args, **kwargs):
super(DatabaseWrapper, self).__init__(*args, **kwargs)
self.features = DatabaseFeatures(self)
self.ops = OracleOperations(self)
self.creation = OracleCreation(self)
self.introspection = OracleIntrospection(self)
11 changes: 10 additions & 1 deletion django/contrib/gis/db/backends/postgis/base.py
@@ -1,15 +1,24 @@
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.introspection import PostGISIntrospection
from django.contrib.gis.db.backends.postgis.operations import PostGISOperations
from django.contrib.gis.db.backends.postgis.schema import PostGISSchemaEditor


class DatabaseFeatures(BaseSpatialFeatures, Psycopg2DatabaseFeatures):
pass


class DatabaseWrapper(Psycopg2DatabaseWrapper):
def __init__(self, *args, **kwargs):
super(DatabaseWrapper, self).__init__(*args, **kwargs)
if kwargs.get('alias', '') != NO_DB_ALIAS:
self.features = DatabaseFeatures(self)
self.creation = PostGISCreation(self)
self.ops = PostGISOperations(self)
self.introspection = PostGISIntrospection(self)
Expand Down
9 changes: 8 additions & 1 deletion django/contrib/gis/db/backends/spatialite/base.py
Expand Up @@ -4,7 +4,9 @@

from django.core.exceptions import ImproperlyConfigured
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.creation import SpatiaLiteCreation
from django.contrib.gis.db.backends.spatialite.introspection import SpatiaLiteIntrospection
Expand All @@ -13,6 +15,10 @@
from django.utils import six


class DatabaseFeatures(BaseSpatialFeatures, SQLiteDatabaseFeatures):
pass


class DatabaseWrapper(SQLiteDatabaseWrapper):
def __init__(self, *args, **kwargs):
# Before we get too far, make sure pysqlite 2.5+ is installed.
Expand All @@ -33,6 +39,7 @@ def __init__(self, *args, **kwargs):
'SPATIALITE_LIBRARY_PATH in your settings.'
)
super(DatabaseWrapper, self).__init__(*args, **kwargs)
self.features = DatabaseFeatures(self)
self.ops = SpatiaLiteOperations(self)
self.client = SpatiaLiteClient(self)
self.creation = SpatiaLiteCreation(self)
Expand Down
13 changes: 7 additions & 6 deletions django/contrib/gis/tests/distapp/tests.py
Expand Up @@ -7,23 +7,24 @@
from django.contrib.gis.geos import HAS_GEOS
from django.contrib.gis.measure import D # alias for Distance
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 .models import (AustraliaCity, Interstate, SouthTexasInterstate,
SouthTexasCity, SouthTexasCityFt, CensusZipcode, SouthTexasZipcode)


@skipUnless(HAS_GEOS and HAS_SPATIAL_DB and not mysql,
"Geos and spatial db (not mysql) are required.")
@skipUnless(HAS_GEOS and not mysql,
"GEOS and spatial db (not mysql) are required.")
@skipUnlessDBFeature("gis_enabled")
class DistanceTest(TestCase):
fixtures = ['initial']

if HAS_GEOS and HAS_SPATIAL_DB:
if HAS_GEOS:
# A point we are testing distances with -- using a WGS84
# coordinate that'll be implicitly transformed to that to
# the coordinate system of the field, EPSG:32140 (Texas South Central
Expand Down
9 changes: 3 additions & 6 deletions django/contrib/gis/tests/geoadmin/tests.py
@@ -1,19 +1,16 @@
from __future__ import unicode_literals

from unittest import skipUnless

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
from django.test import TestCase, override_settings, skipUnlessDBFeature

if HAS_GEOS and HAS_SPATIAL_DB:
if HAS_GEOS:
from django.contrib.gis import admin
from django.contrib.gis.geos import Point

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')
class GeoAdminTest(TestCase):

Expand Down
7 changes: 4 additions & 3 deletions django/contrib/gis/tests/geoapp/test_feeds.py
Expand Up @@ -6,16 +6,17 @@
from django.conf import settings
from django.contrib.sites.models import Site
from django.contrib.gis.geos import HAS_GEOS
from django.contrib.gis.tests.utils import HAS_SPATIAL_DB
from django.test import TestCase, modify_settings, override_settings
from django.test import (
TestCase, modify_settings, override_settings, skipUnlessDBFeature
)

if HAS_GEOS:
from .models import City


@modify_settings(INSTALLED_APPS={'append': 'django.contrib.sites'})
@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):
fixtures = ['initial']

Expand Down
5 changes: 2 additions & 3 deletions django/contrib/gis/tests/geoapp/test_regress.py
Expand Up @@ -7,15 +7,14 @@
from django.contrib.gis.geos import HAS_GEOS
from django.contrib.gis.tests.utils import no_mysql, no_spatialite
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.test import TestCase
from django.test import TestCase, skipUnlessDBFeature

if HAS_GEOS:
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):
fixtures = ['initial']

Expand Down
7 changes: 4 additions & 3 deletions django/contrib/gis/tests/geoapp/test_sitemaps.py
Expand Up @@ -8,9 +8,10 @@

from django.conf import settings
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.test import TestCase, modify_settings, override_settings
from django.test import (
TestCase, modify_settings, override_settings, skipUnlessDBFeature
)
from django.utils.deprecation import RemovedInDjango20Warning

if HAS_GEOS:
Expand All @@ -19,7 +20,7 @@

@modify_settings(INSTALLED_APPS={'append': ['django.contrib.sites', 'django.contrib.sitemaps']})
@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):

def setUp(self):
Expand Down
11 changes: 5 additions & 6 deletions django/contrib/gis/tests/geoapp/tests.py
Expand Up @@ -8,9 +8,8 @@
from django.contrib.gis import gdal
from django.contrib.gis.geos import HAS_GEOS
from django.contrib.gis.tests.utils import (
HAS_SPATIAL_DB, no_mysql, no_oracle, no_spatialite,
mysql, oracle, postgis, spatialite)
from django.test import TestCase
no_mysql, no_oracle, no_spatialite, mysql, oracle, postgis, spatialite)
from django.test import TestCase, skipUnlessDBFeature
from django.utils import six

if HAS_GEOS:
Expand All @@ -28,7 +27,7 @@ def postgis_bug_version():
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):
fixtures = ['initial']

Expand Down Expand Up @@ -205,7 +204,7 @@ def test_raw_sql_query(self):
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):
fixtures = ['initial']

Expand Down Expand Up @@ -397,7 +396,7 @@ def test_relate_lookup(self):
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):
fixtures = ['initial']

Expand Down
10 changes: 5 additions & 5 deletions django/contrib/gis/tests/gis_migrations/test_commands.py
@@ -1,13 +1,14 @@
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.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):
"""
Tests running the migrate command in Geodjango.
Expand All @@ -26,7 +27,6 @@ def assertTableNotExists(self, table):
with connection.cursor() as cursor:
self.assertNotIn(table, connection.introspection.get_table_list(cursor))

@skipUnless(HAS_SPATIAL_DB, "Spatial db is required.")
@override_system_checks([])
@override_settings(MIGRATION_MODULES={"gis": "django.contrib.gis.tests.gis_migrations.migrations"})
def test_migrate_gis(self):
Expand Down
9 changes: 3 additions & 6 deletions django/contrib/gis/tests/gis_migrations/test_operations.py
@@ -1,14 +1,11 @@
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.migrations.migration import Migration
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
try:
GeometryColumns = connection.ops.geometry_columns()
Expand All @@ -17,7 +14,7 @@
HAS_GEOMETRY_COLUMNS = False


@skipUnless(HAS_SPATIAL_DB, "Spatial db is required.")
@skipUnlessDBFeature("gis_enabled")
class OperationTests(TransactionTestCase):
available_apps = ["django.contrib.gis.tests.gis_migrations"]

Expand Down
9 changes: 5 additions & 4 deletions django/contrib/gis/tests/inspectapp/tests.py
Expand Up @@ -5,10 +5,9 @@

from django.core.management import call_command
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.geometry.test_data import TEST_DATA
from django.contrib.gis.tests.utils import HAS_SPATIAL_DB
from django.utils.six import StringIO

if HAS_GDAL:
Expand All @@ -18,7 +17,8 @@
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):
def test_geom_columns(self):
"""
Expand All @@ -34,7 +34,8 @@ def test_geom_columns(self):
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):
maxDiff = 1024

Expand Down
10 changes: 6 additions & 4 deletions django/contrib/gis/tests/layermap/tests.py
Expand Up @@ -8,10 +8,10 @@
from unittest import skipUnless

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.conf import settings
from django.test import TestCase
from django.test import TestCase, skipUnlessDBFeature
from django.utils._os import upath

if HAS_GDAL:
Expand All @@ -36,7 +36,8 @@
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):

def test_init(self):
Expand Down Expand Up @@ -319,7 +320,8 @@ def allow_migrate(self, db, model):
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):

def setUp(self):
Expand Down

0 comments on commit 6295ea0

Please sign in to comment.