mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #27024 -- Prevented logging error with empty string as geometry widget value
Thanks Gavin Wahl for the report, and Tim Graham for the review.
This commit is contained in:
parent
2a11d2d7a7
commit
a7863c78b7
4 changed files with 75 additions and 2 deletions
|
@ -3,6 +3,7 @@ from __future__ import unicode_literals
|
|||
from django.contrib.gis import admin
|
||||
from django.contrib.gis.geos import Point
|
||||
from django.test import TestCase, override_settings, skipUnlessDBFeature
|
||||
from django.test.utils import patch_logger
|
||||
|
||||
from .admin import UnmodifiableAdmin
|
||||
from .models import City, site
|
||||
|
@ -71,3 +72,32 @@ class GeoAdminTest(TestCase):
|
|||
self.assertFalse(has_changed(initial, data_same))
|
||||
self.assertFalse(has_changed(initial, data_almost_same))
|
||||
self.assertTrue(has_changed(initial, data_changed))
|
||||
|
||||
def test_olwidget_empty_string(self):
|
||||
geoadmin = site._registry[City]
|
||||
form = geoadmin.get_changelist_form(None)({'point': ''})
|
||||
with patch_logger('django.contrib.gis', 'error') as logger_calls:
|
||||
output = str(form['point'])
|
||||
self.assertInHTML(
|
||||
'<textarea id="id_point" class="vWKTField required" cols="150"'
|
||||
' rows="10" name="point"></textarea>',
|
||||
output
|
||||
)
|
||||
self.assertEqual(logger_calls, [])
|
||||
|
||||
def test_olwidget_invalid_string(self):
|
||||
geoadmin = site._registry[City]
|
||||
form = geoadmin.get_changelist_form(None)({'point': 'INVALID()'})
|
||||
with patch_logger('django.contrib.gis', 'error') as logger_calls:
|
||||
output = str(form['point'])
|
||||
self.assertInHTML(
|
||||
'<textarea id="id_point" class="vWKTField required" cols="150"'
|
||||
' rows="10" name="point"></textarea>',
|
||||
output
|
||||
)
|
||||
self.assertEqual(len(logger_calls), 1)
|
||||
self.assertEqual(
|
||||
logger_calls[0],
|
||||
"Error creating geometry from value 'INVALID()' (String or unicode input "
|
||||
"unrecognized as WKT EWKT, and HEXEWKB.)"
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue