mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #23768 -- Rewrote template tests as unit tests.
This commit is contained in:
parent
4a4ad27712
commit
b872134bfc
41 changed files with 4855 additions and 1369 deletions
62
tests/template_tests/syntax_tests/test_invalid_string.py
Normal file
62
tests/template_tests/syntax_tests/test_invalid_string.py
Normal file
|
@ -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, '')
|
Loading…
Add table
Add a link
Reference in a new issue