summaryrefslogtreecommitdiff
path: root/tests/template_tests
diff options
context:
space:
mode:
authorCurtis Maloney <curtis@tinbrain.net>2013-08-29 18:58:56 +1000
committerAnssi Kääriäinen <akaariai@gmail.com>2013-08-30 10:36:36 +0300
commite2f06226ea4a38377cdb69f2f5768e4e00c2d88e (patch)
tree12f71ff4a4867e279722ecf25db1ef09e60ff29e /tests/template_tests
parente973ee6a9879969b8ae05bb7ff681172cc5386a5 (diff)
Improved {% include %} implementation
Merged BaseIncludeNode, ConstantIncludeNode and Include node. This avoids raising TemplateDoesNotExist at parsing time, allows recursion when passing a literal template name, and should make TEMPLATE_DEBUG behavior consistant. Thanks loic84 for help with the tests. Fixed #3544, fixed #12064, fixed #16147
Diffstat (limited to 'tests/template_tests')
-rw-r--r--tests/template_tests/templates/recursive_include.html7
-rw-r--r--tests/template_tests/tests.py34
2 files changed, 41 insertions, 0 deletions
diff --git a/tests/template_tests/templates/recursive_include.html b/tests/template_tests/templates/recursive_include.html
new file mode 100644
index 0000000000..dc848f32af
--- /dev/null
+++ b/tests/template_tests/templates/recursive_include.html
@@ -0,0 +1,7 @@
+Recursion!
+{% for comment in comments %}
+ {{ comment.comment }}
+ {% if comment.children %}
+ {% include "recursive_include.html" with comments=comment.children %}
+ {% endif %}
+{% endfor %}
diff --git a/tests/template_tests/tests.py b/tests/template_tests/tests.py
index e9c0a0f7c4..74aec32394 100644
--- a/tests/template_tests/tests.py
+++ b/tests/template_tests/tests.py
@@ -349,6 +349,40 @@ class TemplateLoaderTests(TestCase):
output = outer_tmpl.render(ctx)
self.assertEqual(output, 'This worked!')
+ @override_settings(TEMPLATE_DEBUG=True)
+ def test_include_immediate_missing(self):
+ """
+ Regression test for #16417 -- {% include %} tag raises TemplateDoesNotExist at compile time if TEMPLATE_DEBUG is True
+
+ Test that an {% include %} tag with a literal string referencing a
+ template that does not exist does not raise an exception at parse
+ time.
+ """
+ ctx = Context()
+ tmpl = Template('{% include "this_does_not_exist.html" %}')
+ self.assertIsInstance(tmpl, Template)
+
+ @override_settings(TEMPLATE_DEBUG=True)
+ def test_include_recursive(self):
+ comments = [
+ {
+ 'comment': 'A1',
+ 'children': [
+ {'comment': 'B1', 'children': []},
+ {'comment': 'B2', 'children': []},
+ {'comment': 'B3', 'children': [
+ {'comment': 'C1', 'children': []}
+ ]},
+ ]
+ }
+ ]
+
+ t = loader.get_template('recursive_include.html')
+ self.assertEqual(
+ "Recursion! A1 Recursion! B1 B2 B3 Recursion! C1",
+ t.render(Context({'comments': comments})).replace(' ', '').replace('\n', ' ').strip(),
+ )
+
class TemplateRegressionTests(TestCase):