Example #1
0
    def test_generic_foreign_key_checks_are_performed(self):
        class Model(models.Model):
            content_object = GenericForeignKey()

        with mock.patch.object(GenericForeignKey, 'check') as check:
            checks.run_checks(app_configs=self.apps.get_app_configs())
        check.assert_called_once_with()
Example #2
0
    def test_model_check_method_not_shadowed(self, apps):
        class ModelWithAttributeCalledCheck(models.Model):
            check = 42

        class ModelWithFieldCalledCheck(models.Model):
            check = models.IntegerField()

        class ModelWithRelatedManagerCalledCheck(models.Model):
            pass

        class ModelWithDescriptorCalledCheck(models.Model):
            check = models.ForeignKey(ModelWithRelatedManagerCalledCheck,
                                      models.CASCADE)
            article = models.ForeignKey(
                ModelWithRelatedManagerCalledCheck,
                models.CASCADE,
                related_name='check',
            )

        errors = checks.run_checks(app_configs=apps.get_app_configs())
        expected = [
            Error(
                "The 'ModelWithAttributeCalledCheck.check()' class method is "
                "currently overridden by 42.",
                obj=ModelWithAttributeCalledCheck,
                id='models.E020'),
            Error(
                "The 'ModelWithRelatedManagerCalledCheck.check()' class method is "
                "currently overridden by %r." %
                ModelWithRelatedManagerCalledCheck.check,
                obj=ModelWithRelatedManagerCalledCheck,
                id='models.E020'),
            Error(
                "The 'ModelWithDescriptorCalledCheck.check()' class method is "
                "currently overridden by %r." %
                ModelWithDescriptorCalledCheck.check,
                obj=ModelWithDescriptorCalledCheck,
                id='models.E020'),
        ]
        self.assertEqual(errors, expected)
Example #3
0
 def test_database_checks_called(self):
     with mock.patch('djmodels.db.backends.base.validation.BaseDatabaseValidation.check') as mocked_check:
         run_checks(tags=[Tags.database])
         self.assertTrue(mocked_check.called)
Example #4
0
 def _run_checks(self, **kwargs):
     return checks.run_checks(**kwargs)
Example #5
0
 def _run_checks(self, **kwargs):
     issues = run_checks(tags=[Tags.database])
     issues.extend(super()._run_checks(**kwargs))
     return issues