Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #14960 -- Added tests for inclusion tags. Thanks to Julien Phal…

…ip for the report, and to avenet and Paul Bissex for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15819 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c966566171a0480ea64774f7468c6d218b1088d5 1 parent 23288d1
Russell Keith-Magee authored March 15, 2011
26  tests/regressiontests/templates/custom.py
@@ -52,3 +52,29 @@ def a_simple_tag_without_parameters(arg):
52 52
         register = template.Library()
53 53
         decorator = register.simple_tag(takes_context=True)
54 54
         self.assertRaises(template.TemplateSyntaxError, decorator, a_simple_tag_without_parameters)
  55
+
  56
+    def test_inclusion_tags(self):
  57
+        c = template.Context({'value': 42})
  58
+
  59
+        t = template.Template('{% load custom %}{% inclusion_no_params %}')
  60
+        self.assertEquals(t.render(c), u'inclusion_no_params - Expected result\n')
  61
+
  62
+        t = template.Template('{% load custom %}{% inclusion_one_param 37 %}')
  63
+        self.assertEquals(t.render(c), u'inclusion_one_param - Expected result: 37\n')
  64
+
  65
+        t = template.Template('{% load custom %}{% inclusion_explicit_no_context 37 %}')
  66
+        self.assertEquals(t.render(c), u'inclusion_explicit_no_context - Expected result: 37\n')
  67
+
  68
+        t = template.Template('{% load custom %}{% inclusion_no_params_with_context %}')
  69
+        self.assertEquals(t.render(c), u'inclusion_no_params_with_context - Expected result (context value: 42)\n')
  70
+
  71
+        t = template.Template('{% load custom %}{% inclusion_params_and_context 37 %}')
  72
+        self.assertEquals(t.render(c), u'inclusion_params_and_context - Expected result (context value: 42): 37\n')
  73
+
  74
+    def test_inclusion_tag_registration(self):
  75
+        # Test that the decorators preserve the decorated function's docstring, name and attributes.
  76
+        self.verify_tag(custom.inclusion_no_params, 'inclusion_no_params')
  77
+        self.verify_tag(custom.inclusion_one_param, 'inclusion_one_param')
  78
+        self.verify_tag(custom.inclusion_explicit_no_context, 'inclusion_explicit_no_context')
  79
+        self.verify_tag(custom.inclusion_no_params_with_context, 'inclusion_no_params_with_context')
  80
+        self.verify_tag(custom.inclusion_params_and_context, 'inclusion_params_and_context')
30  tests/regressiontests/templates/templatetags/custom.py
@@ -39,3 +39,33 @@ def params_and_context(context, arg):
39 39
     return "params_and_context - Expected result (context value: %s): %s" % (context['value'], arg)
40 40
 params_and_context.anything = "Expected params_and_context __dict__"
41 41
 
  42
+@register.inclusion_tag('inclusion.html')
  43
+def inclusion_no_params():
  44
+    """Expected inclusion_no_params __doc__"""
  45
+    return {"result" : "inclusion_no_params - Expected result"}
  46
+inclusion_no_params.anything = "Expected inclusion_no_params __dict__"
  47
+
  48
+@register.inclusion_tag('inclusion.html')
  49
+def inclusion_one_param(arg):
  50
+    """Expected inclusion_one_param __doc__"""
  51
+    return {"result" : "inclusion_one_param - Expected result: %s" % arg}
  52
+inclusion_one_param.anything = "Expected inclusion_one_param __dict__"
  53
+
  54
+@register.inclusion_tag('inclusion.html', takes_context=False)
  55
+def inclusion_explicit_no_context(arg):
  56
+    """Expected inclusion_explicit_no_context __doc__"""
  57
+    return {"result" : "inclusion_explicit_no_context - Expected result: %s" % arg}
  58
+inclusion_explicit_no_context.anything = "Expected inclusion_explicit_no_context __dict__"
  59
+
  60
+@register.inclusion_tag('inclusion.html', takes_context=True)
  61
+def inclusion_no_params_with_context(context):
  62
+    """Expected inclusion_no_params_with_context __doc__"""
  63
+    return {"result" : "inclusion_no_params_with_context - Expected result (context value: %s)" % context['value']}
  64
+inclusion_no_params_with_context.anything = "Expected inclusion_no_params_with_context __dict__"
  65
+
  66
+@register.inclusion_tag('inclusion.html', takes_context=True)
  67
+def inclusion_params_and_context(context, arg):
  68
+    """Expected inclusion_params_and_context __doc__"""
  69
+    return {"result" : "inclusion_params_and_context - Expected result (context value: %s): %s" % (context['value'], arg)}
  70
+inclusion_params_and_context.anything = "Expected inclusion_params_and_context __dict__"
  71
+

0 notes on commit c966566

Please sign in to comment.
Something went wrong with that request. Please try again.