Added new srs test and various cleaning
This commit is contained in:
parent
e9d12bae1e
commit
fabc678f93
|
@ -3,6 +3,8 @@ import unittest
|
|||
from django.contrib.gis.gdal import HAS_GDAL
|
||||
from django.contrib.gis.tests.utils import (no_mysql, oracle, postgis,
|
||||
spatialite, HAS_SPATIALREFSYS, SpatialRefSys)
|
||||
from django.contrib.gis.utils import add_srs_entry
|
||||
from django.db import connection
|
||||
from django.utils import six
|
||||
|
||||
|
||||
|
@ -38,8 +40,10 @@ test_srs = ({'srid': 4326,
|
|||
class SpatialRefSysTest(unittest.TestCase):
|
||||
|
||||
@no_mysql
|
||||
def test01_retrieve(self):
|
||||
"Testing retrieval of SpatialRefSys model objects."
|
||||
def test_retrieve(self):
|
||||
"""
|
||||
Test retrieval of SpatialRefSys model objects.
|
||||
"""
|
||||
for sd in test_srs:
|
||||
srs = SpatialRefSys.objects.get(srid=sd['srid'])
|
||||
self.assertEqual(sd['srid'], srs.srid)
|
||||
|
@ -59,8 +63,10 @@ class SpatialRefSysTest(unittest.TestCase):
|
|||
six.assertRegex(self, srs.proj4text, sd['proj4_re'])
|
||||
|
||||
@no_mysql
|
||||
def test02_osr(self):
|
||||
"Testing getting OSR objects from SpatialRefSys model objects."
|
||||
def test_osr(self):
|
||||
"""
|
||||
Test getting OSR objects from SpatialRefSys model objects.
|
||||
"""
|
||||
for sd in test_srs:
|
||||
sr = SpatialRefSys.objects.get(srid=sd['srid'])
|
||||
self.assertEqual(True, sr.spheroid.startswith(sd['spheroid']))
|
||||
|
@ -76,13 +82,15 @@ class SpatialRefSysTest(unittest.TestCase):
|
|||
if postgis or spatialite:
|
||||
srs = sr.srs
|
||||
six.assertRegex(self, srs.proj4, sd['proj4_re'])
|
||||
# No `srtext` field in the `spatial_ref_sys` table in SpatiaLite
|
||||
if not spatialite:
|
||||
# No `srtext` field in the `spatial_ref_sys` table in SpatiaLite < 4
|
||||
if not spatialite or connection.ops.spatial_version[0] >= 4:
|
||||
self.assertTrue(srs.wkt.startswith(sd['srtext']))
|
||||
|
||||
@no_mysql
|
||||
def test03_ellipsoid(self):
|
||||
"Testing the ellipsoid property."
|
||||
def test_ellipsoid(self):
|
||||
"""
|
||||
Test the ellipsoid property.
|
||||
"""
|
||||
for sd in test_srs:
|
||||
# Getting the ellipsoid and precision parameters.
|
||||
ellps1 = sd['ellipsoid']
|
||||
|
@ -95,12 +103,17 @@ class SpatialRefSysTest(unittest.TestCase):
|
|||
for i in range(3):
|
||||
self.assertAlmostEqual(ellps1[i], ellps2[i], prec[i])
|
||||
|
||||
|
||||
def suite():
|
||||
s = unittest.TestSuite()
|
||||
s.addTest(unittest.makeSuite(SpatialRefSysTest))
|
||||
return s
|
||||
|
||||
|
||||
def run(verbosity=2):
|
||||
unittest.TextTestRunner(verbosity=verbosity).run(suite())
|
||||
@no_mysql
|
||||
def test_add_entry(self):
|
||||
"""
|
||||
Test adding a new entry in the SpatialRefSys model using the
|
||||
add_srs_entry utility.
|
||||
"""
|
||||
add_srs_entry(900913)
|
||||
self.assertTrue(
|
||||
SpatialRefSys.objects.filter(srid=900913).exists()
|
||||
)
|
||||
srs = SpatialRefSys.objects.get(srid=900913)
|
||||
self.assertTrue(
|
||||
SpatialRefSys.get_spheroid(srs.wkt).startswith('SPHEROID[')
|
||||
)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from django.contrib.gis.gdal import SpatialReference
|
||||
from django.db import connections, DEFAULT_DB_ALIAS
|
||||
|
||||
|
||||
def add_srs_entry(srs, auth_name='EPSG', auth_srid=None, ref_sys_name=None,
|
||||
|
@ -30,10 +31,9 @@ def add_srs_entry(srs, auth_name='EPSG', auth_srid=None, ref_sys_name=None,
|
|||
|
||||
database:
|
||||
The name of the database connection to use; the default is the value
|
||||
of `django.db.DEFAULT_DB_ALIAS` (at the time of this writing, it's value
|
||||
of `django.db.DEFAULT_DB_ALIAS` (at the time of this writing, its value
|
||||
is 'default').
|
||||
"""
|
||||
from django.db import connections, DEFAULT_DB_ALIAS
|
||||
if not database:
|
||||
database = DEFAULT_DB_ALIAS
|
||||
connection = connections[database]
|
||||
|
|
Loading…
Reference in New Issue