summaryrefslogtreecommitdiff
path: root/tests/forms_tests
diff options
context:
space:
mode:
authorDan Strokirk <dan.strokirk@gmail.com>2021-06-24 17:15:25 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-06-28 11:02:08 +0200
commitf5ea9aa2f32c7ca9a1fdf793580fddba3daae1b9 (patch)
tree663ceceac46833d77dd678d5eba50e95ebdb5679 /tests/forms_tests
parent66af94d56ea08ccf8d906708a6cc002dd3ab24d3 (diff)
Fixed #32807 -- Fixed JSONField crash when redisplaying None values.
Thanks to Alex Hill for the initial patch.
Diffstat (limited to 'tests/forms_tests')
-rw-r--r--tests/forms_tests/field_tests/test_jsonfield.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/forms_tests/field_tests/test_jsonfield.py b/tests/forms_tests/field_tests/test_jsonfield.py
index 46ef0005f6..b4f3e74f6a 100644
--- a/tests/forms_tests/field_tests/test_jsonfield.py
+++ b/tests/forms_tests/field_tests/test_jsonfield.py
@@ -97,6 +97,21 @@ class JSONFieldTest(SimpleTestCase):
form = JSONForm({'json_field': '["bar"]'}, initial={'json_field': ['foo']})
self.assertIn('[&quot;foo&quot;]</textarea>', form.as_p())
+ def test_redisplay_none_input(self):
+ class JSONForm(Form):
+ json_field = JSONField(required=True)
+
+ tests = [
+ {},
+ {'json_field': None},
+ ]
+ for data in tests:
+ with self.subTest(data=data):
+ form = JSONForm(data)
+ self.assertEqual(form['json_field'].value(), 'null')
+ self.assertIn('null</textarea>', form.as_p())
+ self.assertEqual(form.errors['json_field'], ['This field is required.'])
+
def test_redisplay_wrong_input(self):
"""
Displaying a bound form (typically due to invalid input). The form