summaryrefslogtreecommitdiff
path: root/tests/template_tests/syntax_tests
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
parentc76d87427d70f6c91ab855ed688828aa982720d2 (diff)
downloaddjango-bb79e480e17fd9cabc6d6c873f721c66d1ad7465.tar.gz
Increased test coverage for i18n template tags.
Diffstat (limited to 'tests/template_tests/syntax_tests')
-rw-r--r--tests/template_tests/syntax_tests/i18n/test_blocktrans.py39
-rw-r--r--tests/template_tests/syntax_tests/i18n/test_get_available_languages.py7
-rw-r--r--tests/template_tests/syntax_tests/i18n/test_get_current_language.py14
-rw-r--r--tests/template_tests/syntax_tests/i18n/test_get_current_language_bidi.py14
-rw-r--r--tests/template_tests/syntax_tests/i18n/test_get_language_info.py7
-rw-r--r--tests/template_tests/syntax_tests/i18n/test_get_language_info_list.py7
-rw-r--r--tests/template_tests/syntax_tests/i18n/test_language.py13
7 files changed, 101 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):
diff --git a/tests/template_tests/syntax_tests/i18n/test_get_available_languages.py b/tests/template_tests/syntax_tests/i18n/test_get_available_languages.py
index 0be5a79528..5ac97a4f79 100644
--- a/tests/template_tests/syntax_tests/i18n/test_get_available_languages.py
+++ b/tests/template_tests/syntax_tests/i18n/test_get_available_languages.py
@@ -1,3 +1,4 @@
+from django.template import TemplateSyntaxError
from django.test import SimpleTestCase
from ...utils import setup
@@ -12,3 +13,9 @@ class GetAvailableLanguagesTagTests(SimpleTestCase):
def test_i18n12(self):
output = self.engine.render_to_string('i18n12')
self.assertEqual(output, 'de')
+
+ @setup({'syntax_i18n': '{% load i18n %}{% get_available_languages a langs %}'})
+ def test_no_as_var(self):
+ msg = "'get_available_languages' requires 'as variable' (got ['get_available_languages', 'a', 'langs'])"
+ with self.assertRaisesMessage(TemplateSyntaxError, msg):
+ self.engine.render_to_string('syntax_i18n')
diff --git a/tests/template_tests/syntax_tests/i18n/test_get_current_language.py b/tests/template_tests/syntax_tests/i18n/test_get_current_language.py
new file mode 100644
index 0000000000..f168b74f8e
--- /dev/null
+++ b/tests/template_tests/syntax_tests/i18n/test_get_current_language.py
@@ -0,0 +1,14 @@
+from template_tests.utils import setup
+
+from django.template import TemplateSyntaxError
+from django.test import SimpleTestCase
+
+
+class I18nGetCurrentLanguageTagTests(SimpleTestCase):
+ libraries = {'i18n': 'django.templatetags.i18n'}
+
+ @setup({'template': '{% load i18n %} {% get_current_language %}'})
+ def test_no_as_var(self):
+ msg = "'get_current_language' requires 'as variable' (got ['get_current_language'])"
+ with self.assertRaisesMessage(TemplateSyntaxError, msg):
+ self.engine.render_to_string('template')
diff --git a/tests/template_tests/syntax_tests/i18n/test_get_current_language_bidi.py b/tests/template_tests/syntax_tests/i18n/test_get_current_language_bidi.py
new file mode 100644
index 0000000000..0ac408f78f
--- /dev/null
+++ b/tests/template_tests/syntax_tests/i18n/test_get_current_language_bidi.py
@@ -0,0 +1,14 @@
+from template_tests.utils import setup
+
+from django.template import TemplateSyntaxError
+from django.test import SimpleTestCase
+
+
+class I18nGetCurrentLanguageBidiTagTests(SimpleTestCase):
+ libraries = {'i18n': 'django.templatetags.i18n'}
+
+ @setup({'template': '{% load i18n %} {% get_current_language_bidi %}'})
+ def test_no_as_var(self):
+ msg = "'get_current_language_bidi' requires 'as variable' (got ['get_current_language_bidi'])"
+ with self.assertRaisesMessage(TemplateSyntaxError, msg):
+ self.engine.render_to_string('template')
diff --git a/tests/template_tests/syntax_tests/i18n/test_get_language_info.py b/tests/template_tests/syntax_tests/i18n/test_get_language_info.py
index bc89c65fdd..51e8d2bc79 100644
--- a/tests/template_tests/syntax_tests/i18n/test_get_language_info.py
+++ b/tests/template_tests/syntax_tests/i18n/test_get_language_info.py
@@ -1,3 +1,4 @@
+from django.template import TemplateSyntaxError
from django.test import SimpleTestCase
from django.utils import translation
@@ -34,3 +35,9 @@ class I18nGetLanguageInfoTagTests(SimpleTestCase):
with translation.override('cs'):
output = self.engine.render_to_string('i18n38')
self.assertEqual(output, 'de: German/Deutsch/německy bidi=False')
+
+ @setup({'template': '{% load i18n %}''{% get_language_info %}'})
+ def test_no_for_as(self):
+ msg = "'get_language_info' requires 'for string as variable' (got [])"
+ with self.assertRaisesMessage(TemplateSyntaxError, msg):
+ self.engine.render_to_string('template')
diff --git a/tests/template_tests/syntax_tests/i18n/test_get_language_info_list.py b/tests/template_tests/syntax_tests/i18n/test_get_language_info_list.py
index 4572f41f14..c2c7f8b9cb 100644
--- a/tests/template_tests/syntax_tests/i18n/test_get_language_info_list.py
+++ b/tests/template_tests/syntax_tests/i18n/test_get_language_info_list.py
@@ -1,3 +1,4 @@
+from django.template import TemplateSyntaxError
from django.test import SimpleTestCase
from django.utils import translation
@@ -43,3 +44,9 @@ class GetLanguageInfoListTests(SimpleTestCase):
'it: Italian/italiano/italsky bidi=False; '
'fr: French/français/francouzsky bidi=False; '
)
+
+ @setup({'i18n_syntax': '{% load i18n %} {% get_language_info_list error %}'})
+ def test_no_for_as(self):
+ msg = "'get_language_info_list' requires 'for sequence as variable' (got ['error'])"
+ with self.assertRaisesMessage(TemplateSyntaxError, msg):
+ self.engine.render_to_string('i18n_syntax')
diff --git a/tests/template_tests/syntax_tests/i18n/test_language.py b/tests/template_tests/syntax_tests/i18n/test_language.py
new file mode 100644
index 0000000000..47797befae
--- /dev/null
+++ b/tests/template_tests/syntax_tests/i18n/test_language.py
@@ -0,0 +1,13 @@
+from template_tests.utils import setup
+
+from django.template import TemplateSyntaxError
+from django.test import SimpleTestCase
+
+
+class I18nLanguageTagTests(SimpleTestCase):
+ libraries = {'i18n': 'django.templatetags.i18n'}
+
+ @setup({'i18n_language': '{% load i18n %} {% language %} {% endlanguage %}'})
+ def test_no_arg(self):
+ with self.assertRaisesMessage(TemplateSyntaxError, "'language' takes one argument (language)"):
+ self.engine.render_to_string('i18n_language')