diff options
author | Matt Westcott <matt@west.co.tt> | 2021-08-18 22:11:42 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-08-19 07:39:55 +0200 |
commit | 5092f7247de8d3aa2fdb762e50f5ac2aa4e6f6e0 (patch) | |
tree | 98727543de14fca7d0f4ec7ebf330befa97b2627 /tests/template_tests | |
parent | 231de683d86374c2b74da2185efc6ddfb5eb3341 (diff) | |
download | django-5092f7247de8d3aa2fdb762e50f5ac2aa4e6f6e0.tar.gz |
Fixed #33036 -- Made simple_tag()/inclusion_tag() with takes_context raise TemplateSyntaxError when function has no parameters.
Diffstat (limited to 'tests/template_tests')
-rw-r--r-- | tests/template_tests/templatetags/custom.py | 11 | ||||
-rw-r--r-- | tests/template_tests/templatetags/inclusion.py | 11 | ||||
-rw-r--r-- | tests/template_tests/test_custom.py | 20 |
3 files changed, 42 insertions, 0 deletions
diff --git a/tests/template_tests/templatetags/custom.py b/tests/template_tests/templatetags/custom.py index 8efd70147a..0880e6fad4 100644 --- a/tests/template_tests/templatetags/custom.py +++ b/tests/template_tests/templatetags/custom.py @@ -151,6 +151,17 @@ simple_tag_without_context_parameter.anything = "Expected simple_tag_without_con @register.simple_tag(takes_context=True) +def simple_tag_takes_context_without_params(): + """Expected simple_tag_takes_context_without_params __doc__""" + return 'Expected result' + + +simple_tag_takes_context_without_params.anything = ( + 'Expected simple_tag_takes_context_without_params __dict__' +) + + +@register.simple_tag(takes_context=True) def escape_naive(context): """A tag that doesn't even think about escaping issues""" return "Hello {}!".format(context['name']) diff --git a/tests/template_tests/templatetags/inclusion.py b/tests/template_tests/templatetags/inclusion.py index 21b4b10a6e..45281b4c56 100644 --- a/tests/template_tests/templatetags/inclusion.py +++ b/tests/template_tests/templatetags/inclusion.py @@ -242,6 +242,17 @@ def inclusion_tag_without_context_parameter(arg): inclusion_tag_without_context_parameter.anything = "Expected inclusion_tag_without_context_parameter __dict__" +@register.inclusion_tag('inclusion.html', takes_context=True) +def inclusion_tag_takes_context_without_params(): + """Expected inclusion_tag_takes_context_without_params __doc__""" + return {} + + +inclusion_tag_takes_context_without_params.anything = ( + 'Expected inclusion_tag_takes_context_without_params __dict__' +) + + @register.inclusion_tag('inclusion_extends1.html') def inclusion_extends1(): return {} diff --git a/tests/template_tests/test_custom.py b/tests/template_tests/test_custom.py index 62db0d44bc..cade3e4610 100644 --- a/tests/template_tests/test_custom.py +++ b/tests/template_tests/test_custom.py @@ -169,6 +169,16 @@ class SimpleTagTests(TagTestCase): with self.assertRaisesMessage(TemplateSyntaxError, msg): self.engine.from_string('{% load custom %}{% simple_tag_without_context_parameter 123 %}') + def test_simple_tag_missing_context_no_params(self): + msg = ( + "'simple_tag_takes_context_without_params' is decorated with " + "takes_context=True so it must have a first argument of 'context'" + ) + with self.assertRaisesMessage(TemplateSyntaxError, msg): + self.engine.from_string( + '{% load custom %}{% simple_tag_takes_context_without_params %}' + ) + class InclusionTagTests(TagTestCase): @@ -256,6 +266,16 @@ class InclusionTagTests(TagTestCase): with self.assertRaisesMessage(TemplateSyntaxError, msg): self.engine.from_string('{% load inclusion %}{% inclusion_tag_without_context_parameter 123 %}') + def test_include_tag_missing_context_no_params(self): + msg = ( + "'inclusion_tag_takes_context_without_params' is decorated with " + "takes_context=True so it must have a first argument of 'context'" + ) + with self.assertRaisesMessage(TemplateSyntaxError, msg): + self.engine.from_string( + '{% load inclusion %}{% inclusion_tag_takes_context_without_params %}' + ) + def test_inclusion_tags_from_template(self): c = Context({'value': 42}) |