summaryrefslogtreecommitdiff
path: root/tests/check_framework/test_templates.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/check_framework/test_templates.py')
-rw-r--r--tests/check_framework/test_templates.py159
1 files changed, 98 insertions, 61 deletions
diff --git a/tests/check_framework/test_templates.py b/tests/check_framework/test_templates.py
index 88c0479436..352a017e55 100644
--- a/tests/check_framework/test_templates.py
+++ b/tests/check_framework/test_templates.py
@@ -2,8 +2,12 @@ from copy import copy, deepcopy
from django.core.checks import Error
from django.core.checks.templates import (
- E001, E002, E003, check_for_template_tags_with_the_same_name,
- check_setting_app_dirs_loaders, check_string_if_invalid_is_string,
+ E001,
+ E002,
+ E003,
+ check_for_template_tags_with_the_same_name,
+ check_setting_app_dirs_loaders,
+ check_string_if_invalid_is_string,
)
from django.test import SimpleTestCase
from django.test.utils import override_settings
@@ -12,10 +16,10 @@ 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'],
+ "BACKEND": "django.template.backends.django.DjangoTemplates",
+ "APP_DIRS": True,
+ "OPTIONS": {
+ "loaders": ["django.template.loaders.filesystem.Loader"],
},
},
]
@@ -29,13 +33,13 @@ class CheckTemplateSettingsAppDirsTest(SimpleTestCase):
def test_app_dirs_removed(self):
TEMPLATES = deepcopy(self.TEMPLATES_APP_DIRS_AND_LOADERS)
- del TEMPLATES[0]['APP_DIRS']
+ del TEMPLATES[0]["APP_DIRS"]
with self.settings(TEMPLATES=TEMPLATES):
self.assertEqual(check_setting_app_dirs_loaders(None), [])
def test_loaders_removed(self):
TEMPLATES = deepcopy(self.TEMPLATES_APP_DIRS_AND_LOADERS)
- del TEMPLATES[0]['OPTIONS']['loaders']
+ del TEMPLATES[0]["OPTIONS"]["loaders"]
with self.settings(TEMPLATES=TEMPLATES):
self.assertEqual(check_setting_app_dirs_loaders(None), [])
@@ -43,15 +47,15 @@ class CheckTemplateSettingsAppDirsTest(SimpleTestCase):
class CheckTemplateStringIfInvalidTest(SimpleTestCase):
TEMPLATES_STRING_IF_INVALID = [
{
- 'BACKEND': 'django.template.backends.django.DjangoTemplates',
- 'OPTIONS': {
- 'string_if_invalid': False,
+ "BACKEND": "django.template.backends.django.DjangoTemplates",
+ "OPTIONS": {
+ "string_if_invalid": False,
},
},
{
- 'BACKEND': 'django.template.backends.django.DjangoTemplates',
- 'OPTIONS': {
- 'string_if_invalid': 42,
+ "BACKEND": "django.template.backends.django.DjangoTemplates",
+ "OPTIONS": {
+ "string_if_invalid": 42,
},
},
]
@@ -61,31 +65,41 @@ class CheckTemplateStringIfInvalidTest(SimpleTestCase):
super().setUpClass()
cls.error1 = copy(E002)
cls.error2 = copy(E002)
- string_if_invalid1 = cls.TEMPLATES_STRING_IF_INVALID[0]['OPTIONS']['string_if_invalid']
- string_if_invalid2 = cls.TEMPLATES_STRING_IF_INVALID[1]['OPTIONS']['string_if_invalid']
- cls.error1.msg = cls.error1.msg.format(string_if_invalid1, type(string_if_invalid1).__name__)
- cls.error2.msg = cls.error2.msg.format(string_if_invalid2, type(string_if_invalid2).__name__)
+ string_if_invalid1 = cls.TEMPLATES_STRING_IF_INVALID[0]["OPTIONS"][
+ "string_if_invalid"
+ ]
+ string_if_invalid2 = cls.TEMPLATES_STRING_IF_INVALID[1]["OPTIONS"][
+ "string_if_invalid"
+ ]
+ cls.error1.msg = cls.error1.msg.format(
+ string_if_invalid1, type(string_if_invalid1).__name__
+ )
+ cls.error2.msg = cls.error2.msg.format(
+ string_if_invalid2, type(string_if_invalid2).__name__
+ )
@override_settings(TEMPLATES=TEMPLATES_STRING_IF_INVALID)
def test_string_if_invalid_not_string(self):
- self.assertEqual(check_string_if_invalid_is_string(None), [self.error1, self.error2])
+ self.assertEqual(
+ check_string_if_invalid_is_string(None), [self.error1, self.error2]
+ )
def test_string_if_invalid_first_is_string(self):
TEMPLATES = deepcopy(self.TEMPLATES_STRING_IF_INVALID)
- TEMPLATES[0]['OPTIONS']['string_if_invalid'] = 'test'
+ TEMPLATES[0]["OPTIONS"]["string_if_invalid"] = "test"
with self.settings(TEMPLATES=TEMPLATES):
self.assertEqual(check_string_if_invalid_is_string(None), [self.error2])
def test_string_if_invalid_both_are_strings(self):
TEMPLATES = deepcopy(self.TEMPLATES_STRING_IF_INVALID)
- TEMPLATES[0]['OPTIONS']['string_if_invalid'] = 'test'
- TEMPLATES[1]['OPTIONS']['string_if_invalid'] = 'test'
+ TEMPLATES[0]["OPTIONS"]["string_if_invalid"] = "test"
+ TEMPLATES[1]["OPTIONS"]["string_if_invalid"] = "test"
with self.settings(TEMPLATES=TEMPLATES):
self.assertEqual(check_string_if_invalid_is_string(None), [])
def test_string_if_invalid_not_specified(self):
TEMPLATES = deepcopy(self.TEMPLATES_STRING_IF_INVALID)
- del TEMPLATES[1]['OPTIONS']['string_if_invalid']
+ del TEMPLATES[1]["OPTIONS"]["string_if_invalid"]
with self.settings(TEMPLATES=TEMPLATES):
self.assertEqual(check_string_if_invalid_is_string(None), [self.error1])
@@ -108,18 +122,20 @@ class CheckTemplateTagLibrariesWithSameName(SimpleTestCase):
@staticmethod
def get_settings(module_name, module_path):
return {
- 'BACKEND': 'django.template.backends.django.DjangoTemplates',
- 'OPTIONS': {
- 'libraries': {
- module_name: f'check_framework.template_test_apps.{module_path}',
+ "BACKEND": "django.template.backends.django.DjangoTemplates",
+ "OPTIONS": {
+ "libraries": {
+ module_name: f"check_framework.template_test_apps.{module_path}",
},
},
}
- @override_settings(INSTALLED_APPS=[
- 'check_framework.template_test_apps.same_tags_app_1',
- 'check_framework.template_test_apps.same_tags_app_2',
- ])
+ @override_settings(
+ INSTALLED_APPS=[
+ "check_framework.template_test_apps.same_tags_app_1",
+ "check_framework.template_test_apps.same_tags_app_2",
+ ]
+ )
def test_template_tags_with_same_name(self):
self.assertEqual(
check_for_template_tags_with_the_same_name(None),
@@ -127,46 +143,67 @@ class CheckTemplateTagLibrariesWithSameName(SimpleTestCase):
)
def test_template_tags_with_same_library_name(self):
- with self.settings(TEMPLATES=[
- self.get_settings('same_tags', 'same_tags_app_1.templatetags.same_tags'),
- self.get_settings('same_tags', 'same_tags_app_2.templatetags.same_tags'),
- ]):
+ with self.settings(
+ TEMPLATES=[
+ self.get_settings(
+ "same_tags", "same_tags_app_1.templatetags.same_tags"
+ ),
+ self.get_settings(
+ "same_tags", "same_tags_app_2.templatetags.same_tags"
+ ),
+ ]
+ ):
self.assertEqual(
check_for_template_tags_with_the_same_name(None),
[self.error_same_tags],
)
- @override_settings(INSTALLED_APPS=[
- 'check_framework.template_test_apps.same_tags_app_1'
- ])
+ @override_settings(
+ INSTALLED_APPS=["check_framework.template_test_apps.same_tags_app_1"]
+ )
def test_template_tags_with_same_library_name_and_module_name(self):
- with self.settings(TEMPLATES=[
- self.get_settings(
- 'same_tags',
- 'different_tags_app.templatetags.different_tags',
- ),
- ]):
- self.assertEqual(check_for_template_tags_with_the_same_name(None), [Error(
- E003.msg.format(
- "'same_tags'",
- "'check_framework.template_test_apps.different_tags_app."
- "templatetags.different_tags', "
- "'check_framework.template_test_apps.same_tags_app_1."
- "templatetags.same_tags'",
+ with self.settings(
+ TEMPLATES=[
+ self.get_settings(
+ "same_tags",
+ "different_tags_app.templatetags.different_tags",
),
- id=E003.id,
- )])
+ ]
+ ):
+ self.assertEqual(
+ check_for_template_tags_with_the_same_name(None),
+ [
+ Error(
+ E003.msg.format(
+ "'same_tags'",
+ "'check_framework.template_test_apps.different_tags_app."
+ "templatetags.different_tags', "
+ "'check_framework.template_test_apps.same_tags_app_1."
+ "templatetags.same_tags'",
+ ),
+ id=E003.id,
+ )
+ ],
+ )
def test_template_tags_with_different_library_name(self):
- with self.settings(TEMPLATES=[
- self.get_settings('same_tags', 'same_tags_app_1.templatetags.same_tags'),
- self.get_settings('not_same_tags', 'same_tags_app_2.templatetags.same_tags'),
- ]):
+ with self.settings(
+ TEMPLATES=[
+ self.get_settings(
+ "same_tags", "same_tags_app_1.templatetags.same_tags"
+ ),
+ self.get_settings(
+ "not_same_tags", "same_tags_app_2.templatetags.same_tags"
+ ),
+ ]
+ ):
self.assertEqual(check_for_template_tags_with_the_same_name(None), [])
- @override_settings(INSTALLED_APPS=[
- 'check_framework.template_test_apps.same_tags_app_1',
- 'check_framework.template_test_apps.different_tags_app',
- ])
+ @override_settings(
+ INSTALLED_APPS=[
+ "check_framework.template_test_apps.same_tags_app_1",
+ "check_framework.template_test_apps.different_tags_app",
+ ]
+ )
def test_template_tags_with_different_name(self):
self.assertEqual(check_for_template_tags_with_the_same_name(None), [])