2015-02-05 10:53:04 +00:00
|
|
|
from django.core.exceptions import ImproperlyConfigured
|
|
|
|
from django.template import engines
|
|
|
|
from django.test import SimpleTestCase, override_settings
|
|
|
|
|
|
|
|
|
2016-12-15 14:32:46 +00:00
|
|
|
class TemplateUtilsTests(SimpleTestCase):
|
2015-02-05 10:53:04 +00:00
|
|
|
|
2016-12-15 14:32:46 +00:00
|
|
|
@override_settings(TEMPLATES=[{'BACKEND': 'raise.import.error'}])
|
2015-02-05 10:53:04 +00:00
|
|
|
def test_backend_import_error(self):
|
|
|
|
"""
|
2016-12-15 14:32:46 +00:00
|
|
|
Failing to import a backend keeps raising the original import error
|
|
|
|
(#24265).
|
2015-02-05 10:53:04 +00:00
|
|
|
"""
|
2017-01-20 02:10:33 +00:00
|
|
|
with self.assertRaisesMessage(ImportError, "No module named 'raise"):
|
2015-02-05 10:53:04 +00:00
|
|
|
engines.all()
|
2017-01-20 02:10:33 +00:00
|
|
|
with self.assertRaisesMessage(ImportError, "No module named 'raise"):
|
2015-02-05 10:53:04 +00:00
|
|
|
engines.all()
|
|
|
|
|
|
|
|
@override_settings(TEMPLATES=[{
|
|
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
|
|
# Incorrect: APP_DIRS and loaders are mutually incompatible.
|
|
|
|
'APP_DIRS': True,
|
|
|
|
'OPTIONS': {'loaders': []},
|
|
|
|
}])
|
|
|
|
def test_backend_improperly_configured(self):
|
|
|
|
"""
|
2016-12-15 14:32:46 +00:00
|
|
|
Failing to initialize a backend keeps raising the original exception
|
|
|
|
(#24265).
|
2015-02-05 10:53:04 +00:00
|
|
|
"""
|
2016-12-15 14:32:46 +00:00
|
|
|
msg = 'app_dirs must not be set when loaders is defined.'
|
|
|
|
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
2015-02-05 10:53:04 +00:00
|
|
|
engines.all()
|
2016-12-15 14:32:46 +00:00
|
|
|
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
2015-02-05 10:53:04 +00:00
|
|
|
engines.all()
|
2015-05-03 19:42:56 +00:00
|
|
|
|
|
|
|
@override_settings(TEMPLATES=[{
|
|
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
|
|
}, {
|
|
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
|
|
}])
|
|
|
|
def test_backend_names_must_be_unique(self):
|
2016-12-15 14:32:46 +00:00
|
|
|
msg = (
|
|
|
|
"Template engine aliases aren't unique, duplicates: django. Set "
|
|
|
|
"a unique NAME for each engine in settings.TEMPLATES."
|
|
|
|
)
|
|
|
|
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
2015-05-03 19:42:56 +00:00
|
|
|
engines.all()
|