mirror of
https://github.com/django/django.git
synced 2025-10-08 09:40:35 +00:00
[1.10.x] Fixed #26672 -- Fixed HStoreField to raise ValidationError instead of crashing on non-dict JSON input.
Backport of f6517a5335
from master
This commit is contained in:
parent
5641a80d49
commit
3eb31867bb
4 changed files with 22 additions and 1 deletions
|
@ -208,6 +208,13 @@ class TestFormField(PostgreSQLTestCase):
|
|||
self.assertEqual(cm.exception.messages[0], 'Could not load JSON data.')
|
||||
self.assertEqual(cm.exception.code, 'invalid_json')
|
||||
|
||||
def test_non_dict_json(self):
|
||||
field = forms.HStoreField()
|
||||
msg = 'Input must be a JSON dictionary.'
|
||||
with self.assertRaisesMessage(exceptions.ValidationError, msg) as cm:
|
||||
field.clean('["a", "b", 1]')
|
||||
self.assertEqual(cm.exception.code, 'invalid_format')
|
||||
|
||||
def test_not_string_values(self):
|
||||
field = forms.HStoreField()
|
||||
value = field.clean('{"a": 1}')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue