Exemplo n.º 1
0
    def test_one_to_one_cascade(self, mock_get_activatable_models):
        """
        The default cascade behavior is invalid for activatable models.
        """
        class CascadableModel(BaseActivatableModel):
            class Meta:
                abstract = True

            is_active = models.BooleanField(default=False)
            ctype = models.OneToOneField(ContentType, on_delete=models.CASCADE)

        mock_get_activatable_models.return_value = [CascadableModel]
        with self.assertRaises(ValidationError):
            validate_activatable_models()
Exemplo n.º 2
0
    def test_one_to_one_cascade(self, mock_get_activatable_models):
        """
        The default cascade behavior is invalid for activatable models.
        """
        class CascadableModel(BaseActivatableModel):
            class Meta:
                abstract = True

            is_active = models.BooleanField(default=False)
            ctype = models.OneToOneField(ContentType)

        mock_get_activatable_models.return_value = [CascadableModel]
        with self.assertRaises(ValidationError):
            validate_activatable_models()
Exemplo n.º 3
0
    def test_foreign_key_cascade(self, mock_get_activatable_models):
        """
        The default cascade behavior is invalid for activatable models.
        """
        class CascadableModel(BaseActivatableModel):
            class Meta:
                abstract = True

            is_active = models.BooleanField(default=False)
            ctype = models.ForeignKey(ContentType, on_delete=models.CASCADE)

        mock_get_activatable_models.return_value = [CascadableModel]
        with self.assertRaises(ValidationError):
            validate_activatable_models()
Exemplo n.º 4
0
    def test_foreign_key_cascade(self, mock_get_activatable_models):
        """
        The default cascade behavior is invalid for activatable models.
        """
        class CascadableModel(BaseActivatableModel):
            class Meta:
                abstract = True

            is_active = models.BooleanField(default=False)
            ctype = models.ForeignKey(ContentType)

        mock_get_activatable_models.return_value = [CascadableModel]
        with self.assertRaises(ValidationError):
            validate_activatable_models()
Exemplo n.º 5
0
    def test_one_to_one_protect(self, mock_get_activatable_models):
        """
        PROTECT is a valid option for foreign keys in activatable models.
        """
        # Make this an object and not an actual django model. This prevents it from always
        # being included when syncing the db. This is true for all other test models in this file.
        class CascadableModel(BaseActivatableModel):
            class Meta:
                abstract = True

            is_active = models.BooleanField(default=False)
            ctype = models.OneToOneField(ContentType, null=True, on_delete=models.PROTECT)

        mock_get_activatable_models.return_value = [CascadableModel]
        validate_activatable_models()
        self.assertEquals(mock_get_activatable_models.call_count, 1)
Exemplo n.º 6
0
    def test_activatable_field_is_not_boolean(self, mock_get_activatable_models):
        """
        SET_NULL is a valid option for foreign keys in activatable models.
        """
        # Make this an object and not an actual django model. This prevents it from always
        # being included when syncing the db. This is true for all other test models in this file.
        class NonBooleanModel(BaseActivatableModel):
            class Meta:
                abstract = True

            is_active = models.CharField()
            ctype = models.ForeignKey(ContentType, null=True, on_delete=models.SET_NULL)

        mock_get_activatable_models.return_value = [NonBooleanModel]
        with self.assertRaises(ValidationError):
            validate_activatable_models()
Exemplo n.º 7
0
    def test_one_to_one_protect(self, mock_get_activatable_models):
        """
        PROTECT is a valid option for foreign keys in activatable models.
        """

        # Make this an object and not an actual django model. This prevents it from always
        # being included when syncing the db. This is true for all other test models in this file.
        class CascadableModel(BaseActivatableModel):
            class Meta:
                abstract = True

            is_active = models.BooleanField(default=False)
            ctype = models.OneToOneField(ContentType,
                                         null=True,
                                         on_delete=models.PROTECT)

        mock_get_activatable_models.return_value = [CascadableModel]
        validate_activatable_models()
        self.assertEquals(mock_get_activatable_models.call_count, 1)
Exemplo n.º 8
0
    def test_activatable_field_is_not_boolean(self,
                                              mock_get_activatable_models):
        """
        SET_NULL is a valid option for foreign keys in activatable models.
        """

        # Make this an object and not an actual django model. This prevents it from always
        # being included when syncing the db. This is true for all other test models in this file.
        class NonBooleanModel(BaseActivatableModel):
            class Meta:
                abstract = True

            is_active = models.CharField()
            ctype = models.ForeignKey(ContentType,
                                      null=True,
                                      on_delete=models.SET_NULL)

        mock_get_activatable_models.return_value = [NonBooleanModel]
        with self.assertRaises(ValidationError):
            validate_activatable_models()
Exemplo n.º 9
0
 def test_all_valid_models(self):
     """
     All models should validate fine.
     """
     validate_activatable_models()
Exemplo n.º 10
0
 def test_all_valid_models(self):
     """
     All models should validate fine.
     """
     validate_activatable_models()
Exemplo n.º 11
0
 def ready(self):
     from activatable_model.validation import validate_activatable_models
     validate_activatable_models()