summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2010-03-02 07:47:41 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2010-03-02 07:47:41 +0000
commit755a0f6d96573ae5ccc2e2693e630c63c75a06ea (patch)
tree3f79947e736e1919b7d6fd24babe1ea580844c5d /tests
parenta6225393c259f7c188c84897282838ebc224a489 (diff)
[1.1.X] Fixed #6510 -- Refactored the way child nodes are found in template nodes to avoid potential inconsistencies. Thanks to SmileyChris for the patch.
Backport of r12654 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12655 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/templates/nodelist.py30
-rw-r--r--tests/regressiontests/templates/tests.py27
2 files changed, 57 insertions, 0 deletions
diff --git a/tests/regressiontests/templates/nodelist.py b/tests/regressiontests/templates/nodelist.py
new file mode 100644
index 0000000000..89fac97c66
--- /dev/null
+++ b/tests/regressiontests/templates/nodelist.py
@@ -0,0 +1,30 @@
+from unittest import TestCase
+from django.template.loader import get_template_from_string
+from django.template import VariableNode
+
+
+class NodelistTest(TestCase):
+
+ def test_for(self):
+ source = '{% for i in 1 %}{{ a }}{% endfor %}'
+ template = get_template_from_string(source)
+ vars = template.nodelist.get_nodes_by_type(VariableNode)
+ self.assertEqual(len(vars), 1)
+
+ def test_if(self):
+ source = '{% if x %}{{ a }}{% endif %}'
+ template = get_template_from_string(source)
+ vars = template.nodelist.get_nodes_by_type(VariableNode)
+ self.assertEqual(len(vars), 1)
+
+ def test_ifequal(self):
+ source = '{% ifequal x y %}{{ a }}{% endifequal %}'
+ template = get_template_from_string(source)
+ vars = template.nodelist.get_nodes_by_type(VariableNode)
+ self.assertEqual(len(vars), 1)
+
+ def test_ifchanged(self):
+ source = '{% ifchanged x %}{{ a }}{% endifchanged %}'
+ template = get_template_from_string(source)
+ vars = template.nodelist.get_nodes_by_type(VariableNode)
+ self.assertEqual(len(vars), 1)
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index 43a6c284ec..36a48a2379 100644
--- a/tests/regressiontests/templates/tests.py
+++ b/tests/regressiontests/templates/tests.py
@@ -24,6 +24,7 @@ from context import context_tests
from custom import custom_filters
from parser import token_parsing, filter_parsing, variable_parsing
from unicode import unicode_tests
+from nodelist import NodelistTest
try:
from loaders import *
@@ -804,6 +805,32 @@ class Templates(unittest.TestCase):
# Inheritance from a template with a space in its name should work.
'inheritance29': ("{% extends 'inheritance 28' %}", {}, '!'),
+ # Base template, putting block in a conditional {% if %} tag
+ 'inheritance30': ("1{% if optional %}{% block opt %}2{% endblock %}{% endif %}3", {'optional': True}, '123'),
+
+ # Inherit from a template with block wrapped in an {% if %} tag (in parent), still gets overridden
+ 'inheritance31': ("{% extends 'inheritance30' %}{% block opt %}two{% endblock %}", {'optional': True}, '1two3'),
+ 'inheritance32': ("{% extends 'inheritance30' %}{% block opt %}two{% endblock %}", {}, '13'),
+
+ # Base template, putting block in a conditional {% ifequal %} tag
+ 'inheritance33': ("1{% ifequal optional 1 %}{% block opt %}2{% endblock %}{% endifequal %}3", {'optional': 1}, '123'),
+
+ # Inherit from a template with block wrapped in an {% ifequal %} tag (in parent), still gets overridden
+ 'inheritance34': ("{% extends 'inheritance33' %}{% block opt %}two{% endblock %}", {'optional': 1}, '1two3'),
+ 'inheritance35': ("{% extends 'inheritance33' %}{% block opt %}two{% endblock %}", {'optional': 2}, '13'),
+
+ # Base template, putting block in a {% for %} tag
+ 'inheritance36': ("{% for n in numbers %}_{% block opt %}{{ n }}{% endblock %}{% endfor %}_", {'numbers': '123'}, '_1_2_3_'),
+
+ # Inherit from a template with block wrapped in an {% for %} tag (in parent), still gets overridden
+ 'inheritance37': ("{% extends 'inheritance36' %}{% block opt %}X{% endblock %}", {'numbers': '123'}, '_X_X_X_'),
+ 'inheritance38': ("{% extends 'inheritance36' %}{% block opt %}X{% endblock %}", {}, '_'),
+
+ # The super block will still be found.
+ 'inheritance39': ("{% extends 'inheritance30' %}{% block opt %}new{{ block.super }}{% endblock %}", {'optional': True}, '1new23'),
+ 'inheritance40': ("{% extends 'inheritance33' %}{% block opt %}new{{ block.super }}{% endblock %}", {'optional': 1}, '1new23'),
+ 'inheritance41': ("{% extends 'inheritance36' %}{% block opt %}new{{ block.super }}{% endblock %}", {'numbers': '123'}, '_new1_new2_new3_'),
+
### I18N ##################################################################
# {% spaceless %} tag