Example #1
0
    def test_formfield(self):
        field = JSONField("test")
        field.set_attributes_from_name("json")
        formfield = field.formfield()

        self.assertEqual(type(formfield), forms.CharField)
        self.assertEqual(type(formfield.widget), forms.Textarea)
Example #2
0
 def test_formfield_clean_none(self):
     field = JSONField("test")
     formfield = field.formfield()
     self.assertRaisesMessage(forms.ValidationError,
                              force_text(
                                  formfield.error_messages['required']),
                              formfield.clean,
                              value=None)
Example #3
0
 def test_formfield_clean_blank(self):
     field = JSONField("test")
     formfield = field.formfield()
     self.assertRaisesMessage(
         forms.ValidationError,
         force_text(formfield.error_messages["required"]),
         formfield.clean,
         value="",
     )
Example #4
0
 def test_formfield_null_and_blank_clean_blank(self):
     field = JSONField("test", null=True, blank=True)
     formfield = field.formfield()
     self.assertEqual(formfield.clean(value=''), '')
Example #5
0
 def test_formfield_blank_clean_blank(self):
     field = JSONField("test", null=False, blank=True)
     formfield = field.formfield()
     self.assertEqual(formfield.clean(value=""), "")