Kaydet (Commit) 2fd7fc13 authored tarafından Loic Bistuer's avatar Loic Bistuer Kaydeden (comit) Tim Graham

Refs #17413 -- Added isinstance backward compatibility on ErrorList.

üst b6203144
...@@ -79,7 +79,7 @@ class ErrorDict(dict): ...@@ -79,7 +79,7 @@ class ErrorDict(dict):
@python_2_unicode_compatible @python_2_unicode_compatible
class ErrorList(UserList): class ErrorList(UserList, list):
""" """
A collection of errors that knows how to display itself in various formats. A collection of errors that knows how to display itself in various formats.
""" """
......
...@@ -15,6 +15,7 @@ from django.forms import ( ...@@ -15,6 +15,7 @@ from django.forms import (
NullBooleanField, PasswordInput, RadioSelect, Select, SplitDateTimeField, NullBooleanField, PasswordInput, RadioSelect, Select, SplitDateTimeField,
Textarea, TextInput, ValidationError, widgets, Textarea, TextInput, ValidationError, widgets,
) )
from django.forms.utils import ErrorList
from django.http import QueryDict from django.http import QueryDict
from django.template import Template, Context from django.template import Template, Context
from django.test import TestCase from django.test import TestCase
...@@ -2069,3 +2070,27 @@ class FormsTestCase(TestCase): ...@@ -2069,3 +2070,27 @@ class FormsTestCase(TestCase):
'__all__': [{'code': 'secret', 'message': 'Non-field error.'}] '__all__': [{'code': 'secret', 'message': 'Non-field error.'}]
} }
self.assertEqual(errors, control) self.assertEqual(errors, control)
def test_error_list(self):
e = ErrorList()
e.append('Foo')
e.append(ValidationError('Foo%(bar)s', code='foobar', params={'bar': 'bar'}))
self.assertTrue(isinstance(e, list))
self.assertIn('Foo', e)
self.assertIn('Foo', forms.ValidationError(e))
self.assertEqual(
e.as_text(),
'* Foo\n* Foobar'
)
self.assertEqual(
e.as_ul(),
'<ul class="errorlist"><li>Foo</li><li>Foobar</li></ul>'
)
self.assertEqual(
json.loads(e.as_json()),
[{"message": "Foo", "code": ""}, {"message": "Foobar", "code": "foobar"}]
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment