summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Smith <smithdc@gmail.com>2026-04-26 07:53:13 +0100
committerJacob Walls <jacobtylerwalls@gmail.com>2026-04-28 13:07:11 -0400
commit5d911f2d2fecc703be91b2b9b28acc59d34b35f3 (patch)
treefc32596b2e51593a9da35fda6c3833e70c0e2a56 /tests
parente8c6322b4f2ab4df610bb480003a54c88f32210e (diff)
Fixed #35738 -- Deprecated double-dot variable lookups.
Diffstat (limited to 'tests')
-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")