Added a dumpdata/loaddata test for geographic content
This commit is contained in:
parent
20f868bc5a
commit
3339605821
|
@ -376,9 +376,8 @@ class GEOSGeometry(GEOSBase, ListMixin):
|
||||||
@property
|
@property
|
||||||
def ewkt(self):
|
def ewkt(self):
|
||||||
"""
|
"""
|
||||||
Returns the EWKT (WKT + SRID) of the Geometry. Note that Z values
|
Returns the EWKT (SRID + WKT) of the Geometry. Note that Z values
|
||||||
are *not* included in this representation because GEOS does not yet
|
are only included in this representation if GEOS >= 3.3.0.
|
||||||
support serializing them.
|
|
||||||
"""
|
"""
|
||||||
if self.get_srid():
|
if self.get_srid():
|
||||||
return 'SRID=%s;%s' % (self.srid, self.wkt)
|
return 'SRID=%s;%s' % (self.srid, self.wkt)
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
from tempfile import NamedTemporaryFile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.contrib.gis import gdal
|
from django.contrib.gis import gdal
|
||||||
from django.contrib.gis.geos import HAS_GEOS
|
from django.contrib.gis.geos import HAS_GEOS
|
||||||
from django.contrib.gis.tests.utils import no_oracle, oracle, postgis, spatialite
|
from django.contrib.gis.tests.utils import no_oracle, oracle, postgis, spatialite
|
||||||
|
from django.core.management import call_command
|
||||||
from django.test import TestCase, skipUnlessDBFeature
|
from django.test import TestCase, skipUnlessDBFeature
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
|
||||||
|
@ -203,6 +205,24 @@ class GeoModelTest(TestCase):
|
||||||
self.assertEqual(len(cities1), len(list(cities2)))
|
self.assertEqual(len(cities1), len(list(cities2)))
|
||||||
self.assertIsInstance(cities2[0].point, Point)
|
self.assertIsInstance(cities2[0].point, Point)
|
||||||
|
|
||||||
|
def test_dumpdata_loaddata_cycle(self):
|
||||||
|
"""
|
||||||
|
Test a dumpdata/loaddata cycle with geographic data.
|
||||||
|
"""
|
||||||
|
out = six.StringIO()
|
||||||
|
original_data = list(City.objects.all().order_by('name'))
|
||||||
|
call_command('dumpdata', 'geoapp.City', stdout=out)
|
||||||
|
result = out.getvalue()
|
||||||
|
houston = City.objects.get(name='Houston')
|
||||||
|
self.assertIn('"point": "%s"' % houston.point.wkt, result)
|
||||||
|
|
||||||
|
# Reload now dumped data
|
||||||
|
with NamedTemporaryFile(mode='w', suffix='.json') as tempfile:
|
||||||
|
tempfile.write(result)
|
||||||
|
tempfile.seek(0)
|
||||||
|
call_command('loaddata', tempfile.name, verbosity=0)
|
||||||
|
self.assertListEqual(original_data, list(City.objects.all().order_by('name')))
|
||||||
|
|
||||||
|
|
||||||
@skipUnlessDBFeature("gis_enabled")
|
@skipUnlessDBFeature("gis_enabled")
|
||||||
class GeoLookupTest(TestCase):
|
class GeoLookupTest(TestCase):
|
||||||
|
|
Loading…
Reference in New Issue