summaryrefslogtreecommitdiff
path: root/tests/template_tests/syntax_tests/i18n/test_blocktrans.py
diff options
context:
space:
mode:
authorMads Jensen <mje@inducks.org>2018-03-21 08:20:04 +0100
committerTim Graham <timograham@gmail.com>2018-03-21 08:38:07 -0400
commitbb79e480e17fd9cabc6d6c873f721c66d1ad7465 (patch)
tree6c218b18a7165f1c0ecfbf957e6e22fc88f1ff5c /tests/template_tests/syntax_tests/i18n/test_blocktrans.py
parentc76d87427d70f6c91ab855ed688828aa982720d2 (diff)
Increased test coverage for i18n template tags.
Diffstat (limited to 'tests/template_tests/syntax_tests/i18n/test_blocktrans.py')
-rw-r--r--tests/template_tests/syntax_tests/i18n/test_blocktrans.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/template_tests/syntax_tests/i18n/test_blocktrans.py b/tests/template_tests/syntax_tests/i18n/test_blocktrans.py
index 425e748d53..ac8fc16da8 100644
--- a/tests/template_tests/syntax_tests/i18n/test_blocktrans.py
+++ b/tests/template_tests/syntax_tests/i18n/test_blocktrans.py
@@ -233,6 +233,45 @@ class I18nBlockTransTagTests(SimpleTestCase):
output = self.engine.render_to_string('template')
self.assertEqual(output, '%s')
+ @setup({'template': '{% load i18n %}{% blocktrans %}{% block b %} {% endblock %}{% endblocktrans %}'})
+ def test_with_block(self):
+ msg = "'blocktrans' doesn't allow other block tags (seen 'block b') inside it"
+ with self.assertRaisesMessage(TemplateSyntaxError, msg):
+ self.engine.render_to_string('template')
+
+ @setup({'template': '{% load i18n %}{% blocktrans %}{% for b in [1, 2, 3] %} {% endfor %}{% endblocktrans %}'})
+ def test_with_for(self):
+ msg = "'blocktrans' doesn't allow other block tags (seen 'for b in [1, 2, 3]') inside it"
+ with self.assertRaisesMessage(TemplateSyntaxError, msg):
+ self.engine.render_to_string('template')
+
+ @setup({'template': '{% load i18n %}{% blocktrans with foo=bar with %}{{ foo }}{% endblocktrans %}'})
+ def test_variable_twice(self):
+ with self.assertRaisesMessage(TemplateSyntaxError, "The 'with' option was specified more than once"):
+ self.engine.render_to_string('template', {'foo': 'bar'})
+
+ @setup({'template': '{% load i18n %}{% blocktrans with %}{% endblocktrans %}'})
+ def test_no_args_with(self):
+ msg = '"with" in \'blocktrans\' tag needs at least one keyword argument.'
+ with self.assertRaisesMessage(TemplateSyntaxError, msg):
+ self.engine.render_to_string('template')
+
+ @setup({'template': '{% load i18n %}{% blocktrans count a %}{% endblocktrans %}'})
+ def test_count(self):
+ msg = '"count" in \'blocktrans\' tag expected exactly one keyword argument.'
+ with self.assertRaisesMessage(TemplateSyntaxError, msg):
+ self.engine.render_to_string('template', {'a': [1, 2, 3]})
+
+ @setup({'template': (
+ '{% load i18n %}{% blocktrans count count=var|length %}'
+ 'There is {{ count }} object. {% block a %} {% endblock %}'
+ '{% endblocktrans %}'
+ )})
+ def test_plural_bad_syntax(self):
+ msg = "'blocktrans' doesn't allow other block tags inside it"
+ with self.assertRaisesMessage(TemplateSyntaxError, msg):
+ self.engine.render_to_string('template', {'var': [1, 2, 3]})
+
class TranslationBlockTransTagTests(SimpleTestCase):