def test_form_field_clean(self): field = JSONFormField(required=False) self.assertEquals({}, field.clean('{}')) self.assertEquals( {'foo':'bar', 'baz':2}, field.clean('{"foo":"bar","baz":2}') ) self.assertEquals([],field.clean('[]'))
def test_form_field_clean_empty_object(self): field = JSONFormField(required=False) self.assertEqual({}, field.clean('{}'))
def test_invalid_json(self): field = JSONFormField(required=True) with self.assertRaises(ValidationError): field.clean('{"foo"}')
def test_required_form_field_empty(self): field = JSONFormField(required=True) with self.assertRaises(ValidationError): field.clean('')
def test_required_form_field_object(self): field = JSONFormField(required=True) self.assertEqual({}, field.clean('{}'))
def test_required_form_field_array(self): field = JSONFormField(required=True) self.assertEqual([], field.clean('[]'))
def test_form_field_clean_empty_array(self): field = JSONFormField(required=False) self.assertEqual([], field.clean('[]'))
def test_form_field_clean_empty_array(self): field = JSONFormField(required=False) self.assertEqual([],field.clean('[]'))
def test_form_field_clean_object(self): field = JSONFormField(required=False) self.assertEqual({"foo": "bar", "baz": 2}, field.clean('{"foo":"bar","baz":2}'))