From eaf4d8c0d85056c3481986fe092d5a8786bc4f26 Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Thu, 4 Jun 2015 17:55:58 +0200 Subject: Fixed #24922 -- Added system check for templates setting If `'loaders'` is present in the `TEMPLATES` options together with `APP_DIRS` set to `True`, the template engine raises an exception. This conflict is now detected by the system check templates.E001. --- tests/check_framework/test_templates.py | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/check_framework/test_templates.py (limited to 'tests/check_framework') diff --git a/tests/check_framework/test_templates.py b/tests/check_framework/test_templates.py new file mode 100644 index 0000000000..27ccf138a7 --- /dev/null +++ b/tests/check_framework/test_templates.py @@ -0,0 +1,39 @@ +from django.core.checks.templates import E001 +from django.test import SimpleTestCase +from django.test.utils import override_settings + + +class CheckTemplateSettingsAppDirsTest(SimpleTestCase): + TEMPLATES_APP_DIRS_AND_LOADERS = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'APP_DIRS': True, + 'OPTIONS': { + 'loaders': ['django.template.loaders.filesystem.Loader'], + }, + }, + ] + + @property + def func(self): + from django.core.checks.templates import check_setting_app_dirs_loaders + return check_setting_app_dirs_loaders + + @override_settings(TEMPLATES=TEMPLATES_APP_DIRS_AND_LOADERS) + def test_app_dirs_and_loaders(self): + """ + Error if template loaders are specified and APP_DIRS is True. + """ + self.assertEqual(self.func(None), [E001]) + + def test_app_dirs_removed(self): + TEMPLATES = self.TEMPLATES_APP_DIRS_AND_LOADERS[:] + del TEMPLATES[0]['APP_DIRS'] + with self.settings(TEMPLATES=TEMPLATES): + self.assertEqual(self.func(None), []) + + def test_loaders_removed(self): + TEMPLATES = self.TEMPLATES_APP_DIRS_AND_LOADERS[:] + del TEMPLATES[0]['OPTIONS']['loaders'] + with self.settings(TEMPLATES=TEMPLATES): + self.assertEqual(self.func(None), []) -- cgit v1.3