summaryrefslogtreecommitdiff
path: root/tests/template_tests/syntax_tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/template_tests/syntax_tests')
-rw-r--r--tests/template_tests/syntax_tests/test_if_changed.py11
-rw-r--r--tests/template_tests/syntax_tests/test_include.py20
2 files changed, 31 insertions, 0 deletions
diff --git a/tests/template_tests/syntax_tests/test_if_changed.py b/tests/template_tests/syntax_tests/test_if_changed.py
index bf8a95d8a4..ced81e9865 100644
--- a/tests/template_tests/syntax_tests/test_if_changed.py
+++ b/tests/template_tests/syntax_tests/test_if_changed.py
@@ -212,3 +212,14 @@ class IfChangedTests(SimpleTestCase):
])
output = engine.render_to_string('template', dict(vars=[1, 1, 2, 2, 3, 3]))
self.assertEqual(output, "123")
+
+ def test_include_state(self):
+ """Tests the node state for different IncludeNodes (#27974)."""
+ engine = Engine(loaders=[
+ ('django.template.loaders.locmem.Loader', {
+ 'template': '{% for x in vars %}{% include "include" %}{% include "include" %}{% endfor %}',
+ 'include': '{% ifchanged %}{{ x }}{% endifchanged %}',
+ }),
+ ])
+ output = engine.render_to_string('template', dict(vars=[1, 1, 2, 2, 3, 3]))
+ self.assertEqual(output, '112233')
diff --git a/tests/template_tests/syntax_tests/test_include.py b/tests/template_tests/syntax_tests/test_include.py
index 185bcb3988..3368522065 100644
--- a/tests/template_tests/syntax_tests/test_include.py
+++ b/tests/template_tests/syntax_tests/test_include.py
@@ -311,3 +311,23 @@ class IncludeTests(SimpleTestCase):
"Recursion! A1 Recursion! B1 B2 B3 Recursion! C1",
t.render(Context({'comments': comments})).replace(' ', '').replace('\n', ' ').strip(),
)
+
+ def test_include_cache(self):
+ """
+ {% include %} keeps resolved templates constant (#27974). The
+ CounterNode object in the {% counter %} template tag is created once
+ if caching works properly. Each iteration increases the counter instead
+ of restarting it.
+
+ This works as a regression test only if the cached loader
+ isn't used, so the @setup decorator isn't used.
+ """
+ engine = Engine(loaders=[
+ ('django.template.loaders.locmem.Loader', {
+ 'template': '{% for x in vars %}{% include "include" %}{% endfor %}',
+ 'include': '{% include "next" %}',
+ 'next': '{% load custom %}{% counter %}'
+ }),
+ ], libraries={'custom': 'template_tests.templatetags.custom'})
+ output = engine.render_to_string('template', dict(vars=range(9)))
+ self.assertEqual(output, '012345678')