Debian Codegraph @

tests/template_backends/test_utils.py

raw
1 from django.core.exceptions import ImproperlyConfigured
2 from django.template import engines
3 from django.test import SimpleTestCase, override_settings
4
5
6 class TemplateUtilsTests(SimpleTestCase):
7 @override_settings(TEMPLATES=[{"BACKEND": "raise.import.error"}])
8 def test_backend_import_error(self):
9 """
10 Failing to import a backend keeps raising the original import error
11 (#24265).
12 """
13 with self.assertRaisesMessage(ImportError, "No module named 'raise"):
14 engines.all()
15 with self.assertRaisesMessage(ImportError, "No module named 'raise"):
16 engines.all()
17
18 @override_settings(
19 TEMPLATES=[
20 {
21 "BACKEND": "django.template.backends.django.DjangoTemplates",
22 # Incorrect: APP_DIRS and loaders are mutually incompatible.
23 "APP_DIRS": True,
24 "OPTIONS": {"loaders": []},
25 }
26 ]
27 )
28 def test_backend_improperly_configured(self):
29 """
30 Failing to initialize a backend keeps raising the original exception
31 (#24265).
32 """
33 msg = "app_dirs must not be set when loaders is defined."
34 with self.assertRaisesMessage(ImproperlyConfigured, msg):
35 engines.all()
36 with self.assertRaisesMessage(ImproperlyConfigured, msg):
37 engines.all()
38
39 @override_settings(
40 TEMPLATES=[
41 {
42 "BACKEND": "django.template.backends.django.DjangoTemplates",
43 },
44 {
45 "BACKEND": "django.template.backends.django.DjangoTemplates",
46 },
47 ]
48 )
49 def test_backend_names_must_be_unique(self):
50 msg = (
51 "Template engine aliases aren't unique, duplicates: django. Set "
52 "a unique NAME for each engine in settings.TEMPLATES."
53 )
54 with self.assertRaisesMessage(ImproperlyConfigured, msg):
55 engines.all()