Stopped conditional discovery of gis_tests apps

Refs #23879.
This commit is contained in:
Claude Paroz 2015-04-04 18:09:46 +02:00
parent 8097e54832
commit 6b6d13bf6e
15 changed files with 83 additions and 21 deletions

6
tests/gis_tests/admin.py Normal file
View File

@ -0,0 +1,6 @@
try:
from django.contrib.gis import admin
except ImportError:
from django.contrib import admin
admin.OSMGeoAdmin = admin.ModelAdmin

View File

@ -1,6 +1,6 @@
from django.contrib.gis.db import models
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
from ..models import models
from ..utils import gisfield_may_be_null from ..utils import gisfield_may_be_null
@ -12,6 +12,7 @@ class NamedModel(models.Model):
class Meta: class Meta:
abstract = True abstract = True
required_db_features = ['gis_enabled']
def __str__(self): def __str__(self):
return self.name return self.name

View File

@ -1,6 +1,7 @@
from django.contrib.gis.db import models
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
from ..models import models
@python_2_unicode_compatible @python_2_unicode_compatible
class NamedModel(models.Model): class NamedModel(models.Model):
@ -10,6 +11,7 @@ class NamedModel(models.Model):
class Meta: class Meta:
abstract = True abstract = True
required_db_features = ['gis_enabled']
def __str__(self): def __str__(self):
return self.name return self.name
@ -49,6 +51,7 @@ class SimpleModel(models.Model):
class Meta: class Meta:
abstract = True abstract = True
required_db_features = ['gis_enabled']
class Point2D(SimpleModel): class Point2D(SimpleModel):

View File

@ -17,7 +17,7 @@ if HAS_GEOS:
from .models import (City3D, Interstate2D, Interstate3D, InterstateProj2D, from .models import (City3D, Interstate2D, Interstate3D, InterstateProj2D,
InterstateProj3D, Point2D, Point3D, MultiPoint3D, Polygon2D, Polygon3D) InterstateProj3D, Point2D, Point3D, MultiPoint3D, Polygon2D, Polygon3D)
if HAS_GDAL: if HAS_GDAL:
from django.contrib.gis.utils import LayerMapping, LayerMapError from django.contrib.gis.utils import LayerMapping, LayerMapError

View File

@ -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 django.utils.encoding import python_2_unicode_compatible
from ..admin import admin
from ..models import models
@python_2_unicode_compatible @python_2_unicode_compatible
class City(models.Model): class City(models.Model):
@ -12,6 +13,7 @@ class City(models.Model):
class Meta: class Meta:
app_label = 'geoadmin' app_label = 'geoadmin'
required_db_features = ['gis_enabled']
def __str__(self): def __str__(self):
return self.name return self.name

View File

@ -1,6 +1,6 @@
from django.contrib.gis.db import models
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
from ..models import models
from ..utils import gisfield_may_be_null from ..utils import gisfield_may_be_null
@ -12,6 +12,7 @@ class NamedModel(models.Model):
class Meta: class Meta:
abstract = True abstract = True
required_db_features = ['gis_enabled']
def __str__(self): def __str__(self):
return self.name return self.name
@ -26,6 +27,7 @@ class City(NamedModel):
class Meta: class Meta:
app_label = 'geoapp' app_label = 'geoapp'
required_db_features = ['gis_enabled']
# This is an inherited model from City # This is an inherited model from City
@ -39,6 +41,7 @@ class PennsylvaniaCity(City):
class Meta: class Meta:
app_label = 'geoapp' app_label = 'geoapp'
required_db_features = ['gis_enabled']
class State(NamedModel): class State(NamedModel):
@ -46,6 +49,7 @@ class State(NamedModel):
class Meta: class Meta:
app_label = 'geoapp' app_label = 'geoapp'
required_db_features = ['gis_enabled']
class Track(NamedModel): class Track(NamedModel):
@ -59,6 +63,7 @@ class MultiFields(NamedModel):
class Meta: class Meta:
unique_together = ('city', 'point') unique_together = ('city', 'point')
required_db_features = ['gis_enabled']
class Truth(models.Model): class Truth(models.Model):
@ -66,6 +71,9 @@ class Truth(models.Model):
objects = models.GeoManager() objects = models.GeoManager()
class Meta:
required_db_features = ['gis_enabled']
class Feature(NamedModel): class Feature(NamedModel):
geom = models.GeometryField() geom = models.GeometryField()
@ -76,6 +84,9 @@ class MinusOneSRID(models.Model):
objects = models.GeoManager() objects = models.GeoManager()
class Meta:
required_db_features = ['gis_enabled']
class NonConcreteField(models.IntegerField): class NonConcreteField(models.IntegerField):

View File

@ -1,6 +1,7 @@
from django.contrib.gis.db import models
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
from ..models import models
@python_2_unicode_compatible @python_2_unicode_compatible
class NamedModel(models.Model): class NamedModel(models.Model):
@ -10,6 +11,7 @@ class NamedModel(models.Model):
class Meta: class Meta:
abstract = True abstract = True
required_db_features = ['gis_enabled']
def __str__(self): def __str__(self):
return self.name return self.name
@ -20,6 +22,7 @@ class City(NamedModel):
class Meta: class Meta:
app_label = 'geogapp' app_label = 'geogapp'
required_db_features = ['gis_enabled']
class Zipcode(NamedModel): class Zipcode(NamedModel):
@ -33,6 +36,7 @@ class County(NamedModel):
class Meta: class Meta:
app_label = 'geogapp' app_label = 'geogapp'
required_db_features = ['gis_enabled']
def __str__(self): def __str__(self):
return ' County, '.join([self.name, self.state]) return ' County, '.join([self.name, self.state])

View File

