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

This commit is contained in:
Loic Bistuer 2013-12-18 09:33:41 +07:00 committed by Tim Graham
parent b62031441b
commit 2fd7fc134c
2 changed files with 26 additions and 1 deletions

View File

@ -79,7 +79,7 @@ class ErrorDict(dict):
@python_2_unicode_compatible
class ErrorList(UserList):
class ErrorList(UserList, list):
"""
A collection of errors that knows how to display itself in various formats.
"""

View File

@ -15,6 +15,7 @@ from django.forms import (
NullBooleanField, PasswordInput, RadioSelect, Select, SplitDateTimeField,
Textarea, TextInput, ValidationError, widgets,
)
from django.forms.utils import ErrorList
from django.http import QueryDict
from django.template import Template, Context
from django.test import TestCase
@ -2069,3 +2070,27 @@ class FormsTestCase(TestCase):
'__all__': [{'code': 'secret', 'message': 'Non-field error.'}]
}
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"}]
)