當前位置: 首頁>>代碼示例>>Python>>正文


Python checks.run_checks方法代碼示例

本文整理匯總了Python中django.core.checks.run_checks方法的典型用法代碼示例。如果您正苦於以下問題:Python checks.run_checks方法的具體用法?Python checks.run_checks怎麽用?Python checks.run_checks使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.core.checks的用法示例。


在下文中一共展示了checks.run_checks方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: runtests

# 需要導入模塊: from django.core import checks [as 別名]
# 或者: from django.core.checks import run_checks [as 別名]
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) 
開發者ID:pinax,項目名稱:pinax-starter-app,代碼行數:26,代碼來源:runtests.py

示例2: test_username_not_in_required_fields

# 需要導入模塊: from django.core import checks [as 別名]
# 或者: from django.core.checks import run_checks [as 別名]
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',
            ),
        ]) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:20,代碼來源:test_checks.py

示例3: test_username_non_unique

# 需要導入模塊: from django.core import checks [as 別名]
# 或者: from django.core.checks import run_checks [as 別名]
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',
                ),
            ]) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:27,代碼來源:test_checks.py

示例4: test_custom_permission_name_max_length

# 需要導入模塊: from django.core import checks [as 別名]
# 或者: from django.core.checks import run_checks [as 別名]
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',
            ),
        ]) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:19,代碼來源:test_checks.py

示例5: test_collision_in_same_app

# 需要導入模塊: from django.core import checks [as 別名]
# 或者: from django.core.checks import run_checks [as 別名]
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',
            )
        ]) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:19,代碼來源:test_model_checks.py

示例6: test_collision_across_apps

# 需要導入模塊: from django.core import checks [as 別名]
# 或者: from django.core.checks import run_checks [as 別名]
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',
            )
        ]) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:21,代碼來源:test_model_checks.py

示例7: test_required_fields_is_list

# 需要導入模塊: from django.core import checks [as 別名]
# 或者: from django.core.checks import run_checks [as 別名]
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',
            ),
        ]) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:19,代碼來源:test_checks.py

示例8: test_clashing_custom_permissions

# 需要導入模塊: from django.core import checks [as 別名]
# 或者: from django.core.checks import run_checks [as 別名]
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',
            ),
        ]) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:19,代碼來源:test_checks.py

示例9: test_cache_compatibility

# 需要導入模塊: from django.core import checks [as 別名]
# 或者: from django.core.checks import run_checks [as 別名]
def test_cache_compatibility(self):
        compatible_cache = {
            'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
        }
        incompatible_cache = {
            'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
            'LOCATION': 'cache_table'
        }

        with self.settings(CACHES={'default': compatible_cache,
                                   'secondary': incompatible_cache}):
            errors = run_checks(tags=[Tags.compatibility])
            self.assertListEqual(errors, [])

        warning001 = Warning(
            'Cache backend %r is not supported by django-cachalot.'
            % 'django.core.cache.backends.db.DatabaseCache',
            hint='Switch to a supported cache backend '
                 'like Redis or Memcached.',
            id='cachalot.W001')
        with self.settings(CACHES={'default': incompatible_cache}):
            errors = run_checks(tags=[Tags.compatibility])
            self.assertListEqual(errors, [warning001])
        with self.settings(CACHES={'default': compatible_cache,
                                   'secondary': incompatible_cache},
                           CACHALOT_CACHE='secondary'):
            errors = run_checks(tags=[Tags.compatibility])
            self.assertListEqual(errors, [warning001]) 
開發者ID:noripyt,項目名稱:django-cachalot,代碼行數:30,代碼來源:settings.py

示例10: test_models_check

# 需要導入模塊: from django.core import checks [as 別名]
# 或者: from django.core.checks import run_checks [as 別名]
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, []) 
開發者ID:onysos,項目名稱:django-composite-foreignkey,代碼行數:11,代碼來源:tests.py

示例11: test_field_check_errors

# 需要導入模塊: from django.core import checks [as 別名]
# 或者: from django.core.checks import run_checks [as 別名]
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',
            ]) 
開發者ID:onysos,項目名稱:django-composite-foreignkey,代碼行數:15,代碼來源:tests.py

示例12: test_check_invalid_base_form_class

# 需要導入模塊: from django.core import checks [as 別名]
# 或者: from django.core.checks import run_checks [as 別名]
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]) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:29,代碼來源:test_edit_handlers.py

示例13: setUp

# 需要導入模塊: from django.core import checks [as 別名]
# 或者: from django.core.checks import run_checks [as 別名]
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 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:13,代碼來源:test_edit_handlers.py

示例14: setUp

# 需要導入模塊: from django.core import checks [as 別名]
# 或者: from django.core.checks import run_checks [as 別名]
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 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:13,代碼來源:tests.py

示例15: _run_checks

# 需要導入模塊: from django.core import checks [as 別名]
# 或者: from django.core.checks import run_checks [as 別名]
def _run_checks(self, **kwargs):
        issues = run_checks(tags=[Tags.database])
        issues.extend(super()._run_checks(**kwargs))
        return issues 
開發者ID:lorinkoz,項目名稱:django-pgschemas,代碼行數:6,代碼來源:createrefschema.py


注:本文中的django.core.checks.run_checks方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。