summaryrefslogtreecommitdiff
path: root/tests/template_tests/syntax_tests/test_basic.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/template_tests/syntax_tests/test_basic.py')
-rw-r--r--tests/template_tests/syntax_tests/test_basic.py49
1 files changed, 48 insertions, 1 deletions
diff --git a/tests/template_tests/syntax_tests/test_basic.py b/tests/template_tests/syntax_tests/test_basic.py
index 04cf5f4401..47bc949fdc 100644
--- a/tests/template_tests/syntax_tests/test_basic.py
+++ b/tests/template_tests/syntax_tests/test_basic.py
@@ -1,7 +1,9 @@
+from django.template import Engine
from django.template.base import Origin, Template, TemplateSyntaxError
from django.template.context import Context
from django.template.loader_tags import BlockContext, BlockNode
-from django.test import SimpleTestCase
+from django.test import SimpleTestCase, ignore_warnings
+from django.utils.deprecation import RemovedInDjango70Warning
from django.views.debug import ExceptionReporter
from ..utils import SilentAttrClass, SilentGetItemClass, SomeClass, setup
@@ -393,6 +395,42 @@ class BasicSyntaxTests(SimpleTestCase):
output = self.engine.render_to_string("template", {"meals": Meals})
self.assertEqual(output, "soup is yummy.")
+ def test_double_dot_lookup(self):
+ loaders = [
+ (
+ "django.template.loaders.cached.Loader",
+ [
+ (
+ "django.template.loaders.locmem.Loader",
+ {"template": "{{ doubledot..lookup }}"},
+ ),
+ ],
+ ),
+ ]
+
+ msg = (
+ "Support for double-dot lookups '..' which maps to a lookup of the empty "
+ "string is deprecated.\n Template: template\n Line: 1"
+ )
+
+ for debug in [True, False]:
+ with self.subTest(debug=debug):
+ engine = Engine(loaders=loaders, debug=debug)
+ with self.assertWarnsMessage(RemovedInDjango70Warning, msg):
+ engine.render_to_string("template", {})
+ # Cached loader results in warning only on first access.
+ engine.render_to_string("template", {})
+
+ # RemovedInDjango70Warning.
+ # Replace the above test with the following.
+ # @setup({"template": "{{ doubledot..lookup }}"})
+ # def test_double_dot_lookup(self):
+ # with self.assertRaisesMessage(
+ # TemplateSyntaxError,
+ # "Variable contains '..' on line 1",
+ # ):
+ # self.engine.render_to_string("template")
+
class BlockContextTests(SimpleTestCase):
def test_repr(self):
@@ -429,3 +467,12 @@ class TemplateNameInExceptionTests(SimpleTestCase):
Template("{% endfor %}")
except TemplateSyntaxError as e:
self.assertEqual(str(e), self.template_error_msg)
+
+
+# RemovedInDjango70Warning
+@ignore_warnings(category=RemovedInDjango70Warning)
+class DeprecatedTests(SimpleTestCase):
+ @setup({"template": "{{ doubledot..lookup }}"})
+ def test_double_dot_lookup(self):
+ context = Context({"doubledot": {"": {"lookup": "value"}}})
+ self.assertEqual(self.engine.render_to_string("template", context), "value")