summaryrefslogtreecommitdiff
path: root/tests/template_tests
diff options
context:
space:
mode:
authorKeshav Kumar <https://github.com/keshav2212>2020-02-02 22:18:07 +0530
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-02-18 06:56:05 +0100
commitf37d548ede290690589e86b892c4f106e2a8e1bc (patch)
tree693f0ac6a43a19daf06c5826d32f51107e1e71b1 /tests/template_tests
parent86908785076b2bbc31b908781da6b6ad1779b18b (diff)
Fixed #20995 -- Added support for iterables of template names to {% include %} template tag.
Thanks Adam Johnson for the review.
Diffstat (limited to 'tests/template_tests')
-rw-r--r--tests/template_tests/syntax_tests/test_include.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/template_tests/syntax_tests/test_include.py b/tests/template_tests/syntax_tests/test_include.py
index b840c676f7..f1fee7d227 100644
--- a/tests/template_tests/syntax_tests/test_include.py
+++ b/tests/template_tests/syntax_tests/test_include.py
@@ -243,6 +243,26 @@ class IncludeTests(SimpleTestCase):
output = outer_tmpl.render(ctx)
self.assertEqual(output, 'This worked!')
+ def test_include_template_iterable(self):
+ engine = Engine.get_default()
+ outer_temp = engine.from_string('{% include var %}')
+ tests = [
+ ('admin/fail.html', 'index.html'),
+ ['admin/fail.html', 'index.html'],
+ ]
+ for template_names in tests:
+ with self.subTest(template_names):
+ output = outer_temp.render(Context({'var': template_names}))
+ self.assertEqual(output, 'index\n')
+
+ def test_include_template_none(self):
+ engine = Engine.get_default()
+ outer_temp = engine.from_string('{% include var %}')
+ ctx = Context({'var': None})
+ msg = 'No template names provided'
+ with self.assertRaisesMessage(TemplateDoesNotExist, msg):
+ outer_temp.render(ctx)
+
def test_include_from_loader_get_template(self):
tmpl = loader.get_template('include_tpl.html') # {% include tmpl %}
output = tmpl.render({'tmpl': loader.get_template('index.html')})