|
@@ -2,6 +2,7 @@ from django.contrib.gis import forms
|
|
|
from django.contrib.gis.geos import GEOSGeometry
|
|
|
from django.forms import ValidationError
|
|
|
from django.test import SimpleTestCase, override_settings, skipUnlessDBFeature
|
|
|
+from django.test.utils import patch_logger
|
|
|
from django.utils.html import escape
|
|
|
|
|
|
|
|
@@ -84,6 +85,48 @@ class GeometryFieldTest(SimpleTestCase):
|
|
|
form = PointForm(data={'pt': 'POINT(5 23)'}, initial={'pt': point})
|
|
|
self.assertFalse(form.has_changed())
|
|
|
|
|
|
+ def test_field_string_value(self):
|
|
|
+ """
|
|
|
+ Initialization of a geometry field with a valid/empty/invalid string.
|
|
|
+ Only the invalid string should trigger an error log entry.
|
|
|
+ """
|
|
|
+ class PointForm(forms.Form):
|
|
|
+ pt1 = forms.PointField(srid=4326)
|
|
|
+ pt2 = forms.PointField(srid=4326)
|
|
|
+ pt3 = forms.PointField(srid=4326)
|
|
|
+
|
|
|
+ form = PointForm({
|
|
|
+ 'pt1': 'SRID=4326;POINT(7.3 44)', # valid
|
|
|
+ 'pt2': '', # empty
|
|
|
+ 'pt3': 'PNT(0)', # invalid
|
|
|
+ })
|
|
|
+
|
|
|
+ with patch_logger('django.contrib.gis', 'error') as logger_calls:
|
|
|
+ output = str(form)
|
|
|
+
|
|
|
+ self.assertInHTML(
|
|
|
+ '<textarea id="id_pt1" class="vSerializedField required" cols="150"'
|
|
|
+ ' rows="10" name="pt1">POINT (7.3 44)</textarea>',
|
|
|
+ output
|
|
|
+ )
|
|
|
+ self.assertInHTML(
|
|
|
+ '<textarea id="id_pt2" class="vSerializedField required" cols="150"'
|
|
|
+ ' rows="10" name="pt2"></textarea>',
|
|
|
+ output
|
|
|
+ )
|
|
|
+ self.assertInHTML(
|
|
|
+ '<textarea id="id_pt3" class="vSerializedField required" cols="150"'
|
|
|
+ ' rows="10" name="pt3"></textarea>',
|
|
|
+ output
|
|
|
+ )
|
|
|
+ # Only the invalid PNT(0) should trigger an error log entry
|
|
|
+ self.assertEqual(len(logger_calls), 1)
|
|
|
+ self.assertEqual(
|
|
|
+ logger_calls[0],
|
|
|
+ "Error creating geometry from value 'PNT(0)' (String or unicode input "
|
|
|
+ "unrecognized as WKT EWKT, and HEXEWKB.)"
|
|
|
+ )
|
|
|
+
|
|
|
|
|
|
@skipUnlessDBFeature("gis_enabled")
|
|
|
class SpecializedFieldTest(SimpleTestCase):
|