mirror of
https://github.com/django/django.git
synced 2025-10-28 16:16:12 +00:00
Fixed #29695 -- Added system checks for admin's app dependencies and TEMPLATES setting.
This commit is contained in:
@@ -43,6 +43,8 @@ class MyAdmin(admin.ModelAdmin):
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'admin_checks',
|
||||
],
|
||||
)
|
||||
@@ -58,20 +60,42 @@ class SystemChecksTestCase(SimpleTestCase):
|
||||
admin.site.unregister(Song)
|
||||
|
||||
@override_settings(INSTALLED_APPS=['django.contrib.admin'])
|
||||
def test_contenttypes_dependency(self):
|
||||
def test_apps_dependencies(self):
|
||||
errors = admin.checks.check_dependencies()
|
||||
expected = [
|
||||
checks.Error(
|
||||
"'django.contrib.contenttypes' must be in "
|
||||
"INSTALLED_APPS in order to use the admin application.",
|
||||
id="admin.E401",
|
||||
),
|
||||
checks.Error(
|
||||
"'django.contrib.auth' must be in INSTALLED_APPS in order "
|
||||
"to use the admin application.",
|
||||
id='admin.E405',
|
||||
),
|
||||
checks.Error(
|
||||
"'django.contrib.messages' must be in INSTALLED_APPS in order "
|
||||
"to use the admin application.",
|
||||
id='admin.E406',
|
||||
),
|
||||
checks.Error(
|
||||
"'django.contrib.sessions' must be in INSTALLED_APPS in order "
|
||||
"to use the admin application.",
|
||||
id='admin.E407',
|
||||
)
|
||||
]
|
||||
self.assertEqual(errors, expected)
|
||||
|
||||
@override_settings(TEMPLATES=[])
|
||||
def test_no_template_engines(self):
|
||||
self.assertEqual(admin.checks.check_dependencies(), [])
|
||||
self.assertEqual(admin.checks.check_dependencies(), [
|
||||
checks.Error(
|
||||
"A 'django.template.backends.django.DjangoTemplates' "
|
||||
"instance must be configured in TEMPLATES in order to use "
|
||||
"the admin application.",
|
||||
id='admin.E403',
|
||||
)
|
||||
])
|
||||
|
||||
@override_settings(
|
||||
TEMPLATES=[{
|
||||
@@ -83,13 +107,64 @@ class SystemChecksTestCase(SimpleTestCase):
|
||||
},
|
||||
}],
|
||||
)
|
||||
def test_auth_contextprocessor_dependency(self):
|
||||
def test_context_processor_dependencies(self):
|
||||
expected = [
|
||||
checks.Error(
|
||||
"'django.contrib.auth.context_processors.auth' must be "
|
||||
"enabled in DjangoTemplates (TEMPLATES) if using the default "
|
||||
"auth backend in order to use the admin application.",
|
||||
id='admin.E402',
|
||||
),
|
||||
checks.Error(
|
||||
"'django.contrib.messages.context_processors.messages' must "
|
||||
"be enabled in DjangoTemplates (TEMPLATES) in order to use "
|
||||
"the admin application.",
|
||||
id='admin.E404',
|
||||
)
|
||||
]
|
||||
self.assertEqual(admin.checks.check_dependencies(), expected)
|
||||
# The first error doesn't happen if
|
||||
# 'django.contrib.auth.backends.ModelBackend' isn't in
|
||||
# AUTHENTICATION_BACKENDS.
|
||||
with self.settings(AUTHENTICATION_BACKENDS=[]):
|
||||
self.assertEqual(admin.checks.check_dependencies(), expected[1:])
|
||||
|
||||
@override_settings(
|
||||
TEMPLATES=[
|
||||
{
|
||||
'BACKEND': 'django.template.backends.jinja2.Jinja2',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
},
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
)
|
||||
def test_several_templates_backends(self):
|
||||
self.assertEqual(admin.checks.check_dependencies(), [])
|
||||
|
||||
@override_settings(MIDDLEWARE=[])
|
||||
def test_middleware_dependencies(self):
|
||||
errors = admin.checks.check_dependencies()
|
||||
expected = [
|
||||
checks.Error(
|
||||
"'django.contrib.auth.context_processors.auth' must be in "
|
||||
"TEMPLATES in order to use the admin application.",
|
||||
id="admin.E402",
|
||||
"'django.contrib.auth.middleware.AuthenticationMiddleware' "
|
||||
"must be in MIDDLEWARE in order to use the admin application.",
|
||||
id='admin.E408',
|
||||
),
|
||||
checks.Error(
|
||||
"'django.contrib.messages.middleware.MessageMiddleware' "
|
||||
"must be in MIDDLEWARE in order to use the admin application.",
|
||||
id='admin.E409',
|
||||
)
|
||||
]
|
||||
self.assertEqual(errors, expected)
|
||||
|
||||
Reference in New Issue
Block a user