本文整理汇总了Python中django.core.checks.Tags.database方法的典型用法代码示例。如果您正苦于以下问题:Python Tags.database方法的具体用法?Python Tags.database怎么用?Python Tags.database使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.checks.Tags
的用法示例。
在下文中一共展示了Tags.database方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_mysql_strict_mode
# 需要导入模块: from django.core.checks import Tags [as 别名]
# 或者: from django.core.checks.Tags import database [as 别名]
def test_mysql_strict_mode(self):
good_sql_modes = [
'STRICT_TRANS_TABLES,STRICT_ALL_TABLES',
'STRICT_TRANS_TABLES',
'STRICT_ALL_TABLES',
]
for response in good_sql_modes:
with mock.patch(
'django.db.backends.utils.CursorWrapper.fetchone', create=True,
return_value=(response,)
):
self.assertEqual(self.func(None), [])
bad_sql_modes = ['', 'WHATEVER']
for response in bad_sql_modes:
with mock.patch(
'django.db.backends.utils.CursorWrapper.fetchone', create=True,
return_value=(response,)
):
# One warning for each database alias
result = self.func(None)
self.assertEqual(len(result), 2)
self.assertEqual([r.id for r in result], ['mysql.W002', 'mysql.W002'])
示例2: ready
# 需要导入模块: from django.core.checks import Tags [as 别名]
# 或者: from django.core.checks.Tags import database [as 别名]
def ready(self):
@register(Tags.compatibility, Tags.database)
def check_if_postgresql(app_configs, **kwargs):
if get_postgresql_connections():
return []
return [Error('You must use a PostgreSQL database '
'to use PostgreSQL search.',
id='wagtail.contrib.postgres_search.E001')]
set_weights()
from .models import IndexEntry
IndexEntry.add_generic_relations()
示例3: _run_checks
# 需要导入模块: from django.core.checks import Tags [as 别名]
# 或者: from django.core.checks.Tags import database [as 别名]
def _run_checks(self, **kwargs):
issues = run_checks(tags=[Tags.database])
issues.extend(super()._run_checks(**kwargs))
return issues
示例4: get_dynamic_tenant
# 需要导入模块: from django.core.checks import Tags [as 别名]
# 或者: from django.core.checks.Tags import database [as 别名]
def get_dynamic_tenant(self, **options):
tenant = None
domain = None
if self._ask(
"You are cloning a schema for a dynamic tenant. Would you like to create a database entry for it?"
):
tenant = self._get_constructed_instance(get_tenant_model(), {"schema_name": options["destination"]})
domain = self._get_constructed_instance(get_domain_model(), {"is_primary": True})
if options["verbosity"] >= 1:
self.stdout.write(self.style.WARNING("Looks good! Let's get to it!"))
return tenant, domain
示例5: func
# 需要导入模块: from django.core.checks import Tags [as 别名]
# 或者: from django.core.checks.Tags import database [as 别名]
def func(self):
from django.core.checks.database import check_database_backends
return check_database_backends
示例6: test_database_checks_not_run_by_default
# 需要导入模块: from django.core.checks import Tags [as 别名]
# 或者: from django.core.checks.Tags import database [as 别名]
def test_database_checks_not_run_by_default(self):
"""
`database` checks are only run when their tag is specified.
"""
def f1(**kwargs):
return [5]
registry = CheckRegistry()
registry.register(Tags.database)(f1)
errors = registry.run_checks()
self.assertEqual(errors, [])
errors2 = registry.run_checks(tags=[Tags.database])
self.assertEqual(errors2, [5])
示例7: test_database_checks_called
# 需要导入模块: from django.core.checks import Tags [as 别名]
# 或者: from django.core.checks.Tags import database [as 别名]
def test_database_checks_called(self):
with mock.patch('django.db.backends.base.validation.BaseDatabaseValidation.check') as mocked_check:
run_checks(tags=[Tags.database])
self.assertTrue(mocked_check.called)
示例8: check_databases_compatibility
# 需要导入模块: from django.core.checks import Tags [as 别名]
# 或者: from django.core.checks.Tags import database [as 别名]
def check_databases_compatibility(app_configs, **kwargs):
errors = []
databases = settings.DATABASES
original_enabled_databases = getattr(settings, 'CACHALOT_DATABASES',
SUPPORTED_ONLY)
enabled_databases = cachalot_settings.CACHALOT_DATABASES
if original_enabled_databases == SUPPORTED_ONLY:
if not cachalot_settings.CACHALOT_DATABASES:
errors.append(Warning(
'None of the configured databases are supported '
'by django-cachalot.',
hint='Use a supported database, or remove django-cachalot, or '
'put at least one database alias in `CACHALOT_DATABASES` '
'to force django-cachalot to use it.',
id='cachalot.W002'
))
elif enabled_databases.__class__ in ITERABLES:
for db_alias in enabled_databases:
if db_alias in databases:
engine = databases[db_alias]['ENGINE']
if engine not in SUPPORTED_DATABASE_ENGINES:
errors.append(Warning(
'Database engine %r is not supported '
'by django-cachalot.' % engine,
hint='Switch to a supported database engine.',
id='cachalot.W003'
))
else:
errors.append(Error(
'Database alias %r from `CACHALOT_DATABASES` '
'is not defined in `DATABASES`.' % db_alias,
hint='Change `CACHALOT_DATABASES` to be compliant with'
'`CACHALOT_DATABASES`',
id='cachalot.E001',
))
if not enabled_databases:
errors.append(Warning(
'Django-cachalot is useless because no database '
'is configured in `CACHALOT_DATABASES`.',
hint='Reconfigure django-cachalot or remove it.',
id='cachalot.W004'
))
else:
errors.append(Error(
"`CACHALOT_DATABASES` must be either %r or a list, tuple, "
"frozenset or set of database aliases." % SUPPORTED_ONLY,
hint='Remove `CACHALOT_DATABASES` or change it.',
id='cachalot.E002',
))
return errors