Updated get_ogr_db_string in inspectapp tests to support MySQL/Spatialite
The OGRInspectTest.test_time_field does still not succeed with these databases (even when removing the postgis guard), but at least it's now possible to setup a datasource.
This commit is contained in:
parent
1628dfd0b9
commit
53df89c0fe
|
@ -93,21 +93,24 @@ class OGRInspectTest(TestCase):
|
||||||
|
|
||||||
|
|
||||||
def get_ogr_db_string():
|
def get_ogr_db_string():
|
||||||
# Construct the DB string that GDAL will use to inspect the database.
|
"""
|
||||||
# GDAL will create its own connection to the database, so we re-use the
|
Construct the DB string that GDAL will use to inspect the database.
|
||||||
# connection settings from the Django test. This approach is a bit fragile
|
GDAL will create its own connection to the database, so we re-use the
|
||||||
# and cannot work on any other database other than PostgreSQL at the moment.
|
connection settings from the Django test.
|
||||||
|
"""
|
||||||
db = connections.databases['default']
|
db = connections.databases['default']
|
||||||
|
|
||||||
# Map from the django backend into the OGR driver name and database identifier
|
# Map from the django backend into the OGR driver name and database identifier
|
||||||
# http://www.gdal.org/ogr/ogr_formats.html
|
# http://www.gdal.org/ogr/ogr_formats.html
|
||||||
#
|
#
|
||||||
# TODO: Support Oracle (OCI), MySQL, and SpatiaLite.
|
# TODO: Support Oracle (OCI).
|
||||||
drivers = {
|
drivers = {
|
||||||
'django.contrib.gis.db.backends.postgis': ('PostgreSQL', 'PG'),
|
'django.contrib.gis.db.backends.postgis': ('PostgreSQL', "PG:dbname='%(db_name)s'", ' '),
|
||||||
|
'django.contrib.gis.db.backends.mysql': ('MySQL', 'MYSQL:"%(db_name)s"', ','),
|
||||||
|
'django.contrib.gis.db.backends.spatialite': ('SQLite', '%(db_name)s', '')
|
||||||
}
|
}
|
||||||
|
|
||||||
drv_name, db_str = drivers[db['ENGINE']]
|
drv_name, db_str, param_sep = drivers[db['ENGINE']]
|
||||||
|
|
||||||
# Ensure that GDAL library has driver support for the database.
|
# Ensure that GDAL library has driver support for the database.
|
||||||
try:
|
try:
|
||||||
|
@ -115,10 +118,12 @@ def get_ogr_db_string():
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
# SQLite/Spatialite in-memory databases
|
||||||
|
if db['NAME'] == ":memory:":
|
||||||
|
return None
|
||||||
|
|
||||||
# Build the params of the OGR database connection string
|
# Build the params of the OGR database connection string
|
||||||
# TODO: connection strings are database-dependent, thus if
|
params = [db_str % {'db_name': db['NAME']}]
|
||||||
# we ever test other backends, this will need to change.
|
|
||||||
params = ["dbname='%s'" % db['NAME']]
|
|
||||||
def add(key, template):
|
def add(key, template):
|
||||||
value = db.get(key, None)
|
value = db.get(key, None)
|
||||||
# Don't add the parameter if it is not in django's settings
|
# Don't add the parameter if it is not in django's settings
|
||||||
|
@ -129,4 +134,4 @@ def get_ogr_db_string():
|
||||||
add('USER', "user='%s'")
|
add('USER', "user='%s'")
|
||||||
add('PASSWORD', "password='%s'")
|
add('PASSWORD', "password='%s'")
|
||||||
|
|
||||||
return '%s:%s' % (db_str, ' '.join(params))
|
return param_sep.join(params)
|
||||||
|
|
Loading…
Reference in New Issue