summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPreston Timmons <prestontimmons@gmail.com>2015-02-19 14:04:25 -0600
committerTim Graham <timograham@gmail.com>2015-03-02 18:25:28 -0500
commit358850781f8fd3d79aba5b1a9a0b8d28f544bf8a (patch)
treeb35c148c28bbc43f196bc3a28484aed92a903bee /tests
parent8ca35d7c6a639933927f45b439363a1614da56f1 (diff)
Fixed #24372 - Replaced TokenParser usage with traditional parsing.
Diffstat (limited to 'tests')
-rw-r--r--tests/i18n/tests.py4
-rw-r--r--tests/template_tests/syntax_tests/test_i18n.py43
-rw-r--r--tests/template_tests/test_parser.py27
3 files changed, 44 insertions, 30 deletions
diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py
index 9c5b9fddab..ad23861aea 100644
--- a/tests/i18n/tests.py
+++ b/tests/i18n/tests.py
@@ -261,10 +261,6 @@ class TranslationTests(TestCase):
rendered = t.render(Context())
self.assertEqual(rendered, 'Value: Kann')
- # Mis-uses
- self.assertRaises(TemplateSyntaxError, Template, '{% load i18n %}{% trans "May" context as var %}{{ var }}')
- self.assertRaises(TemplateSyntaxError, Template, '{% load i18n %}{% trans "May" as var context %}{{ var }}')
-
# {% blocktrans %} ------------------------------
# Inexisting context...
diff --git a/tests/template_tests/syntax_tests/test_i18n.py b/tests/template_tests/syntax_tests/test_i18n.py
index 11ca002440..da53a8c279 100644
--- a/tests/template_tests/syntax_tests/test_i18n.py
+++ b/tests/template_tests/syntax_tests/test_i18n.py
@@ -1,6 +1,7 @@
# coding: utf-8
from __future__ import unicode_literals
+from django.template import TemplateSyntaxError
from django.test import SimpleTestCase
from django.utils import translation
from django.utils.safestring import mark_safe
@@ -412,3 +413,45 @@ class I18nTagTests(SimpleTestCase):
def test_i18n38_2(self):
output = self.engine.render_to_string('i18n38_2', {'langcodes': ['it', 'no']})
self.assertEqual(output, 'it: Italian/italiano bidi=False; no: Norwegian/norsk bidi=False; ')
+
+ @setup({'template': '{% load i18n %}{% trans %}A}'})
+ def test_syntax_error_no_arguments(self):
+ msg = "'trans' takes at least one argument"
+ with self.assertRaisesMessage(TemplateSyntaxError, msg):
+ self.engine.render_to_string('template')
+
+ @setup({'template': '{% load i18n %}{% trans "Yes" badoption %}'})
+ def test_syntax_error_bad_option(self):
+ msg = "Unknown argument for 'trans' tag: 'badoption'"
+ with self.assertRaisesMessage(TemplateSyntaxError, msg):
+ self.engine.render_to_string('template')
+
+ @setup({'template': '{% load i18n %}{% trans "Yes" as %}'})
+ def test_syntax_error_missing_assignment(self):
+ msg = "No argument provided to the 'trans' tag for the as option."
+ with self.assertRaisesMessage(TemplateSyntaxError, msg):
+ self.engine.render_to_string('template')
+
+ @setup({'template': '{% load i18n %}{% trans "Yes" as var context %}'})
+ def test_syntax_error_missing_context(self):
+ msg = "No argument provided to the 'trans' tag for the context option."
+ with self.assertRaisesMessage(TemplateSyntaxError, msg):
+ self.engine.render_to_string('template')
+
+ @setup({'template': '{% load i18n %}{% trans "Yes" context as var %}'})
+ def test_syntax_error_context_as(self):
+ msg = "Invalid argument 'as' provided to the 'trans' tag for the context option"
+ with self.assertRaisesMessage(TemplateSyntaxError, msg):
+ self.engine.render_to_string('template')
+
+ @setup({'template': '{% load i18n %}{% trans "Yes" context noop %}'})
+ def test_syntax_error_context_noop(self):
+ msg = "Invalid argument 'noop' provided to the 'trans' tag for the context option"
+ with self.assertRaisesMessage(TemplateSyntaxError, msg):
+ self.engine.render_to_string('template')
+
+ @setup({'template': '{% load i18n %}{% trans "Yes" noop noop %}'})
+ def test_syntax_error_duplicate_option(self):
+ msg = "The 'noop' option was specified more than once."
+ with self.assertRaisesMessage(TemplateSyntaxError, msg):
+ self.engine.render_to_string('template')
diff --git a/tests/template_tests/test_parser.py b/tests/template_tests/test_parser.py
index 0c5198fb64..a88dec285e 100644
--- a/tests/template_tests/test_parser.py
+++ b/tests/template_tests/test_parser.py
@@ -7,7 +7,7 @@ from unittest import TestCase
from django.template import Library, Template, TemplateSyntaxError
from django.template.base import (
- TOKEN_BLOCK, FilterExpression, Parser, Token, TokenParser, Variable,
+ TOKEN_BLOCK, FilterExpression, Parser, Token, Variable,
)
from django.test import override_settings
from django.utils import six
@@ -23,31 +23,6 @@ class ParserTests(TestCase):
split = token.split_contents()
self.assertEqual(split, ["sometag", '_("Page not found")', 'value|yesno:_("yes,no")'])
- def test_token_parsing(self):
- # Tests for TokenParser behavior in the face of quoted strings with
- # spaces.
-
- p = TokenParser("tag thevar|filter sometag")
- self.assertEqual(p.tagname, "tag")
- self.assertEqual(p.value(), "thevar|filter")
- self.assertTrue(p.more())
- self.assertEqual(p.tag(), "sometag")
- self.assertFalse(p.more())
-
- p = TokenParser('tag "a value"|filter sometag')
- self.assertEqual(p.tagname, "tag")
- self.assertEqual(p.value(), '"a value"|filter')
- self.assertTrue(p.more())
- self.assertEqual(p.tag(), "sometag")
- self.assertFalse(p.more())
-
- p = TokenParser("tag 'a value'|filter sometag")
- self.assertEqual(p.tagname, "tag")
- self.assertEqual(p.value(), "'a value'|filter")
- self.assertTrue(p.more())
- self.assertEqual(p.tag(), "sometag")
- self.assertFalse(p.more())
-
def test_filter_parsing(self):
c = {"article": {"section": "News"}}
p = Parser("")