|
1 | 1 | from io import StringIO |
| 2 | +from unittest import skipIf |
2 | 3 |
|
3 | 4 | from django.contrib.gis import gdal |
4 | 5 | from django.contrib.gis.db.models import Extent, MakeLine, Union, functions |
|
21 | 22 | from django.test import TestCase, skipUnlessDBFeature |
22 | 23 | from django.test.utils import CaptureQueriesContext |
23 | 24 |
|
24 | | -from ..utils import skipUnlessGISLookup |
| 25 | +from ..utils import cannot_save_multipoint, skipUnlessGISLookup |
25 | 26 | from .models import ( |
26 | 27 | City, |
27 | 28 | Country, |
28 | 29 | Feature, |
| 30 | + GeometryCollectionModel, |
| 31 | + Lines, |
29 | 32 | MinusOneSRID, |
30 | 33 | MultiFields, |
31 | 34 | NonConcreteModel, |
32 | 35 | PennsylvaniaCity, |
| 36 | + Points, |
33 | 37 | State, |
34 | 38 | ThreeDimensionalFeature, |
35 | 39 | Track, |
@@ -269,6 +273,48 @@ def test_empty_geometries(self): |
269 | 273 | self.assertEqual(feature.geom.srid, g.srid) |
270 | 274 |
|
271 | 275 |
|
| 276 | +class SaveLoadTests(TestCase): |
| 277 | + def test_multilinestringfield(self): |
| 278 | + geom = MultiLineString( |
| 279 | + LineString((0, 0), (1, 1), (5, 5)), |
| 280 | + LineString((0, 0), (0, 5), (5, 5), (5, 0), (0, 0)), |
| 281 | + ) |
| 282 | + obj = Lines.objects.create(geom=geom) |
| 283 | + obj.refresh_from_db() |
| 284 | + self.assertEqual(obj.geom.tuple, geom.tuple) |
| 285 | + |
| 286 | + def test_multilinestring_with_linearring(self): |
| 287 | + geom = MultiLineString( |
| 288 | + LineString((0, 0), (1, 1), (5, 5)), |
| 289 | + LinearRing((0, 0), (0, 5), (5, 5), (5, 0), (0, 0)), |
| 290 | + ) |
| 291 | + obj = Lines.objects.create(geom=geom) |
| 292 | + obj.refresh_from_db() |
| 293 | + self.assertEqual(obj.geom.tuple, geom.tuple) |
| 294 | + self.assertEqual(obj.geom[1].__class__.__name__, "LineString") |
| 295 | + self.assertEqual(obj.geom[0].tuple, geom[0].tuple) |
| 296 | + # LinearRings are transformed to LineString. |
| 297 | + self.assertEqual(obj.geom[1].__class__.__name__, "LineString") |
| 298 | + self.assertEqual(obj.geom[1].tuple, geom[1].tuple) |
| 299 | + |
| 300 | + @skipIf(cannot_save_multipoint, "MariaDB cannot save MultiPoint due to a bug.") |
| 301 | + def test_multipointfield(self): |
| 302 | + geom = MultiPoint(Point(1, 1), Point(0, 0)) |
| 303 | + obj = Points.objects.create(geom=geom) |
| 304 | + obj.refresh_from_db() |
| 305 | + self.assertEqual(obj.geom, geom) |
| 306 | + |
| 307 | + def test_geometrycollectionfield(self): |
| 308 | + geom = GeometryCollection( |
| 309 | + Point(2, 2), |
| 310 | + LineString((0, 0), (2, 2)), |
| 311 | + Polygon(LinearRing((0, 0), (0, 5), (5, 5), (5, 0), (0, 0))), |
| 312 | + ) |
| 313 | + obj = GeometryCollectionModel.objects.create(geom=geom) |
| 314 | + obj.refresh_from_db() |
| 315 | + self.assertIs(obj.geom.equals(geom), True) |
| 316 | + |
| 317 | + |
272 | 318 | class GeoLookupTest(TestCase): |
273 | 319 | fixtures = ["initial"] |
274 | 320 |
|
|
0 commit comments