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

        with self.assertRaises(ValidationError):
            field.clean('{"foo"}')
Example #4
0
 def test_required_form_field_empty(self):
     field = JSONFormField(required=True)
     with self.assertRaises(ValidationError):
         field.clean('')
Example #5
0
 def test_required_form_field_object(self):
     field = JSONFormField(required=True)
     self.assertEqual({}, field.clean('{}'))
Example #6
0
 def test_required_form_field_array(self):
     field = JSONFormField(required=True)
     self.assertEqual([], field.clean('[]'))
Example #7
0
 def test_form_field_clean_empty_array(self):
     field = JSONFormField(required=False)
     self.assertEqual([], field.clean('[]'))
Example #8
0
 def test_form_field_clean_empty_object(self):
     field = JSONFormField(required=False)
     self.assertEqual({}, field.clean('{}'))
Example #9
0
 def test_invalid_json(self):
     field = JSONFormField(required=True)
     
     with self.assertRaises(ValidationError):
         field.clean('{"foo"}')
Example #10
0
 def test_required_form_field_empty(self):
     field = JSONFormField(required=True)
     with self.assertRaises(ValidationError):
         field.clean('')
Example #11
0
 def test_required_form_field_object(self):
     field = JSONFormField(required=True)
     self.assertEqual({}, field.clean('{}'))
Example #12
0
 def test_required_form_field_array(self):
     field = JSONFormField(required=True)
     self.assertEqual([], field.clean('[]'))
Example #13
0
 def test_form_field_clean_empty_array(self):
     field = JSONFormField(required=False)
     self.assertEqual([],field.clean('[]'))
Example #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}'))