summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/template_tests/templates/test_context_stack.html2
-rw-r--r--tests/template_tests/templatetags/custom.py5
-rw-r--r--tests/template_tests/test_loaders.py12
3 files changed, 19 insertions, 0 deletions
diff --git a/tests/template_tests/templates/test_context_stack.html b/tests/template_tests/templates/test_context_stack.html
new file mode 100644
index 0000000000..c5097c5e66
--- /dev/null
+++ b/tests/template_tests/templates/test_context_stack.html
@@ -0,0 +1,2 @@
+{% load custom %}
+{% context_stack_length %}
diff --git a/tests/template_tests/templatetags/custom.py b/tests/template_tests/templatetags/custom.py
index 9aa51931e0..16e8e3e26a 100644
--- a/tests/template_tests/templatetags/custom.py
+++ b/tests/template_tests/templatetags/custom.py
@@ -22,6 +22,11 @@ def noop(value, param=None):
return value
+@register.simple_tag(takes_context=True)
+def context_stack_length(context):
+ return len(context.dicts)
+
+
@register.simple_tag
def no_params():
"""Expected no_params __doc__"""
diff --git a/tests/template_tests/test_loaders.py b/tests/template_tests/test_loaders.py
index 5f9306b33b..f89b9803e4 100644
--- a/tests/template_tests/test_loaders.py
+++ b/tests/template_tests/test_loaders.py
@@ -171,6 +171,18 @@ class RenderToStringTest(TestCase):
'No template names provided$',
loader.select_template, [])
+ def test_no_empty_dict_pushed_to_stack(self):
+ """
+ No empty dict should be pushed to the context stack when render_to_string
+ is called without any argument (#21741).
+ """
+
+ # The stack should have a length of 1, corresponding to the builtins
+ self.assertEqual('1',
+ loader.render_to_string('test_context_stack.html').strip())
+ self.assertEqual('1',
+ loader.render_to_string('test_context_stack.html', context_instance=Context()).strip())
+
class TemplateDirsOverrideTest(unittest.TestCase):