Esempio n. 1
0
 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('[]'))
Esempio n. 2
0
 def test_form_field_clean_empty_object(self):
     field = JSONFormField(required=False)
     self.assertEqual({}, field.clean('{}'))
Esempio n. 3
0
    def test_invalid_json(self):
        field = JSONFormField(required=True)

        with self.assertRaises(ValidationError):
            field.clean('{"foo"}')
Esempio n. 4
0
 def test_required_form_field_empty(self):
     field = JSONFormField(required=True)
     with self.assertRaises(ValidationError):
         field.clean('')
Esempio n. 5
0
 def test_required_form_field_object(self):
     field = JSONFormField(required=True)
     self.assertEqual({}, field.clean('{}'))
Esempio n. 6
0
 def test_required_form_field_array(self):
     field = JSONFormField(required=True)
     self.assertEqual([], field.clean('[]'))
Esempio n. 7
0
 def test_form_field_clean_empty_array(self):
     field = JSONFormField(required=False)
     self.assertEqual([], field.clean('[]'))
Esempio n. 8
0
 def test_form_field_clean_empty_object(self):
     field = JSONFormField(required=False)
     self.assertEqual({}, field.clean('{}'))
Esempio n. 9
0
 def test_invalid_json(self):
     field = JSONFormField(required=True)
     
     with self.assertRaises(ValidationError):
         field.clean('{"foo"}')
Esempio n. 10
0
 def test_required_form_field_empty(self):
     field = JSONFormField(required=True)
     with self.assertRaises(ValidationError):
         field.clean('')
Esempio n. 11
0
 def test_required_form_field_object(self):
     field = JSONFormField(required=True)
     self.assertEqual({}, field.clean('{}'))
Esempio n. 12
0
 def test_required_form_field_array(self):
     field = JSONFormField(required=True)
     self.assertEqual([], field.clean('[]'))
Esempio n. 13
0
 def test_form_field_clean_empty_array(self):
     field = JSONFormField(required=False)
     self.assertEqual([],field.clean('[]'))
Esempio n. 14
0
 def test_form_field_clean_object(self):
     field = JSONFormField(required=False)
     self.assertEqual({"foo": "bar", "baz": 2}, field.clean('{"foo":"bar","baz":2}'))