summaryrefslogtreecommitdiff
path: root/tests/template_tests/syntax_tests/test_invalid_string.py
diff options
context:
space:
mode:
authorPreston Timmons <prestontimmons@gmail.com>2014-11-11 19:32:44 -0600
committerTim Graham <timograham@gmail.com>2014-12-02 19:18:35 -0500
commitb872134bfc14f6322bd1e4b0a08bf5bfd2c43a52 (patch)
treef82fc6be418adeb1e7ff36728f82008770066999 /tests/template_tests/syntax_tests/test_invalid_string.py
parent4a4ad27712b44cebada1bdaebd082cf82df74610 (diff)
Fixed #23768 -- Rewrote template tests as unit tests.
Diffstat (limited to 'tests/template_tests/syntax_tests/test_invalid_string.py')
-rw-r--r--tests/template_tests/syntax_tests/test_invalid_string.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/template_tests/syntax_tests/test_invalid_string.py b/tests/template_tests/syntax_tests/test_invalid_string.py
new file mode 100644
index 0000000000..5aadbdbcfa
--- /dev/null
+++ b/tests/template_tests/syntax_tests/test_invalid_string.py
@@ -0,0 +1,62 @@
+from django.conf import settings
+from django.test import TestCase
+
+from .utils import render, setup
+
+
+class InvalidStringTests(TestCase):
+
+ @setup({'invalidstr01': '{{ var|default:"Foo" }}'})
+ def test_invalidstr01(self):
+ output = render('invalidstr01')
+ if settings.TEMPLATE_STRING_IF_INVALID:
+ self.assertEqual(output, 'INVALID')
+ else:
+ self.assertEqual(output, 'Foo')
+
+ @setup({'invalidstr02': '{{ var|default_if_none:"Foo" }}'})
+ def test_invalidstr02(self):
+ output = render('invalidstr02')
+ if settings.TEMPLATE_STRING_IF_INVALID:
+ self.assertEqual(output, 'INVALID')
+ else:
+ self.assertEqual(output, '')
+
+ @setup({'invalidstr03': '{% for v in var %}({{ v }}){% endfor %}'})
+ def test_invalidstr03(self):
+ output = render('invalidstr03')
+ self.assertEqual(output, '')
+
+ @setup({'invalidstr04': '{% if var %}Yes{% else %}No{% endif %}'})
+ def test_invalidstr04(self):
+ output = render('invalidstr04')
+ self.assertEqual(output, 'No')
+
+ @setup({'invalidstr04_2': '{% if var|default:"Foo" %}Yes{% else %}No{% endif %}'})
+ def test_invalidstr04_2(self):
+ output = render('invalidstr04_2')
+ self.assertEqual(output, 'Yes')
+
+ @setup({'invalidstr05': '{{ var }}'})
+ def test_invalidstr05(self):
+ output = render('invalidstr05')
+ if settings.TEMPLATE_STRING_IF_INVALID:
+ self.assertEqual(output, 'INVALID')
+ else:
+ self.assertEqual(output, '')
+
+ @setup({'invalidstr06': '{{ var.prop }}'})
+ def test_invalidstr06(self):
+ output = render('invalidstr06')
+ if settings.TEMPLATE_STRING_IF_INVALID:
+ self.assertEqual(output, 'INVALID')
+ else:
+ self.assertEqual(output, '')
+
+ @setup({'invalidstr07': '{% load i18n %}{% blocktrans %}{{ var }}{% endblocktrans %}'})
+ def test_invalidstr07(self):
+ output = render('invalidstr07')
+ if settings.TEMPLATE_STRING_IF_INVALID:
+ self.assertEqual(output, 'INVALID')
+ else:
+ self.assertEqual(output, '')