diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/template_tests/templates/recursive_include.html | 7 | ||||
| -rw-r--r-- | tests/template_tests/tests.py | 34 |
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): |
