diff --git a/tests/gis_tests/admin.py b/tests/gis_tests/admin.py new file mode 100644 index 00000000000..f693ef34de3 --- /dev/null +++ b/tests/gis_tests/admin.py @@ -0,0 +1,6 @@ +try: + from django.contrib.gis import admin +except ImportError: + from django.contrib import admin + + admin.OSMGeoAdmin = admin.ModelAdmin diff --git a/tests/gis_tests/distapp/models.py b/tests/gis_tests/distapp/models.py index 255bc08bb01..c04659f5245 100644 --- a/tests/gis_tests/distapp/models.py +++ b/tests/gis_tests/distapp/models.py @@ -1,6 +1,6 @@ -from django.contrib.gis.db import models from django.utils.encoding import python_2_unicode_compatible +from ..models import models from ..utils import gisfield_may_be_null @@ -12,6 +12,7 @@ class NamedModel(models.Model): class Meta: abstract = True + required_db_features = ['gis_enabled'] def __str__(self): return self.name diff --git a/tests/gis_tests/geo3d/models.py b/tests/gis_tests/geo3d/models.py index 9575966e75a..fb741ca05c1 100644 --- a/tests/gis_tests/geo3d/models.py +++ b/tests/gis_tests/geo3d/models.py @@ -1,6 +1,7 @@ -from django.contrib.gis.db import models from django.utils.encoding import python_2_unicode_compatible +from ..models import models + @python_2_unicode_compatible class NamedModel(models.Model): @@ -10,6 +11,7 @@ class NamedModel(models.Model): class Meta: abstract = True + required_db_features = ['gis_enabled'] def __str__(self): return self.name @@ -49,6 +51,7 @@ class SimpleModel(models.Model): class Meta: abstract = True + required_db_features = ['gis_enabled'] class Point2D(SimpleModel): diff --git a/tests/gis_tests/geo3d/tests.py b/tests/gis_tests/geo3d/tests.py index b05201d0bfb..7f5112a82fc 100644 --- a/tests/gis_tests/geo3d/tests.py +++ b/tests/gis_tests/geo3d/tests.py @@ -17,8 +17,8 @@ if HAS_GEOS: from .models import (City3D, Interstate2D, Interstate3D, InterstateProj2D, InterstateProj3D, Point2D, Point3D, MultiPoint3D, Polygon2D, Polygon3D) -if HAS_GDAL: - from django.contrib.gis.utils import LayerMapping, LayerMapError + if HAS_GDAL: + from django.contrib.gis.utils import LayerMapping, LayerMapError data_path = os.path.realpath(os.path.join(os.path.dirname(upath(__file__)), '..', 'data')) diff --git a/tests/gis_tests/geoadmin/models.py b/tests/gis_tests/geoadmin/models.py index 9769558f48b..b7d3b53c60d 100644 --- a/tests/gis_tests/geoadmin/models.py +++ b/tests/gis_tests/geoadmin/models.py @@ -1,7 +1,8 @@ -from django.contrib.gis import admin -from django.contrib.gis.db import models from django.utils.encoding import python_2_unicode_compatible +from ..admin import admin +from ..models import models + @python_2_unicode_compatible class City(models.Model): @@ -12,6 +13,7 @@ class City(models.Model): class Meta: app_label = 'geoadmin' + required_db_features = ['gis_enabled'] def __str__(self): return self.name diff --git a/tests/gis_tests/geoapp/models.py b/tests/gis_tests/geoapp/models.py index 877eb7d72c5..2349b29659c 100644 --- a/tests/gis_tests/geoapp/models.py +++ b/tests/gis_tests/geoapp/models.py @@ -1,6 +1,6 @@ -from django.contrib.gis.db import models from django.utils.encoding import python_2_unicode_compatible +from ..models import models from ..utils import gisfield_may_be_null @@ -12,6 +12,7 @@ class NamedModel(models.Model): class Meta: abstract = True + required_db_features = ['gis_enabled'] def __str__(self): return self.name @@ -26,6 +27,7 @@ class City(NamedModel): class Meta: app_label = 'geoapp' + required_db_features = ['gis_enabled'] # This is an inherited model from City @@ -39,6 +41,7 @@ class PennsylvaniaCity(City): class Meta: app_label = 'geoapp' + required_db_features = ['gis_enabled'] class State(NamedModel): @@ -46,6 +49,7 @@ class State(NamedModel): class Meta: app_label = 'geoapp' + required_db_features = ['gis_enabled'] class Track(NamedModel): @@ -59,6 +63,7 @@ class MultiFields(NamedModel): class Meta: unique_together = ('city', 'point') + required_db_features = ['gis_enabled'] class Truth(models.Model): @@ -66,6 +71,9 @@ class Truth(models.Model): objects = models.GeoManager() + class Meta: + required_db_features = ['gis_enabled'] + class Feature(NamedModel): geom = models.GeometryField() @@ -76,6 +84,9 @@ class MinusOneSRID(models.Model): objects = models.GeoManager() + class Meta: + required_db_features = ['gis_enabled'] + class NonConcreteField(models.IntegerField): diff --git a/tests/gis_tests/geogapp/models.py b/tests/gis_tests/geogapp/models.py index 75102d22c9f..d756a0c2a25 100644 --- a/tests/gis_tests/geogapp/models.py +++ b/tests/gis_tests/geogapp/models.py @@ -1,6 +1,7 @@ -from django.contrib.gis.db import models from django.utils.encoding import python_2_unicode_compatible +from ..models import models + @python_2_unicode_compatible class NamedModel(models.Model): @@ -10,6 +11,7 @@ class NamedModel(models.Model): class Meta: abstract = True + required_db_features = ['gis_enabled'] def __str__(self): return self.name @@ -20,6 +22,7 @@ class City(NamedModel): class Meta: app_label = 'geogapp' + required_db_features = ['gis_enabled'] class Zipcode(NamedModel): @@ -33,6 +36,7 @@ class County(NamedModel): class Meta: app_label = 'geogapp' + required_db_features = ['gis_enabled'] def __str__(self): return ' County, '.join([self.name, self.state]) diff --git a/tests/gis_tests/gis_migrations/migrations/0001_initial.py b/tests/gis_tests/gis_migrations/migrations/0001_initial.py index aceaaa301e0..bf2966ee790 100644 --- a/tests/gis_tests/gis_migrations/migrations/0001_initial.py +++ b/tests/gis_tests/gis_migrations/migrations/0001_initial.py @@ -1,6 +1,7 @@ -import django.contrib.gis.db.models.fields from django.db import migrations, models +from ...models import models as gis_models + class Migration(migrations.Migration): """ @@ -12,9 +13,10 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('name', models.CharField(max_length=100, unique=True)), - ('geom', django.contrib.gis.db.models.fields.MultiPolygonField(srid=4326)), + ('geom', gis_models.MultiPolygonField(srid=4326)), ], options={ + 'required_db_features': ['gis_enabled'], }, bases=(models.Model,), ), @@ -25,9 +27,10 @@ class Migration(migrations.Migration): ('neighborhood', models.ForeignKey(to='gis_migrations.Neighborhood', to_field='id', null=True)), ('address', models.CharField(max_length=100)), ('zip_code', models.IntegerField(null=True, blank=True)), - ('geom', django.contrib.gis.db.models.fields.PointField(srid=4326, geography=True)), + ('geom', gis_models.PointField(srid=4326, geography=True)), ], options={ + 'required_db_features': ['gis_enabled'], }, bases=(models.Model,), ), diff --git a/tests/gis_tests/inspectapp/models.py b/tests/gis_tests/inspectapp/models.py index fd343b78034..75c4bcfa229 100644 --- a/tests/gis_tests/inspectapp/models.py +++ b/tests/gis_tests/inspectapp/models.py @@ -1,4 +1,4 @@ -from django.contrib.gis.db import models +from ..models import models class AllOGRFields(models.Model): @@ -15,6 +15,9 @@ class AllOGRFields(models.Model): objects = models.GeoManager() + class Meta: + required_db_features = ['gis_enabled'] + class Fields3D(models.Model): point = models.PointField(dim=3) @@ -22,3 +25,6 @@ class Fields3D(models.Model): poly = models.PolygonField(dim=3) objects = models.GeoManager() + + class Meta: + required_db_features = ['gis_enabled'] diff --git a/tests/gis_tests/layermap/models.py b/tests/gis_tests/layermap/models.py index f2c78825476..4ffcad0486f 100644 --- a/tests/gis_tests/layermap/models.py +++ b/tests/gis_tests/layermap/models.py @@ -1,6 +1,7 @@ -from django.contrib.gis.db import models from django.utils.encoding import python_2_unicode_compatible +from ..models import models + @python_2_unicode_compatible class NamedModel(models.Model): @@ -10,6 +11,7 @@ class NamedModel(models.Model): class Meta: abstract = True + required_db_features = ['gis_enabled'] def __str__(self): return self.name @@ -38,6 +40,7 @@ class City(NamedModel): class Meta: app_label = 'layermap' + required_db_features = ['gis_enabled'] class Interstate(NamedModel): @@ -46,6 +49,7 @@ class Interstate(NamedModel): class Meta: app_label = 'layermap' + required_db_features = ['gis_enabled'] # Same as `City` above, but for testing model inheritance. @@ -72,6 +76,9 @@ class ICity2(ICity1): class Invalid(models.Model): point = models.PointField() + class Meta: + required_db_features = ['gis_enabled'] + # Mapping dictionaries for the models above. co_mapping = { diff --git a/tests/gis_tests/layermap/tests.py b/tests/gis_tests/layermap/tests.py index e4477189cb4..a0abd4030cb 100644 --- a/tests/gis_tests/layermap/tests.py +++ b/tests/gis_tests/layermap/tests.py @@ -9,11 +9,12 @@ from unittest import skipUnless from django.conf import settings from django.contrib.gis.gdal import HAS_GDAL +from django.contrib.gis.geos import HAS_GEOS from django.db import connection from django.test import TestCase, override_settings, skipUnlessDBFeature from django.utils._os import upath -if HAS_GDAL: +if HAS_GEOS and HAS_GDAL: from django.contrib.gis.utils.layermapping import (LayerMapping, LayerMapError, InvalidDecimal, InvalidString, MissingForeignKey) from django.contrib.gis.gdal import DataSource diff --git a/tests/gis_tests/models.py b/tests/gis_tests/models.py new file mode 100644 index 00000000000..cfb7f966563 --- /dev/null +++ b/tests/gis_tests/models.py @@ -0,0 +1,18 @@ +from django.core.exceptions import ImproperlyConfigured + +try: + from django.contrib.gis.db import models +except ImproperlyConfigured: + from django.db import models + + class DummyField(models.Field): + def __init__(self, dim=None, srid=None, geography=None, *args, **kwargs): + super(DummyField, self).__init__(*args, **kwargs) + + models.GeoManager = models.Manager + models.GeometryField = DummyField + models.LineStringField = DummyField + models.MultiPointField = DummyField + models.MultiPolygonField = DummyField + models.PointField = DummyField + models.PolygonField = DummyField diff --git a/tests/gis_tests/relatedapp/models.py b/tests/gis_tests/relatedapp/models.py index 2bcd2ebc5f9..baa1e7ff33f 100644 --- a/tests/gis_tests/relatedapp/models.py +++ b/tests/gis_tests/relatedapp/models.py @@ -1,6 +1,7 @@ -from django.contrib.gis.db import models from django.utils.encoding import python_2_unicode_compatible +from ..models import models + class SimpleModel(models.Model): @@ -8,6 +9,7 @@ class SimpleModel(models.Model): class Meta: abstract = True + required_db_features = ['gis_enabled'] @python_2_unicode_compatible diff --git a/tests/gis_tests/test_geoforms.py b/tests/gis_tests/test_geoforms.py index bcbb5f08045..a7388d03536 100644 --- a/tests/gis_tests/test_geoforms.py +++ b/tests/gis_tests/test_geoforms.py @@ -1,12 +1,13 @@ from unittest import skipUnless from django.contrib.gis.gdal import HAS_GDAL +from django.contrib.gis.geos import HAS_GEOS from django.forms import ValidationError from django.test import SimpleTestCase, skipUnlessDBFeature from django.utils import six from django.utils.html import escape -if HAS_GDAL: +if HAS_GEOS and HAS_GDAL: from django.contrib.gis import forms from django.contrib.gis.geos import GEOSGeometry diff --git a/tests/runtests.py b/tests/runtests.py index f81fe74c3f7..a1c1dfdb1b7 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -73,12 +73,9 @@ def get_test_modules(): modules = [] discovery_paths = [ (None, RUNTESTS_DIR), + # GIS tests are in nested apps + ('gis_tests', os.path.join(RUNTESTS_DIR, 'gis_tests')), ] - # GIS tests are in nested apps - if connection.features.gis_enabled: - discovery_paths.append( - ('gis_tests', os.path.join(RUNTESTS_DIR, 'gis_tests')) - ) for modpath, dirpath in discovery_paths: for f in os.listdir(dirpath):