summaryrefslogtreecommitdiff
path: root/tests/forms_tests
diff options
context:
space:
mode:
authorvvojvoda <vedran.vojvoda@gmail.com>2014-02-18 20:00:09 +0100
committerTim Graham <timograham@gmail.com>2014-02-28 07:05:55 -0500
commitc23b3717be71e4b2e5a32f156ef0a7b4703d012d (patch)
tree40eeb5ea2ecc2cb1132ecbff32a17c036d09a353 /tests/forms_tests
parent7b4743580a2ac8e0194fb3781732cfb0bf96c3b7 (diff)
Fixed #21962 -- Added escape_html flag to ErrorDict.as_json()
Diffstat (limited to 'tests/forms_tests')
-rw-r--r--tests/forms_tests/tests/test_forms.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py
index f2a77cb089..f06a31f393 100644
--- a/tests/forms_tests/tests/test_forms.py
+++ b/tests/forms_tests/tests/test_forms.py
@@ -2071,6 +2071,33 @@ class FormsTestCase(TestCase):
}
self.assertEqual(errors, control)
+ def test_error_dict_as_json_escape_html(self):
+ """#21962 - adding html escape flag to ErrorDict"""
+ class MyForm(Form):
+ foo = CharField()
+ bar = CharField()
+
+ def clean(self):
+ raise ValidationError('<p>Non-field error.</p>',
+ code='secret',
+ params={'a': 1, 'b': 2})
+
+ control = {
+ 'foo': [{'code': 'required', 'message': 'This field is required.'}],
+ 'bar': [{'code': 'required', 'message': 'This field is required.'}],
+ '__all__': [{'code': 'secret', 'message': '<p>Non-field error.</p>'}]
+ }
+
+ form = MyForm({})
+ self.assertFalse(form.is_valid())
+
+ errors = json.loads(form.errors.as_json())
+ self.assertEqual(errors, control)
+
+ errors = json.loads(form.errors.as_json(escape_html=True))
+ control['__all__'][0]['message'] = '&lt;p&gt;Non-field error.&lt;/p&gt;'
+ self.assertEqual(errors, control)
+
def test_error_list(self):
e = ErrorList()
e.append('Foo')