@ -1,6 +1,7 @@
import django.contrib.gis.db.models.fields
from django.db import migrations, models from django.db import migrations, models
from ...models import models as gis_models
class Migration(migrations.Migration): class Migration(migrations.Migration):
""" """
@ -12,9 +13,10 @@ class Migration(migrations.Migration):
fields=[ fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=100, unique=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={ options={
'required_db_features': ['gis_enabled'],
}, },
bases=(models.Model,), bases=(models.Model,),
), ),
@ -25,9 +27,10 @@ class Migration(migrations.Migration):
('neighborhood', models.ForeignKey(to='gis_migrations.Neighborhood', to_field='id', null=True)), ('neighborhood', models.ForeignKey(to='gis_migrations.Neighborhood', to_field='id', null=True)),
('address', models.CharField(max_length=100)), ('address', models.CharField(max_length=100)),
('zip_code', models.IntegerField(null=True, blank=True)), ('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={ options={
'required_db_features': ['gis_enabled'],
}, },
bases=(models.Model,), bases=(models.Model,),
), ),

View File

@ -1,4 +1,4 @@
from django.contrib.gis.db import models from ..models import models
class AllOGRFields(models.Model): class AllOGRFields(models.Model):
@ -15,6 +15,9 @@ class AllOGRFields(models.Model):
objects = models.GeoManager() objects = models.GeoManager()
class Meta:
required_db_features = ['gis_enabled']
class Fields3D(models.Model): class Fields3D(models.Model):
point = models.PointField(dim=3) point = models.PointField(dim=3)
@ -22,3 +25,6 @@ class Fields3D(models.Model):
poly = models.PolygonField(dim=3) poly = models.PolygonField(dim=3)
objects = models.GeoManager() objects = models.GeoManager()
class Meta:
required_db_features = ['gis_enabled']

View File

@ -1,6 +1,7 @@
from django.contrib.gis.db import models
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
from ..models import models
@python_2_unicode_compatible @python_2_unicode_compatible
class NamedModel(models.Model): class NamedModel(models.Model):
@ -10,6 +11,7 @@ class NamedModel(models.Model):
class Meta: class Meta:
abstract = True abstract = True
required_db_features = ['gis_enabled']
def __str__(self): def __str__(self):
return self.name return self.name
@ -38,6 +40,7 @@ class City(NamedModel):
class Meta: class Meta:
app_label = 'layermap' app_label = 'layermap'
required_db_features = ['gis_enabled']
class Interstate(NamedModel): class Interstate(NamedModel):
@ -46,6 +49,7 @@ class Interstate(NamedModel):
class Meta: class Meta:
app_label = 'layermap' app_label = 'layermap'
required_db_features = ['gis_enabled']
# Same as `City` above, but for testing model inheritance. # Same as `City` above, but for testing model inheritance.
@ -72,6 +76,9 @@ class ICity2(ICity1):
class Invalid(models.Model): class Invalid(models.Model):
point = models.PointField() point = models.PointField()
class Meta:
required_db_features = ['gis_enabled']
# Mapping dictionaries for the models above. # Mapping dictionaries for the models above.
co_mapping = { co_mapping = {

View File

@ -9,11 +9,12 @@ from unittest import skipUnless
from django.conf import settings from django.conf import settings
from django.contrib.gis.gdal import HAS_GDAL from django.contrib.gis.gdal import HAS_GDAL
from django.contrib.gis.geos import HAS_GEOS
from django.db import connection from django.db import connection
from django.test import TestCase, override_settings, skipUnlessDBFeature from django.test import TestCase, override_settings, skipUnlessDBFeature
from django.utils._os import upath from django.utils._os import upath
if HAS_GDAL: if HAS_GEOS and HAS_GDAL:
from django.contrib.gis.utils.layermapping import (LayerMapping, from django.contrib.gis.utils.layermapping import (LayerMapping,
LayerMapError, InvalidDecimal, InvalidString, MissingForeignKey) LayerMapError, InvalidDecimal, InvalidString, MissingForeignKey)
from django.contrib.gis.gdal import DataSource from django.contrib.gis.gdal import DataSource

18
tests/gis_tests/models.py Normal file
View File

@ -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

View File

@ -1,6 +1,7 @@
from django.contrib.gis.db import models
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
from ..models import models
class SimpleModel(models.Model): class SimpleModel(models.Model):
@ -8,6 +9,7 @@ class SimpleModel(models.Model):
class Meta: class Meta:
abstract = True abstract = True
required_db_features = ['gis_enabled']
@python_2_unicode_compatible @python_2_unicode_compatible

View File

@ -1,12 +1,13 @@
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.geos import HAS_GEOS
from django.forms import ValidationError from django.forms import ValidationError
from django.test import SimpleTestCase, skipUnlessDBFeature from django.test import SimpleTestCase, skipUnlessDBFeature
from django.utils import six from django.utils import six
from django.utils.html import escape 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 import forms
from django.contrib.gis.geos import GEOSGeometry from django.contrib.gis.geos import GEOSGeometry

View File

@ -73,12 +73,9 @@ def get_test_modules():
modules = [] modules = []
discovery_paths = [ discovery_paths = [
(None, RUNTESTS_DIR), (None, RUNTESTS_DIR),
]
# GIS tests are in nested apps # GIS tests are in nested apps
if connection.features.gis_enabled: ('gis_tests', os.path.join(RUNTESTS_DIR, 'gis_tests')),
discovery_paths.append( ]
('gis_tests', os.path.join(RUNTESTS_DIR, 'gis_tests'))
)
for modpath, dirpath in discovery_paths: for modpath, dirpath in discovery_paths:
for f in os.listdir(dirpath): for f in os.listdir(dirpath):