Python django.core.checks.run_checks() Examples
The following are 30
code examples of django.core.checks.run_checks().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.core.checks
, or try the search function
.
Example #1
Source File: test_checks.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
def test_required_fields_is_list(self): """REQUIRED_FIELDS should be a list.""" class CustomUserNonListRequiredFields(AbstractBaseUser): username = models.CharField(max_length=30, unique=True) date_of_birth = models.DateField() USERNAME_FIELD = 'username' REQUIRED_FIELDS = 'date_of_birth' errors = checks.run_checks(app_configs=self.apps.get_app_configs()) self.assertEqual(errors, [ checks.Error( "'REQUIRED_FIELDS' must be a list or tuple.", obj=CustomUserNonListRequiredFields, id='auth.E001', ), ])
Example #2
Source File: test_checks.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
def test_custom_permission_name_max_length(self): custom_permission_name = 'some ridiculously long verbose name that is out of control' * 5 class Checked(models.Model): class Meta: permissions = [ ('my_custom_permission', custom_permission_name), ] errors = checks.run_checks(self.apps.get_app_configs()) self.assertEqual(errors, [ checks.Error( "The permission named '%s' of model 'auth_tests.Checked' is longer " "than 255 characters." % custom_permission_name, obj=Checked, id='auth.E008', ), ])
Example #3
Source File: test_checks.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
def test_username_non_unique(self): """ A non-unique USERNAME_FIELD raises an error only if the default authentication backend is used. Otherwise, a warning is raised. """ errors = checks.run_checks() self.assertEqual(errors, [ checks.Error( "'CustomUserNonUniqueUsername.username' must be " "unique because it is named as the 'USERNAME_FIELD'.", obj=CustomUserNonUniqueUsername, id='auth.E003', ), ]) with self.settings(AUTHENTICATION_BACKENDS=['my.custom.backend']): errors = checks.run_checks() self.assertEqual(errors, [ checks.Warning( "'CustomUserNonUniqueUsername.username' is named as " "the 'USERNAME_FIELD', but it is not unique.", hint='Ensure that your authentication backend(s) can handle non-unique usernames.', obj=CustomUserNonUniqueUsername, id='auth.W004', ), ])
Example #4
Source File: test_checks.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
def test_username_not_in_required_fields(self): """USERNAME_FIELD should not appear in REQUIRED_FIELDS.""" class CustomUserBadRequiredFields(AbstractBaseUser): username = models.CharField(max_length=30, unique=True) date_of_birth = models.DateField() USERNAME_FIELD = 'username' REQUIRED_FIELDS = ['username', 'date_of_birth'] errors = checks.run_checks(self.apps.get_app_configs()) self.assertEqual(errors, [ checks.Error( "The field named as the 'USERNAME_FIELD' for a custom user model " "must not be included in 'REQUIRED_FIELDS'.", obj=CustomUserBadRequiredFields, id='auth.E002', ), ])
Example #5
Source File: test_model_checks.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
def test_collision_in_same_app(self): class Model1(models.Model): class Meta: db_table = 'test_table' class Model2(models.Model): class Meta: db_table = 'test_table' self.assertEqual(checks.run_checks(app_configs=self.apps.get_app_configs()), [ Error( "db_table 'test_table' is used by multiple models: " "check_framework.Model1, check_framework.Model2.", obj='test_table', id='models.E028', ) ])
Example #6
Source File: test_model_checks.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
def test_collision_across_apps(self, apps): class Model1(models.Model): class Meta: app_label = 'basic' db_table = 'test_table' class Model2(models.Model): class Meta: app_label = 'check_framework' db_table = 'test_table' self.assertEqual(checks.run_checks(app_configs=apps.get_app_configs()), [ Error( "db_table 'test_table' is used by multiple models: " "basic.Model1, check_framework.Model2.", obj='test_table', id='models.E028', ) ])
Example #7
Source File: test_checks.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
def test_username_not_in_required_fields(self): """USERNAME_FIELD should not appear in REQUIRED_FIELDS.""" class CustomUserBadRequiredFields(AbstractBaseUser): username = models.CharField(max_length=30, unique=True) date_of_birth = models.DateField() USERNAME_FIELD = 'username' REQUIRED_FIELDS = ['username', 'date_of_birth'] errors = checks.run_checks(self.apps.get_app_configs()) self.assertEqual(errors, [ checks.Error( "The field named as the 'USERNAME_FIELD' for a custom user model " "must not be included in 'REQUIRED_FIELDS'.", obj=CustomUserBadRequiredFields, id='auth.E002', ), ])
Example #8
Source File: test_checks.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
def test_username_non_unique(self): """ A non-unique USERNAME_FIELD raises an error only if the default authentication backend is used. Otherwise, a warning is raised. """ errors = checks.run_checks() self.assertEqual(errors, [ checks.Error( "'CustomUserNonUniqueUsername.username' must be " "unique because it is named as the 'USERNAME_FIELD'.", obj=CustomUserNonUniqueUsername, id='auth.E003', ), ]) with self.settings(AUTHENTICATION_BACKENDS=['my.custom.backend']): errors = checks.run_checks() self.assertEqual(errors, [ checks.Warning( "'CustomUserNonUniqueUsername.username' is named as " "the 'USERNAME_FIELD', but it is not unique.", hint='Ensure that your authentication backend(s) can handle non-unique usernames.', obj=CustomUserNonUniqueUsername, id='auth.W004', ), ])
Example #9
Source File: createrefschema.py From django-pgschemas with MIT License | 6 votes |
def _run_checks(self, **kwargs): issues = run_checks(tags=[Tags.database]) issues.extend(super()._run_checks(**kwargs)) return issues
Example #10
Source File: runtests.py From pinax-starter-app with MIT License | 6 votes |
def runtests(*test_args): os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pinax.{{ app_name }}.tests.settings") django.setup() parent = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, parent) from django.core import checks try: from django.test.runner import DiscoverRunner runner_class = DiscoverRunner if not test_args: test_args = ["pinax.{{ app_name }}.tests"] except ImportError: from django.test.simple import DjangoTestSuiteRunner runner_class = DjangoTestSuiteRunner test_args = ["tests"] checks = checks.run_checks() if checks: sys.exit(checks) failures = runner_class(verbosity=1, interactive=True, failfast=False).run_tests(test_args) sys.exit(failures)
Example #11
Source File: test_checks.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
def test_clashing_custom_permissions(self): class Checked(models.Model): class Meta: permissions = [ ('my_custom_permission', 'Some permission'), ('other_one', 'Some other permission'), ('my_custom_permission', 'Some permission with duplicate permission code'), ] errors = checks.run_checks(self.apps.get_app_configs()) self.assertEqual(errors, [ checks.Error( "The permission codenamed 'my_custom_permission' is duplicated for " "model 'auth_tests.Checked'.", obj=Checked, id='auth.E006', ), ])
Example #12
Source File: test_checks.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
def test_custom_permission_name_max_length(self): custom_permission_name = 'some ridiculously long verbose name that is out of control' * 5 class Checked(models.Model): class Meta: permissions = [ ('my_custom_permission', custom_permission_name), ] errors = checks.run_checks(self.apps.get_app_configs()) self.assertEqual(errors, [ checks.Error( "The permission named '%s' of model 'auth_tests.Checked' is longer " "than 255 characters." % custom_permission_name, obj=Checked, id='auth.E008', ), ])
Example #13
Source File: test_checks.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_is_anonymous_authenticated_methods(self): """ <User Model>.is_anonymous/is_authenticated must not be methods. """ class BadUser(AbstractBaseUser): username = models.CharField(max_length=30, unique=True) USERNAME_FIELD = 'username' def is_anonymous(self): return True def is_authenticated(self): return True errors = checks.run_checks(app_configs=self.apps.get_app_configs()) self.assertEqual(errors, [ checks.Critical( '%s.is_anonymous must be an attribute or property rather than ' 'a method. Ignoring this is a security issue as anonymous ' 'users will be treated as authenticated!' % BadUser, obj=BadUser, id='auth.C009', ), checks.Critical( '%s.is_authenticated must be an attribute or property rather ' 'than a method. Ignoring this is a security issue as anonymous ' 'users will be treated as authenticated!' % BadUser, obj=BadUser, id='auth.C010', ), ])
Example #14
Source File: test_checks.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_non_clashing_custom_permissions(self): class Checked(models.Model): class Meta: permissions = [ ('my_custom_permission', 'Some permission'), ('other_one', 'Some other permission'), ] errors = checks.run_checks(self.apps.get_app_configs()) self.assertEqual(errors, [])
Example #15
Source File: test_model_checks.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_no_collision_for_unmanaged_models(self): class Unmanaged(models.Model): class Meta: db_table = 'test_table' managed = False class Managed(models.Model): class Meta: db_table = 'test_table' self.assertEqual(checks.run_checks(app_configs=self.apps.get_app_configs()), [])
Example #16
Source File: test_checks.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_clashing_default_permissions(self): class Checked(models.Model): class Meta: permissions = [ ('change_checked', 'Can edit permission (duplicate)') ] errors = checks.run_checks(self.apps.get_app_configs()) self.assertEqual(errors, [ checks.Error( "The permission codenamed 'change_checked' clashes with a builtin " "permission for model 'auth_tests.Checked'.", obj=Checked, id='auth.E005', ), ])
Example #17
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
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 #18
Source File: test_checks.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_verbose_name_max_length(self): class Checked(models.Model): class Meta: verbose_name = 'some ridiculously long verbose name that is out of control' * 5 errors = checks.run_checks(self.apps.get_app_configs()) self.assertEqual(errors, [ checks.Error( "The verbose_name of model 'auth_tests.Checked' must be at most 244 " "characters for its builtin permission names to be at most 255 characters.", obj=Checked, id='auth.E007', ), ])
Example #19
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_custom_adminsite(self): class CustomAdminSite(admin.AdminSite): pass custom_site = CustomAdminSite() custom_site.register(Song, MyAdmin) try: errors = checks.run_checks() expected = ['error!'] self.assertEqual(errors, expected) finally: custom_site.unregister(Song)
Example #20
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_checks_are_performed(self): admin.site.register(Song, MyAdmin) try: errors = checks.run_checks() expected = ['error!'] self.assertEqual(errors, expected) finally: admin.site.unregister(Song)
Example #21
Source File: test_checks.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_empty_default_permissions(self): class Checked(models.Model): class Meta: default_permissions = () self.assertEqual(checks.run_checks(self.apps.get_app_configs()), [])
Example #22
Source File: test_checks.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_empty_default_permissions(self): class Checked(models.Model): class Meta: default_permissions = () self.assertEqual(checks.run_checks(self.apps.get_app_configs()), [])
Example #23
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_checks_are_performed(self): admin.site.register(Song, MyAdmin) try: errors = checks.run_checks() expected = ['error!'] self.assertEqual(errors, expected) finally: admin.site.unregister(Song)
Example #24
Source File: tests.py From django-composite-foreignkey with GNU General Public License v3.0 | 5 votes |
def test_models_check(self): self.maxDiff = None app_configs = [apps.get_app_config("testapp")] all_issues = checks.run_checks( app_configs=app_configs, tags=None, include_deployment_checks=False, ) self.assertListEqual(all_issues, [])
Example #25
Source File: tests.py From django-composite-foreignkey with GNU General Public License v3.0 | 5 votes |
def test_field_check_errors(self): with self.settings(INSTALLED_APPS=settings.INSTALLED_APPS + ("broken_test_app",)): self.maxDiff = None app_configs = [apps.get_app_config("broken_test_app")] all_issues = checks.run_checks( app_configs=app_configs, tags=None, include_deployment_checks=False, ) self.assertListEqual([issue.id for issue in all_issues], [ 'compositefk.E001', 'compositefk.E002', 'compositefk.E003', 'compositefk.E003', 'compositefk.E004', 'compositefk.E006', 'compositefk.E005', ])
Example #26
Source File: test_edit_handlers.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_check_invalid_base_form_class(self): class BadFormClass: pass invalid_base_form = checks.Error( "ValidatedPage.base_form_class does not extend WagtailAdminPageForm", hint="Ensure that wagtail.admin.tests.test_edit_handlers.BadFormClass extends WagtailAdminPageForm", obj=ValidatedPage, id='wagtailadmin.E001') invalid_edit_handler = checks.Error( "ValidatedPage.get_edit_handler().get_form_class() does not extend WagtailAdminPageForm", hint="Ensure that the EditHandler for ValidatedPage creates a subclass of WagtailAdminPageForm", obj=ValidatedPage, id='wagtailadmin.E002') with mock.patch.object(ValidatedPage, 'base_form_class', new=BadFormClass): errors = checks.run_checks() # ignore CSS loading errors (to avoid spurious failures on CI servers that # don't build the CSS) errors = [e for e in errors if e.id != 'wagtailadmin.W001'] # Errors may appear out of order, so sort them by id errors.sort(key=lambda e: e.id) self.assertEqual(errors, [invalid_base_form, invalid_edit_handler])
Example #27
Source File: test_edit_handlers.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
def setUp(self): self.original_panels = EventPageSpeaker.panels delattr(EventPageSpeaker, 'panels') def get_checks_result(): # run checks only with the 'panels' tag checks_result = checks.run_checks(tags=['panels']) return [warning for warning in checks_result if warning.obj == EventPageSpeaker] self.warning_id = 'wagtailadmin.W002' self.get_checks_result = get_checks_result
Example #28
Source File: tests.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
def setUp(self): self.warning_id = 'wagtailadmin.W002' def get_checks_result(): # run checks only with the 'panels' tag checks_result = checks.run_checks(tags=['panels']) return [ warning for warning in checks_result if warning.id == self.warning_id] self.get_checks_result = get_checks_result
Example #29
Source File: test_simple_modeladmin.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
def setUp(self): self.warning_id = 'wagtailadmin.W002' def get_checks_result(): # run checks only with the 'panels' tag checks_result = checks.run_checks(tags=['panels']) return [ warning for warning in checks_result if warning.id == self.warning_id] self.get_checks_result = get_checks_result
Example #30
Source File: migrateschema.py From django-pgschemas with MIT License | 5 votes |
def _run_checks(self, **kwargs): issues = run_checks(tags=[Tags.database]) issues.extend(super()._run_checks(**kwargs)) return issues