From 333960582170457473aafe24dbcb8502af7d8ffc Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Wed, 1 Oct 2014 21:24:10 +0200 Subject: [PATCH] Added a dumpdata/loaddata test for geographic content --- django/contrib/gis/geos/geometry.py | 5 ++--- django/contrib/gis/tests/geoapp/tests.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/django/contrib/gis/geos/geometry.py b/django/contrib/gis/geos/geometry.py index fb36306503..9299d3e397 100644 --- a/django/contrib/gis/geos/geometry.py +++ b/django/contrib/gis/geos/geometry.py @@ -376,9 +376,8 @@ class GEOSGeometry(GEOSBase, ListMixin): @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) diff --git a/django/contrib/gis/tests/geoapp/tests.py b/django/contrib/gis/tests/geoapp/tests.py index 3d4cd3de9f..4b4d4ddce8 100644 --- a/django/contrib/gis/tests/geoapp/tests.py +++ b/django/contrib/gis/tests/geoapp/tests.py @@ -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 @@ -203,6 +205,24 @@ class GeoModelTest(TestCase): 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):