diff options
| author | Tim Graham <timograham@gmail.com> | 2015-04-01 13:12:18 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-04-01 13:12:18 -0400 |
| commit | 5c63c45512eeca1f9c2dbdb0c46cbc7d9c550bdc (patch) | |
| tree | d8c56b2a3015e64a9b92b54a8800a79438ac521d /tests | |
| parent | ff8eabc5ccb7af928856910c8af72d84346821e9 (diff) | |
[1.8.x] Fixed #23441, #24555 -- Improved the behavior of InclusionNode.
This change:
* Makes the InclusionNode cache-safe by removing render-time side effects
to its nodelist.
* Ensures the render_context stack is properly scoped and reset by updating
the render call to use Template.render rather than Nodelist.render.
Backport of 0808ccce3808235c5b5a56e3f689cec0d4bc0ebf from master
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/template_tests/templates/inclusion_base.html | 1 | ||||
| -rw-r--r-- | tests/template_tests/templates/inclusion_extends1.html | 2 | ||||
| -rw-r--r-- | tests/template_tests/templates/inclusion_extends2.html | 2 | ||||
| -rw-r--r-- | tests/template_tests/templatetags/inclusion.py | 10 | ||||
| -rw-r--r-- | tests/template_tests/test_custom.py | 23 |
5 files changed, 37 insertions, 1 deletions
diff --git a/tests/template_tests/templates/inclusion_base.html b/tests/template_tests/templates/inclusion_base.html new file mode 100644 index 0000000000..795c4dad32 --- /dev/null +++ b/tests/template_tests/templates/inclusion_base.html @@ -0,0 +1 @@ +{% block content %}base{% endblock %} diff --git a/tests/template_tests/templates/inclusion_extends1.html b/tests/template_tests/templates/inclusion_extends1.html new file mode 100644 index 0000000000..4827f42d3c --- /dev/null +++ b/tests/template_tests/templates/inclusion_extends1.html @@ -0,0 +1,2 @@ +{% extends 'inclusion_base.html' %} +{% block content %}one{% endblock %} diff --git a/tests/template_tests/templates/inclusion_extends2.html b/tests/template_tests/templates/inclusion_extends2.html new file mode 100644 index 0000000000..0ec4d64c04 --- /dev/null +++ b/tests/template_tests/templates/inclusion_extends2.html @@ -0,0 +1,2 @@ +{% extends 'inclusion_base.html' %} +{% block content %}two{% endblock %} diff --git a/tests/template_tests/templatetags/inclusion.py b/tests/template_tests/templatetags/inclusion.py index 77c9abeb5c..1631ce92b9 100644 --- a/tests/template_tests/templatetags/inclusion.py +++ b/tests/template_tests/templatetags/inclusion.py @@ -164,3 +164,13 @@ def inclusion_tag_without_context_parameter(arg): """Expected inclusion_tag_without_context_parameter __doc__""" return {} inclusion_tag_without_context_parameter.anything = "Expected inclusion_tag_without_context_parameter __dict__" + + +@register.inclusion_tag('inclusion_extends1.html') +def inclusion_extends1(): + return {} + + +@register.inclusion_tag('inclusion_extends2.html') +def inclusion_extends2(): + return {} diff --git a/tests/template_tests/test_custom.py b/tests/template_tests/test_custom.py index 8cf45b68d5..fa485bb674 100644 --- a/tests/template_tests/test_custom.py +++ b/tests/template_tests/test_custom.py @@ -2,7 +2,8 @@ from __future__ import unicode_literals import os -from django.template import Context, Template, TemplateSyntaxError +from django.template import Context, Engine, Template, TemplateSyntaxError +from django.template.base import Node from django.test import SimpleTestCase, ignore_warnings from django.test.utils import extend_sys_path from django.utils import six @@ -274,6 +275,26 @@ class CustomTagTests(SimpleTestCase): c.use_l10n = True self.assertEqual(t.render(c).strip(), 'True') + def test_no_render_side_effect(self): + """ + #23441 -- InclusionNode shouldn't modify its nodelist at render time. + """ + engine = Engine(app_dirs=True) + template = engine.from_string('{% load inclusion %}{% inclusion_no_params %}') + count = template.nodelist.get_nodes_by_type(Node) + template.render(Context({})) + self.assertEqual(template.nodelist.get_nodes_by_type(Node), count) + + def test_render_context_is_cleared(self): + """ + #24555 -- InclusionNode should push and pop the render_context stack + when rendering. Otherwise, leftover values such as blocks from + extending can interfere with subsequent rendering. + """ + engine = Engine(app_dirs=True) + template = engine.from_string('{% load inclusion %}{% inclusion_extends1 %}{% inclusion_extends2 %}') + self.assertEqual(template.render(Context({})).strip(), 'one\ntwo') + def test_assignment_tags(self): c = Context({'value': 42}) |
