mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Replaced django.test.utils.patch_logger() with assertLogs().
Thanks Tim Graham for the review.
This commit is contained in:
parent
7d3fe36c62
commit
607970f31c
13 changed files with 97 additions and 157 deletions
|
@ -1,7 +1,6 @@
|
|||
from django.contrib.gis import admin
|
||||
from django.contrib.gis.geos import Point
|
||||
from django.test import TestCase, override_settings
|
||||
from django.test.utils import patch_logger
|
||||
|
||||
from .admin import UnmodifiableAdmin
|
||||
from .models import City, site
|
||||
|
@ -73,28 +72,28 @@ class GeoAdminTest(TestCase):
|
|||
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'])
|
||||
with self.assertRaisesMessage(AssertionError, 'no logs'):
|
||||
with self.assertLogs('django.contrib.gis', 'ERROR'):
|
||||
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:
|
||||
with self.assertLogs('django.contrib.gis', 'ERROR') as cm:
|
||||
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(len(cm.records), 1)
|
||||
self.assertEqual(
|
||||
logger_calls[0],
|
||||
cm.records[0].getMessage(),
|
||||
"Error creating geometry from value 'INVALID()' (String input "
|
||||
"unrecognized as WKT EWKT, and HEXEWKB.)"
|
||||
)
|
||||
|
|
|
@ -5,7 +5,6 @@ from django.contrib.gis.forms import BaseGeometryWidget, OpenLayersWidget
|
|||
from django.contrib.gis.geos import GEOSGeometry
|
||||
from django.forms import ValidationError
|
||||
from django.test import SimpleTestCase, override_settings
|
||||
from django.test.utils import patch_logger
|
||||
from django.utils.html import escape
|
||||
|
||||
|
||||
|
@ -120,7 +119,7 @@ class GeometryFieldTest(SimpleTestCase):
|
|||
'pt3': 'PNT(0)', # invalid
|
||||
})
|
||||
|
||||
with patch_logger('django.contrib.gis', 'error') as logger_calls:
|
||||
with self.assertLogs('django.contrib.gis', 'ERROR') as logger_calls:
|
||||
output = str(form)
|
||||
|
||||
# The first point can't use assertInHTML() due to non-deterministic
|
||||
|
@ -142,9 +141,9 @@ class GeometryFieldTest(SimpleTestCase):
|
|||
)
|
||||
# Only the invalid PNT(0) triggers an error log entry.
|
||||
# Deserialization is called in form clean and in widget rendering.
|
||||
self.assertEqual(len(logger_calls), 2)
|
||||
self.assertEqual(len(logger_calls.records), 2)
|
||||
self.assertEqual(
|
||||
logger_calls[0],
|
||||
logger_calls.records[0].getMessage(),
|
||||
"Error creating geometry from value 'PNT(0)' (String input "
|
||||
"unrecognized as WKT EWKT, and HEXEWKB.)"
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue