diff options
| author | Vincenzo Pandolfo <pandolfovince@gmail.com> | 2016-03-18 12:48:14 +0000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-03-21 13:01:38 -0400 |
| commit | abf07355aa5d85f4bb4dd9912d70fa62511fa40f (patch) | |
| tree | 01d732e58e69f095b35d275cc42bc08097fd89aa /tests/check_framework | |
| parent | efa9539787dbdd06cd2169023edcf7db3e2ff0c4 (diff) | |
Fixed #26365 -- Added a system check to ensure "string_is_invalid" is a string.
Diffstat (limited to 'tests/check_framework')
| -rw-r--r-- | tests/check_framework/test_templates.py | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/tests/check_framework/test_templates.py b/tests/check_framework/test_templates.py index caaa8857a3..918e0fcbdf 100644 --- a/tests/check_framework/test_templates.py +++ b/tests/check_framework/test_templates.py @@ -1,6 +1,6 @@ -from copy import deepcopy +from copy import copy, deepcopy -from django.core.checks.templates import E001 +from django.core.checks.templates import E001, E002 from django.test import SimpleTestCase from django.test.utils import override_settings @@ -39,3 +39,58 @@ class CheckTemplateSettingsAppDirsTest(SimpleTestCase): del TEMPLATES[0]['OPTIONS']['loaders'] with self.settings(TEMPLATES=TEMPLATES): self.assertEqual(self.func(None), []) + + +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': 42, + }, + }, + ] + + @classmethod + def setUpClass(cls): + super(CheckTemplateStringIfInvalidTest, cls).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__) + + @property + def func(self): + from django.core.checks.templates import check_string_if_invalid_is_string + return check_string_if_invalid_is_string + + @override_settings(TEMPLATES=TEMPLATES_STRING_IF_INVALID) + def test_string_if_invalid_not_string(self): + self.assertEqual(self.func(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' + with self.settings(TEMPLATES=TEMPLATES): + self.assertEqual(self.func(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' + with self.settings(TEMPLATES=TEMPLATES): + self.assertEqual(self.func(None), []) + + def test_string_if_invalid_not_specified(self): + TEMPLATES = deepcopy(self.TEMPLATES_STRING_IF_INVALID) + del TEMPLATES[1]['OPTIONS']['string_if_invalid'] + with self.settings(TEMPLATES=TEMPLATES): + self.assertEqual(self.func(None), [self.error1]) |
