summaryrefslogtreecommitdiff
path: root/tests/template_tests/syntax_tests/test_for.py
diff options
context:
space:
mode:
authorMads Jensen <mje@inducks.org>2017-10-04 17:36:15 +0200
committerTim Graham <timograham@gmail.com>2017-10-05 11:33:14 -0400
commit86367a11d347c489e450232b19d9ca23e5a9cef4 (patch)
treedc7510b49417afef401aedf9852407f068117511 /tests/template_tests/syntax_tests/test_for.py
parentee7ab1b6e2439f79f3594925a6bf539aabaec8e1 (diff)
Added tests for invalid {% for %} usage and ForLoop.__repr__().
Diffstat (limited to 'tests/template_tests/syntax_tests/test_for.py')
-rw-r--r--tests/template_tests/syntax_tests/test_for.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/template_tests/syntax_tests/test_for.py b/tests/template_tests/syntax_tests/test_for.py
index 1ffe25e1a7..d7db6108a2 100644
--- a/tests/template_tests/syntax_tests/test_for.py
+++ b/tests/template_tests/syntax_tests/test_for.py
@@ -1,4 +1,5 @@
from django.template import TemplateSyntaxError
+from django.template.defaulttags import ForNode
from django.test import SimpleTestCase
from ..utils import setup
@@ -197,3 +198,21 @@ class ForTagTests(SimpleTestCase):
},
})
self.assertEqual(output, 'two:2,four:4,_six:6,eight:8,')
+
+ @setup({'invalid_for_loop': '{% for x items %}{{ x }}{% endfor %}'})
+ def test_invalid_arg(self):
+ msg = "'for' statements should have at least four words: for x items"
+ with self.assertRaisesMessage(TemplateSyntaxError, msg):
+ self.engine.render_to_string('invalid_for_loop', {'items': (1, 2)})
+
+ @setup({'invalid_for_loop': '{% for x from items %}{{ x }}{% endfor %}'})
+ def test_invalid_in_keyword(self):
+ msg = "'for' statements should use the format 'for x in y': for x from items"
+ with self.assertRaisesMessage(TemplateSyntaxError, msg):
+ self.engine.render_to_string('invalid_for_loop', {'items': (1, 2)})
+
+
+class ForNodeTests(SimpleTestCase):
+ def test_repr(self):
+ node = ForNode('x', 'sequence', is_reversed=True, nodelist_loop=['val'], nodelist_empty=['val2'])
+ self.assertEqual(repr(node), '<ForNode: for x in sequence, tail_len: 1 reversed>')