当前位置: 首页>>代码示例>>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;未经允许,请勿转载。