2013-09-24 10:22:50 +00:00
|
|
|
from unittest import skip
|
|
|
|
|
2008-08-05 18:13:06 +00:00
|
|
|
from django.conf import settings
|
2009-12-22 15:18:51 +00:00
|
|
|
from django.db import DEFAULT_DB_ALIAS
|
2008-08-05 18:13:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
def no_backend(test_func, backend):
|
|
|
|
"Use this decorator to disable test on specified backend."
|
2009-12-22 15:18:51 +00:00
|
|
|
if settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'].rsplit('.')[-1] == backend:
|
2013-09-24 10:22:50 +00:00
|
|
|
@skip("This test is skipped on '%s' backend" % backend)
|
|
|
|
def inner():
|
|
|
|
pass
|
|
|
|
return inner
|
2008-08-05 18:13:06 +00:00
|
|
|
else:
|
|
|
|
return test_func
|
|
|
|
|
|
|
|
# Decorators to disable entire test functions for specific
|
|
|
|
# spatial backends.
|
2013-10-17 08:17:41 +00:00
|
|
|
def no_oracle(func):
|
|
|
|
return no_backend(func, 'oracle')
|
|
|
|
|
|
|
|
def no_postgis(func):
|
|
|
|
return no_backend(func, 'postgis')
|
|
|
|
|
|
|
|
def no_mysql(func):
|
|
|
|
return no_backend(func, 'mysql')
|
|
|
|
|
|
|
|
def no_spatialite(func):
|
|
|
|
return no_backend(func, 'spatialite')
|
2008-08-05 18:13:06 +00:00
|
|
|
|
|
|
|
# Shortcut booleans to omit only portions of tests.
|
2009-12-22 15:18:51 +00:00
|
|
|
_default_db = settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'].rsplit('.')[-1]
|
2013-10-22 13:31:43 +00:00
|
|
|
oracle = _default_db == 'oracle'
|
2009-12-22 15:18:51 +00:00
|
|
|
postgis = _default_db == 'postgis'
|
2013-10-22 13:31:43 +00:00
|
|
|
mysql = _default_db == 'mysql'
|
2009-12-22 15:18:51 +00:00
|
|
|
spatialite = _default_db == 'spatialite'
|
2012-06-17 09:39:02 +00:00
|
|
|
|
|
|
|
HAS_SPATIALREFSYS = True
|
2012-10-27 15:10:41 +00:00
|
|
|
if oracle and 'gis' in settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE']:
|
2012-06-17 09:39:02 +00:00
|
|
|
from django.contrib.gis.db.backends.oracle.models import SpatialRefSys
|
|
|
|
elif postgis:
|
|
|
|
from django.contrib.gis.db.backends.postgis.models import SpatialRefSys
|
|
|
|
elif spatialite:
|
|
|
|
from django.contrib.gis.db.backends.spatialite.models import SpatialRefSys
|
|
|
|
else:
|
|
|
|
HAS_SPATIALREFSYS = False
|
|
|
|
SpatialRefSys = None
|
2013-05-11 03:08:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
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()
|