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):
|
2022-02-03 19:24:19 +00:00
|
|
|
libraries = {"i18n": "django.templatetags.i18n"}
|
2014-11-12 01:32:44 +00:00
|
|
|
|
2022-02-03 19:24:19 +00:00
|
|
|
@setup({"invalidstr01": '{{ var|default:"Foo" }}'})
|
2014-11-12 01:32:44 +00:00
|
|
|
def test_invalidstr01(self):
|
2022-02-03 19:24:19 +00:00
|
|
|
output = self.engine.render_to_string("invalidstr01")
|
2014-12-07 08:43:10 +00:00
|
|
|
if self.engine.string_if_invalid:
|
2022-02-03 19:24:19 +00:00
|
|
|
self.assertEqual(output, "INVALID")
|
2014-11-12 01:32:44 +00:00
|
|
|
else:
|
2022-02-03 19:24:19 +00:00
|
|
|
self.assertEqual(output, "Foo")
|
2014-11-12 01:32:44 +00:00
|
|
|
|
2022-02-03 19:24:19 +00:00
|
|
|
@setup({"invalidstr02": '{{ var|default_if_none:"Foo" }}'})
|
2014-11-12 01:32:44 +00:00
|
|
|
def test_invalidstr02(self):
|
2022-02-03 19:24:19 +00:00
|
|
|
output = self.engine.render_to_string("invalidstr02")
|
2014-12-07 08:43:10 +00:00
|
|
|
if self.engine.string_if_invalid:
|
2022-02-03 19:24:19 +00:00
|
|
|
self.assertEqual(output, "INVALID")
|
2014-11-12 01:32:44 +00:00
|
|
|
else:
|
2022-02-03 19:24:19 +00:00
|
|
|
self.assertEqual(output, "")
|
2014-11-12 01:32:44 +00:00
|
|
|
|
2022-02-03 19:24:19 +00:00
|
|
|
@setup({"invalidstr03": "{% for v in var %}({{ v }}){% endfor %}"})
|
2014-11-12 01:32:44 +00:00
|
|
|
def test_invalidstr03(self):
|
2022-02-03 19:24:19 +00:00
|
|
|
output = self.engine.render_to_string("invalidstr03")
|
|
|
|
self.assertEqual(output, "")
|
2014-11-12 01:32:44 +00:00
|
|
|
|
2022-02-03 19:24:19 +00:00
|
|
|
@setup({"invalidstr04": "{% if var %}Yes{% else %}No{% endif %}"})
|
2014-11-12 01:32:44 +00:00
|
|
|
def test_invalidstr04(self):
|
2022-02-03 19:24:19 +00:00
|
|
|
output = self.engine.render_to_string("invalidstr04")
|
|
|
|
self.assertEqual(output, "No")
|
2014-11-12 01:32:44 +00:00
|
|
|
|
2022-02-03 19:24:19 +00:00
|
|
|
@setup({"invalidstr04_2": '{% if var|default:"Foo" %}Yes{% else %}No{% endif %}'})
|
2014-11-12 01:32:44 +00:00
|
|
|
def test_invalidstr04_2(self):
|
2022-02-03 19:24:19 +00:00
|
|
|
output = self.engine.render_to_string("invalidstr04_2")
|
|
|
|
self.assertEqual(output, "Yes")
|
2014-11-12 01:32:44 +00:00
|
|
|
|
2022-02-03 19:24:19 +00:00
|
|
|
@setup({"invalidstr05": "{{ var }}"})
|
2014-11-12 01:32:44 +00:00
|
|
|
def test_invalidstr05(self):
|
2022-02-03 19:24:19 +00:00
|
|
|
output = self.engine.render_to_string("invalidstr05")
|
2014-12-07 08:43:10 +00:00
|
|
|
if self.engine.string_if_invalid:
|
2022-02-03 19:24:19 +00:00
|
|
|
self.assertEqual(output, "INVALID")
|
2014-11-12 01:32:44 +00:00
|
|
|
else:
|
2022-02-03 19:24:19 +00:00
|
|
|
self.assertEqual(output, "")
|
2014-11-12 01:32:44 +00:00
|
|
|
|
2022-02-03 19:24:19 +00:00
|
|
|
@setup({"invalidstr06": "{{ var.prop }}"})
|
2014-11-12 01:32:44 +00:00
|
|
|
def test_invalidstr06(self):
|
2022-02-03 19:24:19 +00:00
|
|
|
output = self.engine.render_to_string("invalidstr06")
|
2014-12-07 08:43:10 +00:00
|
|
|
if self.engine.string_if_invalid:
|
2022-02-03 19:24:19 +00:00
|
|
|
self.assertEqual(output, "INVALID")
|
2014-11-12 01:32:44 +00:00
|
|
|
else:
|
2022-02-03 19:24:19 +00:00
|
|
|
self.assertEqual(output, "")
|
2014-11-12 01:32:44 +00:00
|
|
|
|
2022-02-03 19:24:19 +00:00
|
|
|
@setup(
|
|
|
|
{
|
|
|
|
"invalidstr07": "{% load i18n %}{% blocktranslate %}{{ var }}{% endblocktranslate %}"
|
|
|
|
}
|
|
|
|
)
|
2014-11-12 01:32:44 +00:00
|
|
|
def test_invalidstr07(self):
|
2022-02-03 19:24:19 +00:00
|
|
|
output = self.engine.render_to_string("invalidstr07")
|
2014-12-07 08:43:10 +00:00
|
|
|
if self.engine.string_if_invalid:
|
2022-02-03 19:24:19 +00:00
|
|
|
self.assertEqual(output, "INVALID")
|
2014-11-12 01:32:44 +00:00
|
|
|
else:
|
2022-02-03 19:24:19 +00:00
|
|
|
self.assertEqual(output, "")
|