|
@@ -48,12 +48,17 @@ class GeometryFieldTest(SimpleTestCase):
|
|
|
# By default, all geometry types are allowed.
|
|
|
fld = forms.GeometryField()
|
|
|
for wkt in ('POINT(5 23)', 'MULTIPOLYGON(((0 0, 0 1, 1 1, 1 0, 0 0)))', 'LINESTRING(0 0, 1 1)'):
|
|
|
- self.assertEqual(GEOSGeometry(wkt), fld.clean(wkt))
|
|
|
+ # `to_python` uses the SRID of OpenLayersWidget if the converted
|
|
|
+ # value doesn't have an SRID itself.
|
|
|
+ self.assertEqual(GEOSGeometry(wkt, srid=fld.widget.map_srid), fld.clean(wkt))
|
|
|
|
|
|
pnt_fld = forms.GeometryField(geom_type='POINT')
|
|
|
- self.assertEqual(GEOSGeometry('POINT(5 23)'), pnt_fld.clean('POINT(5 23)'))
|
|
|
+ self.assertEqual(GEOSGeometry('POINT(5 23)', srid=pnt_fld.widget.map_srid), pnt_fld.clean('POINT(5 23)'))
|
|
|
# a WKT for any other geom_type will be properly transformed by `to_python`
|
|
|
- self.assertEqual(GEOSGeometry('LINESTRING(0 0, 1 1)'), pnt_fld.to_python('LINESTRING(0 0, 1 1)'))
|
|
|
+ self.assertEqual(
|
|
|
+ GEOSGeometry('LINESTRING(0 0, 1 1)', srid=pnt_fld.widget.map_srid),
|
|
|
+ pnt_fld.to_python('LINESTRING(0 0, 1 1)')
|
|
|
+ )
|
|
|
# but rejected by `clean`
|
|
|
with self.assertRaises(forms.ValidationError):
|
|
|
pnt_fld.clean('LINESTRING(0 0, 1 1)')
|
|
@@ -66,7 +71,7 @@ class GeometryFieldTest(SimpleTestCase):
|
|
|
fld = forms.GeometryField()
|
|
|
# to_python returns the same GEOSGeometry for a WKT
|
|
|
for wkt in ('POINT(5 23)', 'MULTIPOLYGON(((0 0, 0 1, 1 1, 1 0, 0 0)))', 'LINESTRING(0 0, 1 1)'):
|
|
|
- self.assertEqual(GEOSGeometry(wkt), fld.to_python(wkt))
|
|
|
+ self.assertEqual(GEOSGeometry(wkt, srid=fld.widget.map_srid), fld.to_python(wkt))
|
|
|
# but raises a ValidationError for any other string
|
|
|
for wkt in ('POINT(5)', 'MULTI POLYGON(((0 0, 0 1, 1 1, 1 0, 0 0)))', 'BLAH(0 0, 1 1)'):
|
|
|
with self.assertRaises(forms.ValidationError):
|
|
@@ -78,7 +83,7 @@ class GeometryFieldTest(SimpleTestCase):
|
|
|
|
|
|
form = PointForm()
|
|
|
cleaned_pt = form.fields['pt'].clean('POINT(5 23)')
|
|
|
- self.assertEqual(cleaned_pt, GEOSGeometry('POINT(5 23)'))
|
|
|
+ self.assertEqual(cleaned_pt, GEOSGeometry('POINT(5 23)', srid=4326))
|
|
|
self.assertEqual(4326, cleaned_pt.srid)
|
|
|
|
|
|
point = GEOSGeometry('SRID=4326;POINT(5 23)')
|