Skip to content

Commit

Permalink
Added a dumpdata/loaddata test for geographic content
Browse files Browse the repository at this point in the history
  • Loading branch information
claudep authored and kswiat committed Oct 7, 2014
1 parent b818ed5 commit cb62be7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 2 additions & 3 deletions django/contrib/gis/geos/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,8 @@ def set_srid(self, srid):
@property
def ewkt(self):
"""
Returns the EWKT (WKT + SRID) of the Geometry. Note that Z values
are *not* included in this representation because GEOS does not yet
support serializing them.
Returns the EWKT (SRID + WKT) of the Geometry. Note that Z values
are only included in this representation if GEOS >= 3.3.0.
"""
if self.get_srid():
return 'SRID=%s;%s' % (self.srid, self.wkt)
Expand Down
20 changes: 20 additions & 0 deletions django/contrib/gis/tests/geoapp/tests.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from __future__ import unicode_literals

import re
from tempfile import NamedTemporaryFile
import unittest

from django.db import connection
from django.contrib.gis import gdal
from django.contrib.gis.geos import HAS_GEOS
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.utils import six

Expand Down Expand Up @@ -203,6 +205,24 @@ def test_raw_sql_query(self):
self.assertEqual(len(cities1), len(list(cities2)))
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")
class GeoLookupTest(TestCase):
Expand Down

0 comments on commit cb62be7

Please sign in to comment.