Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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="",
     )
Ejemplo n.º 4
0
 def test_db_prep_save(self):
     field = JSONField("test")
     field.set_attributes_from_name("json")
     self.assertEqual(None, field.get_db_prep_save(None, connection=None))
     self.assertEqual(
         '{"spam": "eggs"}',
         field.get_db_prep_save({"spam": "eggs"}, connection=None))
Ejemplo n.º 5
0
class DocIntegration(Model):
    """
    Document based integrations can be found in Sentry, but are installed via code change.
    """

    __include_in_export__ = False

    name = models.CharField(max_length=64)
    slug = models.CharField(max_length=64, unique=True)
    author = models.CharField(max_length=255)
    description = models.TextField()
    url = models.URLField()
    popularity = models.PositiveSmallIntegerField(null=True, default=1)
    # Quickly hide/show integration, used for logo uploads.
    is_draft = models.BooleanField(default=True)

    # Allow future extensions by adding more metadata.
    # To start, only { resources: [{title, link}] }.
    metadata = JSONField(null=True)

    class Meta:
        app_label = "sentry"
        db_table = "sentry_docintegration"
Ejemplo n.º 6
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=''), '')
Ejemplo n.º 7
0
class CallableDefaultModel(models.Model):
    json = JSONField(default=lambda: {'x': 2})

    class Meta:
        app_label = 'sentry'
Ejemplo n.º 8
0
class BlankJSONFieldTestModel(models.Model):
    null_json = JSONField(null=True)
    blank_json = JSONField(blank=True)

    class Meta:
        app_label = 'sentry'
Ejemplo n.º 9
0
 def test_invalid_json_default(self):
     with self.assertRaises(ValueError):
         JSONField('test', default='{"foo"}')
Ejemplo n.º 10
0
class JSONFieldWithDefaultTestModel(models.Model):
    json = JSONField(default={"sukasuka": "YAAAAAZ"})

    class Meta:
        app_label = 'sentry'
Ejemplo n.º 11
0
class JSONFieldTestModel(models.Model):
    json = JSONField("test", null=True, blank=True)

    class Meta:
        app_label = 'sentry'
Ejemplo n.º 12
0
class CallableDefaultModel(models.Model):
    json = JSONField(default=default)

    class Meta:
        app_label = "sentry"
Ejemplo n.º 13
0
 def test_formfield_blank_clean_blank(self):
     field = JSONField("test", null=False, blank=True)
     formfield = field.formfield()
     self.assertEqual(formfield.clean(value=""), "")