2014-12-03 20:36:17 +00:00
|
|
|
from django.test import SimpleTestCase
|
2014-11-12 01:32:44 +00:00
|
|
|
|
2014-12-07 08:43:10 +00:00
|
|
|
from ..utils import setup
|
2014-11-12 01:32:44 +00:00
|
|
|
|
|
|
|
|
2014-12-03 20:36:17 +00:00
|
|
|
class InvalidStringTests(SimpleTestCase):
|
2015-05-08 20:10:36 +00:00
|
|
|
libraries = {"i18n": "django.templatetags.i18n"}
|
2014-11-12 01:32:44 +00:00
|
|
|
|
|
|
|
@setup({"invalidstr01": '{{ var|default:"Foo" }}'})
|
|
|
|
def test_invalidstr01(self):
|
2014-12-07 08:43:10 +00:00
|
|
|
output = self.engine.render_to_string("invalidstr01")
|
|
|
|
if self.engine.string_if_invalid:
|
2014-11-12 01:32:44 +00:00
|
|
|
self.assertEqual(output, "INVALID")
|
|
|
|
else:
|
|
|
|
self.assertEqual(output, "Foo")
|
|
|
|
|
|
|
|
@setup({"invalidstr02": '{{ var|default_if_none:"Foo" }}'})
|
|
|
|
def test_invalidstr02(self):
|
2014-12-07 08:43:10 +00:00
|
|
|
output = self.engine.render_to_string("invalidstr02")
|
|
|
|
if self.engine.string_if_invalid:
|
2014-11-12 01:32:44 +00:00
|
|
|
self.assertEqual(output, "INVALID")
|
|
|
|
else:
|
|
|
|
self.assertEqual(output, "")
|
|
|
|
|
|
|
|
@setup({"invalidstr03": "{% for v in var %}({{ v }}){% endfor %}"})
|
|
|
|
def test_invalidstr03(self):
|
2014-12-07 08:43:10 +00:00
|
|
|
output = self.engine.render_to_string("invalidstr03")
|
2014-11-12 01:32:44 +00:00
|
|
|
self.assertEqual(output, "")
|
|
|
|
|
|
|
|
@setup({"invalidstr04": "{% if var %}Yes{% else %}No{% endif %}"})
|
|
|
|
def test_invalidstr04(self):
|
2014-12-07 08:43:10 +00:00
|
|
|
output = self.engine.render_to_string("invalidstr04")
|
2014-11-12 01:32:44 +00:00
|
|
|
self.assertEqual(output, "No")
|
|
|
|
|
|
|
|
@setup({"invalidstr04_2": '{% if var|default:"Foo" %}Yes{% else %}No{% endif %}'})
|
|
|
|
def test_invalidstr04_2(self):
|
2014-12-07 08:43:10 +00:00
|
|
|
output = self.engine.render_to_string("invalidstr04_2")
|
2014-11-12 01:32:44 +00:00
|
|
|
self.assertEqual(output, "Yes")
|
|
|
|
|
|
|
|
@setup({"invalidstr05": "{{ var }}"})
|
|
|
|
def test_invalidstr05(self):
|
2014-12-07 08:43:10 +00:00
|
|
|
output = self.engine.render_to_string("invalidstr05")
|
|
|
|
if self.engine.string_if_invalid:
|
2014-11-12 01:32:44 +00:00
|
|
|
self.assertEqual(output, "INVALID")
|
|
|
|
else:
|
|
|
|
self.assertEqual(output, "")
|
|
|
|
|
|
|
|
@setup({"invalidstr06": "{{ var.prop }}"})
|
|
|
|
def test_invalidstr06(self):
|
2014-12-07 08:43:10 +00:00
|
|
|
output = self.engine.render_to_string("invalidstr06")
|
|
|
|
if self.engine.string_if_invalid:
|
2014-11-12 01:32:44 +00:00
|
|
|
self.assertEqual(output, "INVALID")
|
|
|
|
else:
|
|
|
|
self.assertEqual(output, "")
|
|
|
|
|
2019-09-23 15:31:21 +00:00
|
|
|
@setup(
|
2022-02-03 19:24:19 +00:00
|
|
|
{
|
2019-09-23 15:31:21 +00:00
|
|
|
"invalidstr07": (
|
|
|
|
"{% load i18n %}{% blocktranslate %}{{ var }}{% endblocktranslate %}"
|
2022-02-04 07:08:27 +00:00
|
|
|
)
|
2022-02-03 19:24:19 +00:00
|
|
|
}
|
2019-09-23 15:31:21 +00:00
|
|
|
)
|
2014-11-12 01:32:44 +00:00
|
|
|
def test_invalidstr07(self):
|
2014-12-07 08:43:10 +00:00
|
|
|
output = self.engine.render_to_string("invalidstr07")
|
|
|
|
if self.engine.string_if_invalid:
|
2014-11-12 01:32:44 +00:00
|
|
|
self.assertEqual(output, "INVALID")
|
|
|
|
else:
|
|
|
|
self.assertEqual(output, "")
|