Isolated template tests from Django settings.
This commit is contained in:
parent
b34b8a12b7
commit
92a2d049a2
|
@ -3,7 +3,7 @@ from datetime import date, timedelta
|
|||
from django.template.defaultfilters import add
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class AddTests(SimpleTestCase):
|
||||
|
@ -13,37 +13,37 @@ class AddTests(SimpleTestCase):
|
|||
|
||||
@setup({'add01': '{{ i|add:"5" }}'})
|
||||
def test_add01(self):
|
||||
output = render('add01', {'i': 2000})
|
||||
output = self.engine.render_to_string('add01', {'i': 2000})
|
||||
self.assertEqual(output, '2005')
|
||||
|
||||
@setup({'add02': '{{ i|add:"napis" }}'})
|
||||
def test_add02(self):
|
||||
output = render('add02', {'i': 2000})
|
||||
output = self.engine.render_to_string('add02', {'i': 2000})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'add03': '{{ i|add:16 }}'})
|
||||
def test_add03(self):
|
||||
output = render('add03', {'i': 'not_an_int'})
|
||||
output = self.engine.render_to_string('add03', {'i': 'not_an_int'})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'add04': '{{ i|add:"16" }}'})
|
||||
def test_add04(self):
|
||||
output = render('add04', {'i': 'not_an_int'})
|
||||
output = self.engine.render_to_string('add04', {'i': 'not_an_int'})
|
||||
self.assertEqual(output, 'not_an_int16')
|
||||
|
||||
@setup({'add05': '{{ l1|add:l2 }}'})
|
||||
def test_add05(self):
|
||||
output = render('add05', {'l1': [1, 2], 'l2': [3, 4]})
|
||||
output = self.engine.render_to_string('add05', {'l1': [1, 2], 'l2': [3, 4]})
|
||||
self.assertEqual(output, '[1, 2, 3, 4]')
|
||||
|
||||
@setup({'add06': '{{ t1|add:t2 }}'})
|
||||
def test_add06(self):
|
||||
output = render('add06', {'t1': (3, 4), 't2': (1, 2)})
|
||||
output = self.engine.render_to_string('add06', {'t1': (3, 4), 't2': (1, 2)})
|
||||
self.assertEqual(output, '(3, 4, 1, 2)')
|
||||
|
||||
@setup({'add07': '{{ d|add:t }}'})
|
||||
def test_add07(self):
|
||||
output = render('add07', {'d': date(2000, 1, 1), 't': timedelta(10)})
|
||||
output = self.engine.render_to_string('add07', {'d': date(2000, 1, 1), 't': timedelta(10)})
|
||||
self.assertEqual(output, 'Jan. 11, 2000')
|
||||
|
||||
|
||||
|
|
|
@ -2,19 +2,19 @@ from django.template.defaultfilters import addslashes
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class AddslashesTests(SimpleTestCase):
|
||||
|
||||
@setup({'addslashes01': '{% autoescape off %}{{ a|addslashes }} {{ b|addslashes }}{% endautoescape %}'})
|
||||
def test_addslashes01(self):
|
||||
output = render('addslashes01', {"a": "<a>'", "b": mark_safe("<a>'")})
|
||||
output = self.engine.render_to_string('addslashes01', {"a": "<a>'", "b": mark_safe("<a>'")})
|
||||
self.assertEqual(output, r"<a>\' <a>\'")
|
||||
|
||||
@setup({'addslashes02': '{{ a|addslashes }} {{ b|addslashes }}'})
|
||||
def test_addslashes02(self):
|
||||
output = render('addslashes02', {"a": "<a>'", "b": mark_safe("<a>'")})
|
||||
output = self.engine.render_to_string('addslashes02', {"a": "<a>'", "b": mark_safe("<a>'")})
|
||||
self.assertEqual(output, r"<a>\' <a>\'")
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup, SafeClass, UnsafeClass
|
||||
from ..utils import setup, SafeClass, UnsafeClass
|
||||
|
||||
|
||||
class AutoescapeStringfilterTests(SimpleTestCase):
|
||||
|
@ -10,20 +10,20 @@ class AutoescapeStringfilterTests(SimpleTestCase):
|
|||
|
||||
@setup({'autoescape-stringfilter01': '{{ unsafe|capfirst }}'})
|
||||
def test_autoescape_stringfilter01(self):
|
||||
output = render('autoescape-stringfilter01', {'unsafe': UnsafeClass()})
|
||||
output = self.engine.render_to_string('autoescape-stringfilter01', {'unsafe': UnsafeClass()})
|
||||
self.assertEqual(output, 'You & me')
|
||||
|
||||
@setup({'autoescape-stringfilter02': '{% autoescape off %}{{ unsafe|capfirst }}{% endautoescape %}'})
|
||||
def test_autoescape_stringfilter02(self):
|
||||
output = render('autoescape-stringfilter02', {'unsafe': UnsafeClass()})
|
||||
output = self.engine.render_to_string('autoescape-stringfilter02', {'unsafe': UnsafeClass()})
|
||||
self.assertEqual(output, 'You & me')
|
||||
|
||||
@setup({'autoescape-stringfilter03': '{{ safe|capfirst }}'})
|
||||
def test_autoescape_stringfilter03(self):
|
||||
output = render('autoescape-stringfilter03', {'safe': SafeClass()})
|
||||
output = self.engine.render_to_string('autoescape-stringfilter03', {'safe': SafeClass()})
|
||||
self.assertEqual(output, 'You > me')
|
||||
|
||||
@setup({'autoescape-stringfilter04': '{% autoescape off %}{{ safe|capfirst }}{% endautoescape %}'})
|
||||
def test_autoescape_stringfilter04(self):
|
||||
output = render('autoescape-stringfilter04', {'safe': SafeClass()})
|
||||
output = self.engine.render_to_string('autoescape-stringfilter04', {'safe': SafeClass()})
|
||||
self.assertEqual(output, 'You > me')
|
||||
|
|
|
@ -2,19 +2,19 @@ from django.template.defaultfilters import capfirst
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class CapfirstTests(SimpleTestCase):
|
||||
|
||||
@setup({'capfirst01': '{% autoescape off %}{{ a|capfirst }} {{ b|capfirst }}{% endautoescape %}'})
|
||||
def test_capfirst01(self):
|
||||
output = render('capfirst01', {'a': 'fred>', 'b': mark_safe('fred>')})
|
||||
output = self.engine.render_to_string('capfirst01', {'a': 'fred>', 'b': mark_safe('fred>')})
|
||||
self.assertEqual(output, 'Fred> Fred>')
|
||||
|
||||
@setup({'capfirst02': '{{ a|capfirst }} {{ b|capfirst }}'})
|
||||
def test_capfirst02(self):
|
||||
output = render('capfirst02', {'a': 'fred>', 'b': mark_safe('fred>')})
|
||||
output = self.engine.render_to_string('capfirst02', {'a': 'fred>', 'b': mark_safe('fred>')})
|
||||
self.assertEqual(output, 'Fred> Fred>')
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ from django.template.defaultfilters import center
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class CenterTests(SimpleTestCase):
|
||||
|
@ -10,12 +10,12 @@ class CenterTests(SimpleTestCase):
|
|||
@setup({'center01':
|
||||
'{% autoescape off %}.{{ a|center:"5" }}. .{{ b|center:"5" }}.{% endautoescape %}'})
|
||||
def test_center01(self):
|
||||
output = render('center01', {"a": "a&b", "b": mark_safe("a&b")})
|
||||
output = self.engine.render_to_string('center01', {"a": "a&b", "b": mark_safe("a&b")})
|
||||
self.assertEqual(output, ". a&b . . a&b .")
|
||||
|
||||
@setup({'center02': '.{{ a|center:"5" }}. .{{ b|center:"5" }}.'})
|
||||
def test_center02(self):
|
||||
output = render('center02', {"a": "a&b", "b": mark_safe("a&b")})
|
||||
output = self.engine.render_to_string('center02', {"a": "a&b", "b": mark_safe("a&b")})
|
||||
self.assertEqual(output, ". a&b . . a&b .")
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class ChainingTests(SimpleTestCase):
|
||||
|
@ -11,76 +11,76 @@ class ChainingTests(SimpleTestCase):
|
|||
|
||||
@setup({'chaining01': '{{ a|capfirst|center:"7" }}.{{ b|capfirst|center:"7" }}'})
|
||||
def test_chaining01(self):
|
||||
output = render('chaining01', {'a': 'a < b', 'b': mark_safe('a < b')})
|
||||
output = self.engine.render_to_string('chaining01', {'a': 'a < b', 'b': mark_safe('a < b')})
|
||||
self.assertEqual(output, ' A < b . A < b ')
|
||||
|
||||
@setup({'chaining02':
|
||||
'{% autoescape off %}{{ a|capfirst|center:"7" }}.{{ b|capfirst|center:"7" }}{% endautoescape %}'})
|
||||
def test_chaining02(self):
|
||||
output = render('chaining02', {'a': 'a < b', 'b': mark_safe('a < b')})
|
||||
output = self.engine.render_to_string('chaining02', {'a': 'a < b', 'b': mark_safe('a < b')})
|
||||
self.assertEqual(output, ' A < b . A < b ')
|
||||
|
||||
# Using a filter that forces a string back to unsafe:
|
||||
@setup({'chaining03': '{{ a|cut:"b"|capfirst }}.{{ b|cut:"b"|capfirst }}'})
|
||||
def test_chaining03(self):
|
||||
output = render('chaining03', {'a': 'a < b', 'b': mark_safe('a < b')})
|
||||
output = self.engine.render_to_string('chaining03', {'a': 'a < b', 'b': mark_safe('a < b')})
|
||||
self.assertEqual(output, 'A < .A < ')
|
||||
|
||||
@setup({'chaining04':
|
||||
'{% autoescape off %}{{ a|cut:"b"|capfirst }}.{{ b|cut:"b"|capfirst }}{% endautoescape %}'})
|
||||
def test_chaining04(self):
|
||||
output = render('chaining04', {'a': 'a < b', 'b': mark_safe('a < b')})
|
||||
output = self.engine.render_to_string('chaining04', {'a': 'a < b', 'b': mark_safe('a < b')})
|
||||
self.assertEqual(output, 'A < .A < ')
|
||||
|
||||
# Using a filter that forces safeness does not lead to double-escaping
|
||||
@setup({'chaining05': '{{ a|escape|capfirst }}'})
|
||||
def test_chaining05(self):
|
||||
output = render('chaining05', {'a': 'a < b'})
|
||||
output = self.engine.render_to_string('chaining05', {'a': 'a < b'})
|
||||
self.assertEqual(output, 'A < b')
|
||||
|
||||
@setup({'chaining06': '{% autoescape off %}{{ a|escape|capfirst }}{% endautoescape %}'})
|
||||
def test_chaining06(self):
|
||||
output = render('chaining06', {'a': 'a < b'})
|
||||
output = self.engine.render_to_string('chaining06', {'a': 'a < b'})
|
||||
self.assertEqual(output, 'A < b')
|
||||
|
||||
# Force to safe, then back (also showing why using force_escape too
|
||||
# early in a chain can lead to unexpected results).
|
||||
@setup({'chaining07': '{{ a|force_escape|cut:";" }}'})
|
||||
def test_chaining07(self):
|
||||
output = render('chaining07', {'a': 'a < b'})
|
||||
output = self.engine.render_to_string('chaining07', {'a': 'a < b'})
|
||||
self.assertEqual(output, 'a &lt b')
|
||||
|
||||
@setup({'chaining08': '{% autoescape off %}{{ a|force_escape|cut:";" }}{% endautoescape %}'})
|
||||
def test_chaining08(self):
|
||||
output = render('chaining08', {'a': 'a < b'})
|
||||
output = self.engine.render_to_string('chaining08', {'a': 'a < b'})
|
||||
self.assertEqual(output, 'a < b')
|
||||
|
||||
@setup({'chaining09': '{{ a|cut:";"|force_escape }}'})
|
||||
def test_chaining09(self):
|
||||
output = render('chaining09', {'a': 'a < b'})
|
||||
output = self.engine.render_to_string('chaining09', {'a': 'a < b'})
|
||||
self.assertEqual(output, 'a < b')
|
||||
|
||||
@setup({'chaining10': '{% autoescape off %}{{ a|cut:";"|force_escape }}{% endautoescape %}'})
|
||||
def test_chaining10(self):
|
||||
output = render('chaining10', {'a': 'a < b'})
|
||||
output = self.engine.render_to_string('chaining10', {'a': 'a < b'})
|
||||
self.assertEqual(output, 'a < b')
|
||||
|
||||
@setup({'chaining11': '{{ a|cut:"b"|safe }}'})
|
||||
def test_chaining11(self):
|
||||
output = render('chaining11', {'a': 'a < b'})
|
||||
output = self.engine.render_to_string('chaining11', {'a': 'a < b'})
|
||||
self.assertEqual(output, 'a < ')
|
||||
|
||||
@setup({'chaining12': '{% autoescape off %}{{ a|cut:"b"|safe }}{% endautoescape %}'})
|
||||
def test_chaining12(self):
|
||||
output = render('chaining12', {'a': 'a < b'})
|
||||
output = self.engine.render_to_string('chaining12', {'a': 'a < b'})
|
||||
self.assertEqual(output, 'a < ')
|
||||
|
||||
@setup({'chaining13': '{{ a|safe|force_escape }}'})
|
||||
def test_chaining13(self):
|
||||
output = render('chaining13', {"a": "a < b"})
|
||||
output = self.engine.render_to_string('chaining13', {"a": "a < b"})
|
||||
self.assertEqual(output, 'a < b')
|
||||
|
||||
@setup({'chaining14': '{% autoescape off %}{{ a|safe|force_escape }}{% endautoescape %}'})
|
||||
def test_chaining14(self):
|
||||
output = render('chaining14', {"a": "a < b"})
|
||||
output = self.engine.render_to_string('chaining14', {"a": "a < b"})
|
||||
self.assertEqual(output, 'a < b')
|
||||
|
|
|
@ -2,41 +2,41 @@ from django.template.defaultfilters import cut
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class CutTests(SimpleTestCase):
|
||||
|
||||
@setup({'cut01': '{% autoescape off %}{{ a|cut:"x" }} {{ b|cut:"x" }}{% endautoescape %}'})
|
||||
def test_cut01(self):
|
||||
output = render('cut01', {"a": "x&y", "b": mark_safe("x&y")})
|
||||
output = self.engine.render_to_string('cut01', {"a": "x&y", "b": mark_safe("x&y")})
|
||||
self.assertEqual(output, "&y &y")
|
||||
|
||||
@setup({'cut02': '{{ a|cut:"x" }} {{ b|cut:"x" }}'})
|
||||
def test_cut02(self):
|
||||
output = render('cut02', {"a": "x&y", "b": mark_safe("x&y")})
|
||||
output = self.engine.render_to_string('cut02', {"a": "x&y", "b": mark_safe("x&y")})
|
||||
self.assertEqual(output, "&y &y")
|
||||
|
||||
@setup({'cut03': '{% autoescape off %}{{ a|cut:"&" }} {{ b|cut:"&" }}{% endautoescape %}'})
|
||||
def test_cut03(self):
|
||||
output = render('cut03', {"a": "x&y", "b": mark_safe("x&y")})
|
||||
output = self.engine.render_to_string('cut03', {"a": "x&y", "b": mark_safe("x&y")})
|
||||
self.assertEqual(output, "xy xamp;y")
|
||||
|
||||
@setup({'cut04': '{{ a|cut:"&" }} {{ b|cut:"&" }}'})
|
||||
def test_cut04(self):
|
||||
output = render('cut04', {"a": "x&y", "b": mark_safe("x&y")})
|
||||
output = self.engine.render_to_string('cut04', {"a": "x&y", "b": mark_safe("x&y")})
|
||||
self.assertEqual(output, "xy xamp;y")
|
||||
|
||||
# Passing ';' to cut can break existing HTML entities, so those strings
|
||||
# are auto-escaped.
|
||||
@setup({'cut05': '{% autoescape off %}{{ a|cut:";" }} {{ b|cut:";" }}{% endautoescape %}'})
|
||||
def test_cut05(self):
|
||||
output = render('cut05', {"a": "x&y", "b": mark_safe("x&y")})
|
||||
output = self.engine.render_to_string('cut05', {"a": "x&y", "b": mark_safe("x&y")})
|
||||
self.assertEqual(output, "x&y x&y")
|
||||
|
||||
@setup({'cut06': '{{ a|cut:";" }} {{ b|cut:";" }}'})
|
||||
def test_cut06(self):
|
||||
output = render('cut06', {"a": "x&y", "b": mark_safe("x&y")})
|
||||
output = self.engine.render_to_string('cut06', {"a": "x&y", "b": mark_safe("x&y")})
|
||||
self.assertEqual(output, "x&y x&ampy")
|
||||
|
||||
|
||||
|
|
|
@ -5,19 +5,19 @@ from django.test import SimpleTestCase
|
|||
from django.utils import timezone
|
||||
|
||||
from .timezone_utils import TimezoneTestCase
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class DateTests(TimezoneTestCase):
|
||||
|
||||
@setup({'date01': '{{ d|date:"m" }}'})
|
||||
def test_date01(self):
|
||||
output = render('date01', {'d': datetime(2008, 1, 1)})
|
||||
output = self.engine.render_to_string('date01', {'d': datetime(2008, 1, 1)})
|
||||
self.assertEqual(output, '01')
|
||||
|
||||
@setup({'date02': '{{ d|date }}'})
|
||||
def test_date02(self):
|
||||
output = render('date02', {'d': datetime(2008, 1, 1)})
|
||||
output = self.engine.render_to_string('date02', {'d': datetime(2008, 1, 1)})
|
||||
self.assertEqual(output, 'Jan. 1, 2008')
|
||||
|
||||
@setup({'date03': '{{ d|date:"m" }}'})
|
||||
|
@ -25,40 +25,40 @@ class DateTests(TimezoneTestCase):
|
|||
"""
|
||||
#9520: Make sure |date doesn't blow up on non-dates
|
||||
"""
|
||||
output = render('date03', {'d': 'fail_string'})
|
||||
output = self.engine.render_to_string('date03', {'d': 'fail_string'})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
# ISO date formats
|
||||
@setup({'date04': '{{ d|date:"o" }}'})
|
||||
def test_date04(self):
|
||||
output = render('date04', {'d': datetime(2008, 12, 29)})
|
||||
output = self.engine.render_to_string('date04', {'d': datetime(2008, 12, 29)})
|
||||
self.assertEqual(output, '2009')
|
||||
|
||||
@setup({'date05': '{{ d|date:"o" }}'})
|
||||
def test_date05(self):
|
||||
output = render('date05', {'d': datetime(2010, 1, 3)})
|
||||
output = self.engine.render_to_string('date05', {'d': datetime(2010, 1, 3)})
|
||||
self.assertEqual(output, '2009')
|
||||
|
||||
# Timezone name
|
||||
@setup({'date06': '{{ d|date:"e" }}'})
|
||||
def test_date06(self):
|
||||
output = render('date06', {'d': datetime(2009, 3, 12, tzinfo=timezone.get_fixed_timezone(30))})
|
||||
output = self.engine.render_to_string('date06', {'d': datetime(2009, 3, 12, tzinfo=timezone.get_fixed_timezone(30))})
|
||||
self.assertEqual(output, '+0030')
|
||||
|
||||
@setup({'date07': '{{ d|date:"e" }}'})
|
||||
def test_date07(self):
|
||||
output = render('date07', {'d': datetime(2009, 3, 12)})
|
||||
output = self.engine.render_to_string('date07', {'d': datetime(2009, 3, 12)})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
# #19370: Make sure |date doesn't blow up on a midnight time object
|
||||
@setup({'date08': '{{ t|date:"H:i" }}'})
|
||||
def test_date08(self):
|
||||
output = render('date08', {'t': time(0, 1)})
|
||||
output = self.engine.render_to_string('date08', {'t': time(0, 1)})
|
||||
self.assertEqual(output, '00:01')
|
||||
|
||||
@setup({'date09': '{{ t|date:"H:i" }}'})
|
||||
def test_date09(self):
|
||||
output = render('date09', {'t': time(0, 0)})
|
||||
output = self.engine.render_to_string('date09', {'t': time(0, 0)})
|
||||
self.assertEqual(output, '00:00')
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ from django.template.defaultfilters import default
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class DefaultTests(SimpleTestCase):
|
||||
|
@ -16,22 +16,22 @@ class DefaultTests(SimpleTestCase):
|
|||
|
||||
@setup({'default01': '{{ a|default:"x<" }}'})
|
||||
def test_default01(self):
|
||||
output = render('default01', {"a": ""})
|
||||
output = self.engine.render_to_string('default01', {"a": ""})
|
||||
self.assertEqual(output, "x<")
|
||||
|
||||
@setup({'default02': '{% autoescape off %}{{ a|default:"x<" }}{% endautoescape %}'})
|
||||
def test_default02(self):
|
||||
output = render('default02', {"a": ""})
|
||||
output = self.engine.render_to_string('default02', {"a": ""})
|
||||
self.assertEqual(output, "x<")
|
||||
|
||||
@setup({'default03': '{{ a|default:"x<" }}'})
|
||||
def test_default03(self):
|
||||
output = render('default03', {"a": mark_safe("x>")})
|
||||
output = self.engine.render_to_string('default03', {"a": mark_safe("x>")})
|
||||
self.assertEqual(output, "x>")
|
||||
|
||||
@setup({'default04': '{% autoescape off %}{{ a|default:"x<" }}{% endautoescape %}'})
|
||||
def test_default04(self):
|
||||
output = render('default04', {"a": mark_safe("x>")})
|
||||
output = self.engine.render_to_string('default04', {"a": mark_safe("x>")})
|
||||
self.assertEqual(output, "x>")
|
||||
|
||||
|
||||
|
@ -39,12 +39,12 @@ class DefaultIfNoneTests(SimpleTestCase):
|
|||
|
||||
@setup({'default_if_none01': '{{ a|default:"x<" }}'})
|
||||
def test_default_if_none01(self):
|
||||
output = render('default_if_none01', {"a": None})
|
||||
output = self.engine.render_to_string('default_if_none01', {"a": None})
|
||||
self.assertEqual(output, "x<")
|
||||
|
||||
@setup({'default_if_none02': '{% autoescape off %}{{ a|default:"x<" }}{% endautoescape %}'})
|
||||
def test_default_if_none02(self):
|
||||
output = render('default_if_none02', {"a": None})
|
||||
output = self.engine.render_to_string('default_if_none02', {"a": None})
|
||||
self.assertEqual(output, "x<")
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ from django.template.defaultfilters import escape
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class EscapeTests(SimpleTestCase):
|
||||
|
@ -13,24 +13,24 @@ class EscapeTests(SimpleTestCase):
|
|||
|
||||
@setup({'escape01': '{{ a|escape }} {{ b|escape }}'})
|
||||
def test_escape01(self):
|
||||
output = render('escape01', {"a": "x&y", "b": mark_safe("x&y")})
|
||||
output = self.engine.render_to_string('escape01', {"a": "x&y", "b": mark_safe("x&y")})
|
||||
self.assertEqual(output, "x&y x&y")
|
||||
|
||||
@setup({'escape02': '{% autoescape off %}{{ a|escape }} {{ b|escape }}{% endautoescape %}'})
|
||||
def test_escape02(self):
|
||||
output = render('escape02', {"a": "x&y", "b": mark_safe("x&y")})
|
||||
output = self.engine.render_to_string('escape02', {"a": "x&y", "b": mark_safe("x&y")})
|
||||
self.assertEqual(output, "x&y x&y")
|
||||
|
||||
# It is only applied once, regardless of the number of times it
|
||||
# appears in a chain.
|
||||
@setup({'escape03': '{% autoescape off %}{{ a|escape|escape }}{% endautoescape %}'})
|
||||
def test_escape03(self):
|
||||
output = render('escape03', {"a": "x&y"})
|
||||
output = self.engine.render_to_string('escape03', {"a": "x&y"})
|
||||
self.assertEqual(output, "x&y")
|
||||
|
||||
@setup({'escape04': '{{ a|escape|escape }}'})
|
||||
def test_escape04(self):
|
||||
output = render('escape04', {"a": "x&y"})
|
||||
output = self.engine.render_to_string('escape04', {"a": "x&y"})
|
||||
self.assertEqual(output, "x&y")
|
||||
|
||||
|
||||
|
|
|
@ -3,21 +3,21 @@ from __future__ import unicode_literals
|
|||
from django.template.defaultfilters import escapejs_filter
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class EscapejsTests(SimpleTestCase):
|
||||
|
||||
@setup({'escapejs01': '{{ a|escapejs }}'})
|
||||
def test_escapejs01(self):
|
||||
output = render('escapejs01', {'a': 'testing\r\njavascript \'string" <b>escaping</b>'})
|
||||
output = self.engine.render_to_string('escapejs01', {'a': 'testing\r\njavascript \'string" <b>escaping</b>'})
|
||||
self.assertEqual(output, 'testing\\u000D\\u000Ajavascript '
|
||||
'\\u0027string\\u0022 \\u003Cb\\u003E'
|
||||
'escaping\\u003C/b\\u003E')
|
||||
|
||||
@setup({'escapejs02': '{% autoescape off %}{{ a|escapejs }}{% endautoescape %}'})
|
||||
def test_escapejs02(self):
|
||||
output = render('escapejs02', {'a': 'testing\r\njavascript \'string" <b>escaping</b>'})
|
||||
output = self.engine.render_to_string('escapejs02', {'a': 'testing\r\njavascript \'string" <b>escaping</b>'})
|
||||
self.assertEqual(output, 'testing\\u000D\\u000Ajavascript '
|
||||
'\\u0027string\\u0022 \\u003Cb\\u003E'
|
||||
'escaping\\u003C/b\\u003E')
|
||||
|
|
|
@ -2,19 +2,19 @@ from django.template.defaultfilters import first
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class FirstTests(SimpleTestCase):
|
||||
|
||||
@setup({'first01': '{{ a|first }} {{ b|first }}'})
|
||||
def test_first01(self):
|
||||
output = render('first01', {"a": ["a&b", "x"], "b": [mark_safe("a&b"), "x"]})
|
||||
output = self.engine.render_to_string('first01', {"a": ["a&b", "x"], "b": [mark_safe("a&b"), "x"]})
|
||||
self.assertEqual(output, "a&b a&b")
|
||||
|
||||
@setup({'first02': '{% autoescape off %}{{ a|first }} {{ b|first }}{% endautoescape %}'})
|
||||
def test_first02(self):
|
||||
output = render('first02', {"a": ["a&b", "x"], "b": [mark_safe("a&b"), "x"]})
|
||||
output = self.engine.render_to_string('first02', {"a": ["a&b", "x"], "b": [mark_safe("a&b"), "x"]})
|
||||
self.assertEqual(output, "a&b a&b")
|
||||
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ from django.test import SimpleTestCase
|
|||
from django.utils import six
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class FloatformatTests(SimpleTestCase):
|
||||
|
@ -17,12 +17,12 @@ class FloatformatTests(SimpleTestCase):
|
|||
@setup({'floatformat01':
|
||||
'{% autoescape off %}{{ a|floatformat }} {{ b|floatformat }}{% endautoescape %}'})
|
||||
def test_floatformat01(self):
|
||||
output = render('floatformat01', {"a": "1.42", "b": mark_safe("1.42")})
|
||||
output = self.engine.render_to_string('floatformat01', {"a": "1.42", "b": mark_safe("1.42")})
|
||||
self.assertEqual(output, "1.4 1.4")
|
||||
|
||||
@setup({'floatformat02': '{{ a|floatformat }} {{ b|floatformat }}'})
|
||||
def test_floatformat02(self):
|
||||
output = render('floatformat02', {"a": "1.42", "b": mark_safe("1.42")})
|
||||
output = self.engine.render_to_string('floatformat02', {"a": "1.42", "b": mark_safe("1.42")})
|
||||
self.assertEqual(output, "1.4 1.4")
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ from django.template.defaultfilters import force_escape
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import SafeData
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class ForceEscapeTests(SimpleTestCase):
|
||||
|
@ -16,44 +16,44 @@ class ForceEscapeTests(SimpleTestCase):
|
|||
|
||||
@setup({'force-escape01': '{% autoescape off %}{{ a|force_escape }}{% endautoescape %}'})
|
||||
def test_force_escape01(self):
|
||||
output = render('force-escape01', {"a": "x&y"})
|
||||
output = self.engine.render_to_string('force-escape01', {"a": "x&y"})
|
||||
self.assertEqual(output, "x&y")
|
||||
|
||||
@setup({'force-escape02': '{{ a|force_escape }}'})
|
||||
def test_force_escape02(self):
|
||||
output = render('force-escape02', {"a": "x&y"})
|
||||
output = self.engine.render_to_string('force-escape02', {"a": "x&y"})
|
||||
self.assertEqual(output, "x&y")
|
||||
|
||||
@setup({'force-escape03': '{% autoescape off %}{{ a|force_escape|force_escape }}{% endautoescape %}'})
|
||||
def test_force_escape03(self):
|
||||
output = render('force-escape03', {"a": "x&y"})
|
||||
output = self.engine.render_to_string('force-escape03', {"a": "x&y"})
|
||||
self.assertEqual(output, "x&amp;y")
|
||||
|
||||
@setup({'force-escape04': '{{ a|force_escape|force_escape }}'})
|
||||
def test_force_escape04(self):
|
||||
output = render('force-escape04', {"a": "x&y"})
|
||||
output = self.engine.render_to_string('force-escape04', {"a": "x&y"})
|
||||
self.assertEqual(output, "x&amp;y")
|
||||
|
||||
# Because the result of force_escape is "safe", an additional
|
||||
# escape filter has no effect.
|
||||
@setup({'force-escape05': '{% autoescape off %}{{ a|force_escape|escape }}{% endautoescape %}'})
|
||||
def test_force_escape05(self):
|
||||
output = render('force-escape05', {"a": "x&y"})
|
||||
output = self.engine.render_to_string('force-escape05', {"a": "x&y"})
|
||||
self.assertEqual(output, "x&y")
|
||||
|
||||
@setup({'force-escape06': '{{ a|force_escape|escape }}'})
|
||||
def test_force_escape06(self):
|
||||
output = render('force-escape06', {"a": "x&y"})
|
||||
output = self.engine.render_to_string('force-escape06', {"a": "x&y"})
|
||||
self.assertEqual(output, "x&y")
|
||||
|
||||
@setup({'force-escape07': '{% autoescape off %}{{ a|escape|force_escape }}{% endautoescape %}'})
|
||||
def test_force_escape07(self):
|
||||
output = render('force-escape07', {"a": "x&y"})
|
||||
output = self.engine.render_to_string('force-escape07', {"a": "x&y"})
|
||||
self.assertEqual(output, "x&y")
|
||||
|
||||
@setup({'force-escape08': '{{ a|escape|force_escape }}'})
|
||||
def test_force_escape08(self):
|
||||
output = render('force-escape08', {"a": "x&y"})
|
||||
output = self.engine.render_to_string('force-escape08', {"a": "x&y"})
|
||||
self.assertEqual(output, "x&y")
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ from django.template.defaultfilters import iriencode, urlencode
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class IriencodeTests(SimpleTestCase):
|
||||
|
@ -15,22 +15,22 @@ class IriencodeTests(SimpleTestCase):
|
|||
|
||||
@setup({'iriencode01': '{{ url|iriencode }}'})
|
||||
def test_iriencode01(self):
|
||||
output = render('iriencode01', {'url': '?test=1&me=2'})
|
||||
output = self.engine.render_to_string('iriencode01', {'url': '?test=1&me=2'})
|
||||
self.assertEqual(output, '?test=1&me=2')
|
||||
|
||||
@setup({'iriencode02': '{% autoescape off %}{{ url|iriencode }}{% endautoescape %}'})
|
||||
def test_iriencode02(self):
|
||||
output = render('iriencode02', {'url': '?test=1&me=2'})
|
||||
output = self.engine.render_to_string('iriencode02', {'url': '?test=1&me=2'})
|
||||
self.assertEqual(output, '?test=1&me=2')
|
||||
|
||||
@setup({'iriencode03': '{{ url|iriencode }}'})
|
||||
def test_iriencode03(self):
|
||||
output = render('iriencode03', {'url': mark_safe('?test=1&me=2')})
|
||||
output = self.engine.render_to_string('iriencode03', {'url': mark_safe('?test=1&me=2')})
|
||||
self.assertEqual(output, '?test=1&me=2')
|
||||
|
||||
@setup({'iriencode04': '{% autoescape off %}{{ url|iriencode }}{% endautoescape %}'})
|
||||
def test_iriencode04(self):
|
||||
output = render('iriencode04', {'url': mark_safe('?test=1&me=2')})
|
||||
output = self.engine.render_to_string('iriencode04', {'url': mark_safe('?test=1&me=2')})
|
||||
self.assertEqual(output, '?test=1&me=2')
|
||||
|
||||
|
||||
|
|
|
@ -2,51 +2,51 @@ from django.template.defaultfilters import join
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class JoinTests(SimpleTestCase):
|
||||
|
||||
@setup({'join01': '{{ a|join:", " }}'})
|
||||
def test_join01(self):
|
||||
output = render('join01', {'a': ['alpha', 'beta & me']})
|
||||
output = self.engine.render_to_string('join01', {'a': ['alpha', 'beta & me']})
|
||||
self.assertEqual(output, 'alpha, beta & me')
|
||||
|
||||
@setup({'join02': '{% autoescape off %}{{ a|join:", " }}{% endautoescape %}'})
|
||||
def test_join02(self):
|
||||
output = render('join02', {'a': ['alpha', 'beta & me']})
|
||||
output = self.engine.render_to_string('join02', {'a': ['alpha', 'beta & me']})
|
||||
self.assertEqual(output, 'alpha, beta & me')
|
||||
|
||||
@setup({'join03': '{{ a|join:" & " }}'})
|
||||
def test_join03(self):
|
||||
output = render('join03', {'a': ['alpha', 'beta & me']})
|
||||
output = self.engine.render_to_string('join03', {'a': ['alpha', 'beta & me']})
|
||||
self.assertEqual(output, 'alpha & beta & me')
|
||||
|
||||
@setup({'join04': '{% autoescape off %}{{ a|join:" & " }}{% endautoescape %}'})
|
||||
def test_join04(self):
|
||||
output = render('join04', {'a': ['alpha', 'beta & me']})
|
||||
output = self.engine.render_to_string('join04', {'a': ['alpha', 'beta & me']})
|
||||
self.assertEqual(output, 'alpha & beta & me')
|
||||
|
||||
# #11377 Test that joining with unsafe joiners doesn't result in
|
||||
# unsafe strings
|
||||
@setup({'join05': '{{ a|join:var }}'})
|
||||
def test_join05(self):
|
||||
output = render('join05', {'a': ['alpha', 'beta & me'], 'var': ' & '})
|
||||
output = self.engine.render_to_string('join05', {'a': ['alpha', 'beta & me'], 'var': ' & '})
|
||||
self.assertEqual(output, 'alpha & beta & me')
|
||||
|
||||
@setup({'join06': '{{ a|join:var }}'})
|
||||
def test_join06(self):
|
||||
output = render('join06', {'a': ['alpha', 'beta & me'], 'var': mark_safe(' & ')})
|
||||
output = self.engine.render_to_string('join06', {'a': ['alpha', 'beta & me'], 'var': mark_safe(' & ')})
|
||||
self.assertEqual(output, 'alpha & beta & me')
|
||||
|
||||
@setup({'join07': '{{ a|join:var|lower }}'})
|
||||
def test_join07(self):
|
||||
output = render('join07', {'a': ['Alpha', 'Beta & me'], 'var': ' & '})
|
||||
output = self.engine.render_to_string('join07', {'a': ['Alpha', 'Beta & me'], 'var': ' & '})
|
||||
self.assertEqual(output, 'alpha & beta & me')
|
||||
|
||||
@setup({'join08': '{{ a|join:var|lower }}'})
|
||||
def test_join08(self):
|
||||
output = render('join08', {'a': ['Alpha', 'Beta & me'], 'var': mark_safe(' & ')})
|
||||
output = self.engine.render_to_string('join08', {'a': ['Alpha', 'Beta & me'], 'var': mark_safe(' & ')})
|
||||
self.assertEqual(output, 'alpha & beta & me')
|
||||
|
||||
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class LastTests(SimpleTestCase):
|
||||
|
||||
@setup({'last01': '{{ a|last }} {{ b|last }}'})
|
||||
def test_last01(self):
|
||||
output = render('last01', {"a": ["x", "a&b"], "b": ["x", mark_safe("a&b")]})
|
||||
output = self.engine.render_to_string('last01', {"a": ["x", "a&b"], "b": ["x", mark_safe("a&b")]})
|
||||
self.assertEqual(output, "a&b a&b")
|
||||
|
||||
@setup({'last02': '{% autoescape off %}{{ a|last }} {{ b|last }}{% endautoescape %}'})
|
||||
def test_last02(self):
|
||||
output = render('last02', {"a": ["x", "a&b"], "b": ["x", mark_safe("a&b")]})
|
||||
output = self.engine.render_to_string('last02', {"a": ["x", "a&b"], "b": ["x", mark_safe("a&b")]})
|
||||
self.assertEqual(output, "a&b a&b")
|
||||
|
|
|
@ -2,45 +2,45 @@ from django.template.defaultfilters import length
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class LengthTests(SimpleTestCase):
|
||||
|
||||
@setup({'length01': '{{ list|length }}'})
|
||||
def test_length01(self):
|
||||
output = render('length01', {'list': ['4', None, True, {}]})
|
||||
output = self.engine.render_to_string('length01', {'list': ['4', None, True, {}]})
|
||||
self.assertEqual(output, '4')
|
||||
|
||||
@setup({'length02': '{{ list|length }}'})
|
||||
def test_length02(self):
|
||||
output = render('length02', {'list': []})
|
||||
output = self.engine.render_to_string('length02', {'list': []})
|
||||
self.assertEqual(output, '0')
|
||||
|
||||
@setup({'length03': '{{ string|length }}'})
|
||||
def test_length03(self):
|
||||
output = render('length03', {'string': ''})
|
||||
output = self.engine.render_to_string('length03', {'string': ''})
|
||||
self.assertEqual(output, '0')
|
||||
|
||||
@setup({'length04': '{{ string|length }}'})
|
||||
def test_length04(self):
|
||||
output = render('length04', {'string': 'django'})
|
||||
output = self.engine.render_to_string('length04', {'string': 'django'})
|
||||
self.assertEqual(output, '6')
|
||||
|
||||
@setup({'length05': '{% if string|length == 6 %}Pass{% endif %}'})
|
||||
def test_length05(self):
|
||||
output = render('length05', {'string': mark_safe('django')})
|
||||
output = self.engine.render_to_string('length05', {'string': mark_safe('django')})
|
||||
self.assertEqual(output, 'Pass')
|
||||
|
||||
# Invalid uses that should fail silently.
|
||||
@setup({'length06': '{{ int|length }}'})
|
||||
def test_length06(self):
|
||||
output = render('length06', {'int': 7})
|
||||
output = self.engine.render_to_string('length06', {'int': 7})
|
||||
self.assertEqual(output, '0')
|
||||
|
||||
@setup({'length07': '{{ None|length }}'})
|
||||
def test_length07(self):
|
||||
output = render('length07', {'None': None})
|
||||
output = self.engine.render_to_string('length07', {'None': None})
|
||||
self.assertEqual(output, '0')
|
||||
|
||||
|
||||
|
|
|
@ -1,66 +1,66 @@
|
|||
from django.template.defaultfilters import length_is
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class LengthIsTests(SimpleTestCase):
|
||||
|
||||
@setup({'length_is01': '{% if some_list|length_is:"4" %}Four{% endif %}'})
|
||||
def test_length_is01(self):
|
||||
output = render('length_is01', {'some_list': ['4', None, True, {}]})
|
||||
output = self.engine.render_to_string('length_is01', {'some_list': ['4', None, True, {}]})
|
||||
self.assertEqual(output, 'Four')
|
||||
|
||||
@setup({'length_is02': '{% if some_list|length_is:"4" %}Four{% else %}Not Four{% endif %}'})
|
||||
def test_length_is02(self):
|
||||
output = render('length_is02', {'some_list': ['4', None, True, {}, 17]})
|
||||
output = self.engine.render_to_string('length_is02', {'some_list': ['4', None, True, {}, 17]})
|
||||
self.assertEqual(output, 'Not Four')
|
||||
|
||||
@setup({'length_is03': '{% if mystring|length_is:"4" %}Four{% endif %}'})
|
||||
def test_length_is03(self):
|
||||
output = render('length_is03', {'mystring': 'word'})
|
||||
output = self.engine.render_to_string('length_is03', {'mystring': 'word'})
|
||||
self.assertEqual(output, 'Four')
|
||||
|
||||
@setup({'length_is04': '{% if mystring|length_is:"4" %}Four{% else %}Not Four{% endif %}'})
|
||||
def test_length_is04(self):
|
||||
output = render('length_is04', {'mystring': 'Python'})
|
||||
output = self.engine.render_to_string('length_is04', {'mystring': 'Python'})
|
||||
self.assertEqual(output, 'Not Four')
|
||||
|
||||
@setup({'length_is05': '{% if mystring|length_is:"4" %}Four{% else %}Not Four{% endif %}'})
|
||||
def test_length_is05(self):
|
||||
output = render('length_is05', {'mystring': ''})
|
||||
output = self.engine.render_to_string('length_is05', {'mystring': ''})
|
||||
self.assertEqual(output, 'Not Four')
|
||||
|
||||
@setup({'length_is06': '{% with var|length as my_length %}{{ my_length }}{% endwith %}'})
|
||||
def test_length_is06(self):
|
||||
output = render('length_is06', {'var': 'django'})
|
||||
output = self.engine.render_to_string('length_is06', {'var': 'django'})
|
||||
self.assertEqual(output, '6')
|
||||
|
||||
# Boolean return value from length_is should not be coerced to a string
|
||||
@setup({'length_is07': '{% if "X"|length_is:0 %}Length is 0{% else %}Length not 0{% endif %}'})
|
||||
def test_length_is07(self):
|
||||
output = render('length_is07', {})
|
||||
output = self.engine.render_to_string('length_is07', {})
|
||||
self.assertEqual(output, 'Length not 0')
|
||||
|
||||
@setup({'length_is08': '{% if "X"|length_is:1 %}Length is 1{% else %}Length not 1{% endif %}'})
|
||||
def test_length_is08(self):
|
||||
output = render('length_is08', {})
|
||||
output = self.engine.render_to_string('length_is08', {})
|
||||
self.assertEqual(output, 'Length is 1')
|
||||
|
||||
# Invalid uses that should fail silently.
|
||||
@setup({'length_is09': '{{ var|length_is:"fish" }}'})
|
||||
def test_length_is09(self):
|
||||
output = render('length_is09', {'var': 'django'})
|
||||
output = self.engine.render_to_string('length_is09', {'var': 'django'})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'length_is10': '{{ int|length_is:"1" }}'})
|
||||
def test_length_is10(self):
|
||||
output = render('length_is10', {'int': 7})
|
||||
output = self.engine.render_to_string('length_is10', {'int': 7})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'length_is11': '{{ none|length_is:"1" }}'})
|
||||
def test_length_is11(self):
|
||||
output = render('length_is11', {'none': None})
|
||||
output = self.engine.render_to_string('length_is11', {'none': None})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ from django.template.defaultfilters import linebreaks_filter
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class LinebreaksTests(SimpleTestCase):
|
||||
|
@ -13,13 +13,13 @@ class LinebreaksTests(SimpleTestCase):
|
|||
|
||||
@setup({'linebreaks01': '{{ a|linebreaks }} {{ b|linebreaks }}'})
|
||||
def test_linebreaks01(self):
|
||||
output = render('linebreaks01', {"a": "x&\ny", "b": mark_safe("x&\ny")})
|
||||
output = self.engine.render_to_string('linebreaks01', {"a": "x&\ny", "b": mark_safe("x&\ny")})
|
||||
self.assertEqual(output, "<p>x&<br />y</p> <p>x&<br />y</p>")
|
||||
|
||||
@setup({'linebreaks02':
|
||||
'{% autoescape off %}{{ a|linebreaks }} {{ b|linebreaks }}{% endautoescape %}'})
|
||||
def test_linebreaks02(self):
|
||||
output = render('linebreaks02', {"a": "x&\ny", "b": mark_safe("x&\ny")})
|
||||
output = self.engine.render_to_string('linebreaks02', {"a": "x&\ny", "b": mark_safe("x&\ny")})
|
||||
self.assertEqual(output, "<p>x&<br />y</p> <p>x&<br />y</p>")
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ from django.template.defaultfilters import linebreaksbr
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class LinebreaksbrTests(SimpleTestCase):
|
||||
|
@ -13,13 +13,13 @@ class LinebreaksbrTests(SimpleTestCase):
|
|||
|
||||
@setup({'linebreaksbr01': '{{ a|linebreaksbr }} {{ b|linebreaksbr }}'})
|
||||
def test_linebreaksbr01(self):
|
||||
output = render('linebreaksbr01', {"a": "x&\ny", "b": mark_safe("x&\ny")})
|
||||
output = self.engine.render_to_string('linebreaksbr01', {"a": "x&\ny", "b": mark_safe("x&\ny")})
|
||||
self.assertEqual(output, "x&<br />y x&<br />y")
|
||||
|
||||
@setup({'linebreaksbr02':
|
||||
'{% autoescape off %}{{ a|linebreaksbr }} {{ b|linebreaksbr }}{% endautoescape %}'})
|
||||
def test_linebreaksbr02(self):
|
||||
output = render('linebreaksbr02', {"a": "x&\ny", "b": mark_safe("x&\ny")})
|
||||
output = self.engine.render_to_string('linebreaksbr02', {"a": "x&\ny", "b": mark_safe("x&\ny")})
|
||||
self.assertEqual(output, "x&<br />y x&<br />y")
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ from django.template.defaultfilters import linenumbers
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class LinenumbersTests(SimpleTestCase):
|
||||
|
@ -13,7 +13,7 @@ class LinenumbersTests(SimpleTestCase):
|
|||
|
||||
@setup({'linenumbers01': '{{ a|linenumbers }} {{ b|linenumbers }}'})
|
||||
def test_linenumbers01(self):
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'linenumbers01',
|
||||
{'a': 'one\n<two>\nthree', 'b': mark_safe('one\n<two>\nthree')},
|
||||
)
|
||||
|
@ -23,7 +23,7 @@ class LinenumbersTests(SimpleTestCase):
|
|||
@setup({'linenumbers02':
|
||||
'{% autoescape off %}{{ a|linenumbers }} {{ b|linenumbers }}{% endautoescape %}'})
|
||||
def test_linenumbers02(self):
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'linenumbers02',
|
||||
{'a': 'one\n<two>\nthree', 'b': mark_safe('one\n<two>\nthree')},
|
||||
)
|
||||
|
|
|
@ -2,19 +2,19 @@ from django.template.defaultfilters import ljust
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class LjustTests(SimpleTestCase):
|
||||
|
||||
@setup({'ljust01': '{% autoescape off %}.{{ a|ljust:"5" }}. .{{ b|ljust:"5" }}.{% endautoescape %}'})
|
||||
def test_ljust01(self):
|
||||
output = render('ljust01', {"a": "a&b", "b": mark_safe("a&b")})
|
||||
output = self.engine.render_to_string('ljust01', {"a": "a&b", "b": mark_safe("a&b")})
|
||||
self.assertEqual(output, ".a&b . .a&b .")
|
||||
|
||||
@setup({'ljust02': '.{{ a|ljust:"5" }}. .{{ b|ljust:"5" }}.'})
|
||||
def test_ljust02(self):
|
||||
output = render('ljust02', {"a": "a&b", "b": mark_safe("a&b")})
|
||||
output = self.engine.render_to_string('ljust02', {"a": "a&b", "b": mark_safe("a&b")})
|
||||
self.assertEqual(output, ".a&b . .a&b .")
|
||||
|
||||
|
||||
|
|
|
@ -5,19 +5,19 @@ from django.template.defaultfilters import lower
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class LowerTests(SimpleTestCase):
|
||||
|
||||
@setup({'lower01': '{% autoescape off %}{{ a|lower }} {{ b|lower }}{% endautoescape %}'})
|
||||
def test_lower01(self):
|
||||
output = render('lower01', {"a": "Apple & banana", "b": mark_safe("Apple & banana")})
|
||||
output = self.engine.render_to_string('lower01', {"a": "Apple & banana", "b": mark_safe("Apple & banana")})
|
||||
self.assertEqual(output, "apple & banana apple & banana")
|
||||
|
||||
@setup({'lower02': '{{ a|lower }} {{ b|lower }}'})
|
||||
def test_lower02(self):
|
||||
output = render('lower02', {"a": "Apple & banana", "b": mark_safe("Apple & banana")})
|
||||
output = self.engine.render_to_string('lower02', {"a": "Apple & banana", "b": mark_safe("Apple & banana")})
|
||||
self.assertEqual(output, "apple & banana apple & banana")
|
||||
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ from django.test import SimpleTestCase
|
|||
from django.test.utils import str_prefix
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class MakeListTests(SimpleTestCase):
|
||||
|
@ -14,23 +14,23 @@ class MakeListTests(SimpleTestCase):
|
|||
|
||||
@setup({'make_list01': '{% autoescape off %}{{ a|make_list }}{% endautoescape %}'})
|
||||
def test_make_list01(self):
|
||||
output = render('make_list01', {"a": mark_safe("&")})
|
||||
output = self.engine.render_to_string('make_list01', {"a": mark_safe("&")})
|
||||
self.assertEqual(output, str_prefix("[%(_)s'&']"))
|
||||
|
||||
@setup({'make_list02': '{{ a|make_list }}'})
|
||||
def test_make_list02(self):
|
||||
output = render('make_list02', {"a": mark_safe("&")})
|
||||
output = self.engine.render_to_string('make_list02', {"a": mark_safe("&")})
|
||||
self.assertEqual(output, str_prefix("[%(_)s'&']"))
|
||||
|
||||
@setup({'make_list03':
|
||||
'{% autoescape off %}{{ a|make_list|stringformat:"s"|safe }}{% endautoescape %}'})
|
||||
def test_make_list03(self):
|
||||
output = render('make_list03', {"a": mark_safe("&")})
|
||||
output = self.engine.render_to_string('make_list03', {"a": mark_safe("&")})
|
||||
self.assertEqual(output, str_prefix("[%(_)s'&']"))
|
||||
|
||||
@setup({'make_list04': '{{ a|make_list|stringformat:"s"|safe }}'})
|
||||
def test_make_list04(self):
|
||||
output = render('make_list04', {"a": mark_safe("&")})
|
||||
output = self.engine.render_to_string('make_list04', {"a": mark_safe("&")})
|
||||
self.assertEqual(output, str_prefix("[%(_)s'&']"))
|
||||
|
||||
|
||||
|
|
|
@ -2,14 +2,14 @@ from django.template.defaultfilters import phone2numeric_filter
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class Phone2numericTests(SimpleTestCase):
|
||||
|
||||
@setup({'phone2numeric01': '{{ a|phone2numeric }} {{ b|phone2numeric }}'})
|
||||
def test_phone2numeric01(self):
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'phone2numeric01',
|
||||
{'a': '<1-800-call-me>', 'b': mark_safe('<1-800-call-me>')},
|
||||
)
|
||||
|
@ -18,7 +18,7 @@ class Phone2numericTests(SimpleTestCase):
|
|||
@setup({'phone2numeric02':
|
||||
'{% autoescape off %}{{ a|phone2numeric }} {{ b|phone2numeric }}{% endautoescape %}'})
|
||||
def test_phone2numeric02(self):
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'phone2numeric02',
|
||||
{'a': '<1-800-call-me>', 'b': mark_safe('<1-800-call-me>')},
|
||||
)
|
||||
|
@ -26,7 +26,7 @@ class Phone2numericTests(SimpleTestCase):
|
|||
|
||||
@setup({'phone2numeric03': '{{ a|phone2numeric }}'})
|
||||
def test_phone2numeric03(self):
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'phone2numeric03',
|
||||
{'a': 'How razorback-jumping frogs can level six piqued gymnasts!'},
|
||||
)
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class RandomTests(SimpleTestCase):
|
||||
|
||||
@setup({'random01': '{{ a|random }} {{ b|random }}'})
|
||||
def test_random01(self):
|
||||
output = render('random01', {'a': ['a&b', 'a&b'], 'b': [mark_safe('a&b'), mark_safe('a&b')]})
|
||||
output = self.engine.render_to_string('random01', {'a': ['a&b', 'a&b'], 'b': [mark_safe('a&b'), mark_safe('a&b')]})
|
||||
self.assertEqual(output, 'a&b a&b')
|
||||
|
||||
@setup({'random02': '{% autoescape off %}{{ a|random }} {{ b|random }}{% endautoescape %}'})
|
||||
def test_random02(self):
|
||||
output = render('random02', {'a': ['a&b', 'a&b'], 'b': [mark_safe('a&b'), mark_safe('a&b')]})
|
||||
output = self.engine.render_to_string('random02', {'a': ['a&b', 'a&b'], 'b': [mark_safe('a&b'), mark_safe('a&b')]})
|
||||
self.assertEqual(output, 'a&b a&b')
|
||||
|
|
|
@ -5,7 +5,7 @@ from django.test import SimpleTestCase
|
|||
from django.utils.deprecation import RemovedInDjango20Warning
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class RemovetagsTests(SimpleTestCase):
|
||||
|
@ -14,7 +14,7 @@ class RemovetagsTests(SimpleTestCase):
|
|||
def test_removetags01(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', RemovedInDjango20Warning)
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'removetags01',
|
||||
{
|
||||
'a': '<a>x</a> <p><b>y</b></p>',
|
||||
|
@ -28,7 +28,7 @@ class RemovetagsTests(SimpleTestCase):
|
|||
def test_removetags02(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', RemovedInDjango20Warning)
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'removetags02',
|
||||
{
|
||||
'a': '<a>x</a> <p><b>y</b></p>',
|
||||
|
|
|
@ -2,19 +2,19 @@ from django.template.defaultfilters import rjust
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class RjustTests(SimpleTestCase):
|
||||
|
||||
@setup({'rjust01': '{% autoescape off %}.{{ a|rjust:"5" }}. .{{ b|rjust:"5" }}.{% endautoescape %}'})
|
||||
def test_rjust01(self):
|
||||
output = render('rjust01', {"a": "a&b", "b": mark_safe("a&b")})
|
||||
output = self.engine.render_to_string('rjust01', {"a": "a&b", "b": mark_safe("a&b")})
|
||||
self.assertEqual(output, ". a&b. . a&b.")
|
||||
|
||||
@setup({'rjust02': '.{{ a|rjust:"5" }}. .{{ b|rjust:"5" }}.'})
|
||||
def test_rjust02(self):
|
||||
output = render('rjust02', {"a": "a&b", "b": mark_safe("a&b")})
|
||||
output = self.engine.render_to_string('rjust02', {"a": "a&b", "b": mark_safe("a&b")})
|
||||
self.assertEqual(output, ". a&b. . a&b.")
|
||||
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class SafeTests(SimpleTestCase):
|
||||
|
||||
@setup({'safe01': '{{ a }} -- {{ a|safe }}'})
|
||||
def test_safe01(self):
|
||||
output = render('safe01', {'a': '<b>hello</b>'})
|
||||
output = self.engine.render_to_string('safe01', {'a': '<b>hello</b>'})
|
||||
self.assertEqual(output, '<b>hello</b> -- <b>hello</b>')
|
||||
|
||||
@setup({'safe02': '{% autoescape off %}{{ a }} -- {{ a|safe }}{% endautoescape %}'})
|
||||
def test_safe02(self):
|
||||
output = render('safe02', {'a': '<b>hello</b>'})
|
||||
output = self.engine.render_to_string('safe02', {'a': '<b>hello</b>'})
|
||||
self.assertEqual(output, '<b>hello</b> -- <b>hello</b>')
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class SafeseqTests(SimpleTestCase):
|
||||
|
||||
@setup({'safeseq01': '{{ a|join:", " }} -- {{ a|safeseq|join:", " }}'})
|
||||
def test_safeseq01(self):
|
||||
output = render('safeseq01', {'a': ['&', '<']})
|
||||
output = self.engine.render_to_string('safeseq01', {'a': ['&', '<']})
|
||||
self.assertEqual(output, '&, < -- &, <')
|
||||
|
||||
@setup({'safeseq02':
|
||||
'{% autoescape off %}{{ a|join:", " }} -- {{ a|safeseq|join:", " }}{% endautoescape %}'})
|
||||
def test_safeseq02(self):
|
||||
output = render('safeseq02', {'a': ['&', '<']})
|
||||
output = self.engine.render_to_string('safeseq02', {'a': ['&', '<']})
|
||||
self.assertEqual(output, '&, < -- &, <')
|
||||
|
|
|
@ -2,19 +2,19 @@ from django.template.defaultfilters import slice_filter
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class SliceTests(SimpleTestCase):
|
||||
|
||||
@setup({'slice01': '{{ a|slice:"1:3" }} {{ b|slice:"1:3" }}'})
|
||||
def test_slice01(self):
|
||||
output = render('slice01', {'a': 'a&b', 'b': mark_safe('a&b')})
|
||||
output = self.engine.render_to_string('slice01', {'a': 'a&b', 'b': mark_safe('a&b')})
|
||||
self.assertEqual(output, '&b &b')
|
||||
|
||||
@setup({'slice02': '{% autoescape off %}{{ a|slice:"1:3" }} {{ b|slice:"1:3" }}{% endautoescape %}'})
|
||||
def test_slice02(self):
|
||||
output = render('slice02', {'a': 'a&b', 'b': mark_safe('a&b')})
|
||||
output = self.engine.render_to_string('slice02', {'a': 'a&b', 'b': mark_safe('a&b')})
|
||||
self.assertEqual(output, '&b &b')
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ from django.template.defaultfilters import slugify
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class SlugifyTests(SimpleTestCase):
|
||||
|
@ -16,12 +16,12 @@ class SlugifyTests(SimpleTestCase):
|
|||
|
||||
@setup({'slugify01': '{% autoescape off %}{{ a|slugify }} {{ b|slugify }}{% endautoescape %}'})
|
||||
def test_slugify01(self):
|
||||
output = render('slugify01', {'a': 'a & b', 'b': mark_safe('a & b')})
|
||||
output = self.engine.render_to_string('slugify01', {'a': 'a & b', 'b': mark_safe('a & b')})
|
||||
self.assertEqual(output, 'a-b a-amp-b')
|
||||
|
||||
@setup({'slugify02': '{{ a|slugify }} {{ b|slugify }}'})
|
||||
def test_slugify02(self):
|
||||
output = render('slugify02', {'a': 'a & b', 'b': mark_safe('a & b')})
|
||||
output = self.engine.render_to_string('slugify02', {'a': 'a & b', 'b': mark_safe('a & b')})
|
||||
self.assertEqual(output, 'a-b a-amp-b')
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ from django.template.defaultfilters import stringformat
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class StringformatTests(SimpleTestCase):
|
||||
|
@ -14,12 +14,12 @@ class StringformatTests(SimpleTestCase):
|
|||
@setup({'stringformat01':
|
||||
'{% autoescape off %}.{{ a|stringformat:"5s" }}. .{{ b|stringformat:"5s" }}.{% endautoescape %}'})
|
||||
def test_stringformat01(self):
|
||||
output = render('stringformat01', {'a': 'a<b', 'b': mark_safe('a<b')})
|
||||
output = self.engine.render_to_string('stringformat01', {'a': 'a<b', 'b': mark_safe('a<b')})
|
||||
self.assertEqual(output, '. a<b. . a<b.')
|
||||
|
||||
@setup({'stringformat02': '.{{ a|stringformat:"5s" }}. .{{ b|stringformat:"5s" }}.'})
|
||||
def test_stringformat02(self):
|
||||
output = render('stringformat02', {'a': 'a<b', 'b': mark_safe('a<b')})
|
||||
output = self.engine.render_to_string('stringformat02', {'a': 'a<b', 'b': mark_safe('a<b')})
|
||||
self.assertEqual(output, '. a<b. . a<b.')
|
||||
|
||||
|
||||
|
|
|
@ -2,14 +2,14 @@ from django.template.defaultfilters import striptags
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class StriptagsTests(SimpleTestCase):
|
||||
|
||||
@setup({'striptags01': '{{ a|striptags }} {{ b|striptags }}'})
|
||||
def test_striptags01(self):
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'striptags01',
|
||||
{
|
||||
'a': '<a>x</a> <p><b>y</b></p>',
|
||||
|
@ -20,7 +20,7 @@ class StriptagsTests(SimpleTestCase):
|
|||
|
||||
@setup({'striptags02': '{% autoescape off %}{{ a|striptags }} {{ b|striptags }}{% endautoescape %}'})
|
||||
def test_striptags02(self):
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'striptags02',
|
||||
{
|
||||
'a': '<a>x</a> <p><b>y</b></p>',
|
||||
|
|
|
@ -5,7 +5,7 @@ from django.test import SimpleTestCase
|
|||
from django.utils import timezone
|
||||
|
||||
from .timezone_utils import TimezoneTestCase
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class TimeTests(TimezoneTestCase):
|
||||
|
@ -15,32 +15,32 @@ class TimeTests(TimezoneTestCase):
|
|||
|
||||
@setup({'time01': '{{ dt|time:"e:O:T:Z" }}'})
|
||||
def test_time01(self):
|
||||
output = render('time01', {'dt': self.now_tz_i})
|
||||
output = self.engine.render_to_string('time01', {'dt': self.now_tz_i})
|
||||
self.assertEqual(output, '+0315:+0315:+0315:11700')
|
||||
|
||||
@setup({'time02': '{{ dt|time:"e:T" }}'})
|
||||
def test_time02(self):
|
||||
output = render('time02', {'dt': self.now})
|
||||
output = self.engine.render_to_string('time02', {'dt': self.now})
|
||||
self.assertEqual(output, ':' + self.now_tz.tzinfo.tzname(self.now_tz))
|
||||
|
||||
@setup({'time03': '{{ t|time:"P:e:O:T:Z" }}'})
|
||||
def test_time03(self):
|
||||
output = render('time03', {'t': time(4, 0, tzinfo=timezone.get_fixed_timezone(30))})
|
||||
output = self.engine.render_to_string('time03', {'t': time(4, 0, tzinfo=timezone.get_fixed_timezone(30))})
|
||||
self.assertEqual(output, '4 a.m.::::')
|
||||
|
||||
@setup({'time04': '{{ t|time:"P:e:O:T:Z" }}'})
|
||||
def test_time04(self):
|
||||
output = render('time04', {'t': time(4, 0)})
|
||||
output = self.engine.render_to_string('time04', {'t': time(4, 0)})
|
||||
self.assertEqual(output, '4 a.m.::::')
|
||||
|
||||
@setup({'time05': '{{ d|time:"P:e:O:T:Z" }}'})
|
||||
def test_time05(self):
|
||||
output = render('time05', {'d': self.today})
|
||||
output = self.engine.render_to_string('time05', {'d': self.today})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'time06': '{{ obj|time:"P:e:O:T:Z" }}'})
|
||||
def test_time06(self):
|
||||
output = render('time06', {'obj': 'non-datetime-value'})
|
||||
output = self.engine.render_to_string('time06', {'obj': 'non-datetime-value'})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ from django.test import SimpleTestCase
|
|||
from django.test.utils import requires_tz_support
|
||||
|
||||
from .timezone_utils import TimezoneTestCase
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class TimesinceTests(TimezoneTestCase):
|
||||
|
@ -18,23 +18,23 @@ class TimesinceTests(TimezoneTestCase):
|
|||
# Default compare with datetime.now()
|
||||
@setup({'timesince01': '{{ a|timesince }}'})
|
||||
def test_timesince01(self):
|
||||
output = render('timesince01', {'a': datetime.now() + timedelta(minutes=-1, seconds=-10)})
|
||||
output = self.engine.render_to_string('timesince01', {'a': datetime.now() + timedelta(minutes=-1, seconds=-10)})
|
||||
self.assertEqual(output, '1\xa0minute')
|
||||
|
||||
@setup({'timesince02': '{{ a|timesince }}'})
|
||||
def test_timesince02(self):
|
||||
output = render('timesince02', {'a': datetime.now() - timedelta(days=1, minutes=1)})
|
||||
output = self.engine.render_to_string('timesince02', {'a': datetime.now() - timedelta(days=1, minutes=1)})
|
||||
self.assertEqual(output, '1\xa0day')
|
||||
|
||||
@setup({'timesince03': '{{ a|timesince }}'})
|
||||
def test_timesince03(self):
|
||||
output = render('timesince03', {'a': datetime.now() - timedelta(hours=1, minutes=25, seconds=10)})
|
||||
output = self.engine.render_to_string('timesince03', {'a': datetime.now() - timedelta(hours=1, minutes=25, seconds=10)})
|
||||
self.assertEqual(output, '1\xa0hour, 25\xa0minutes')
|
||||
|
||||
# Compare to a given parameter
|
||||
@setup({'timesince04': '{{ a|timesince:b }}'})
|
||||
def test_timesince04(self):
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'timesince04',
|
||||
{'a': self.now - timedelta(days=2), 'b': self.now - timedelta(days=1)},
|
||||
)
|
||||
|
@ -42,7 +42,7 @@ class TimesinceTests(TimezoneTestCase):
|
|||
|
||||
@setup({'timesince05': '{{ a|timesince:b }}'})
|
||||
def test_timesince05(self):
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'timesince05',
|
||||
{'a': self.now - timedelta(days=2, minutes=1), 'b': self.now - timedelta(days=2)},
|
||||
)
|
||||
|
@ -51,72 +51,72 @@ class TimesinceTests(TimezoneTestCase):
|
|||
# Check that timezone is respected
|
||||
@setup({'timesince06': '{{ a|timesince:b }}'})
|
||||
def test_timesince06(self):
|
||||
output = render('timesince06', {'a': self.now_tz - timedelta(hours=8), 'b': self.now_tz})
|
||||
output = self.engine.render_to_string('timesince06', {'a': self.now_tz - timedelta(hours=8), 'b': self.now_tz})
|
||||
self.assertEqual(output, '8\xa0hours')
|
||||
|
||||
# Tests for #7443
|
||||
@setup({'timesince07': '{{ earlier|timesince }}'})
|
||||
def test_timesince07(self):
|
||||
output = render('timesince07', {'earlier': self.now - timedelta(days=7)})
|
||||
output = self.engine.render_to_string('timesince07', {'earlier': self.now - timedelta(days=7)})
|
||||
self.assertEqual(output, '1\xa0week')
|
||||
|
||||
@setup({'timesince08': '{{ earlier|timesince:now }}'})
|
||||
def test_timesince08(self):
|
||||
output = render('timesince08', {'now': self.now, 'earlier': self.now - timedelta(days=7)})
|
||||
output = self.engine.render_to_string('timesince08', {'now': self.now, 'earlier': self.now - timedelta(days=7)})
|
||||
self.assertEqual(output, '1\xa0week')
|
||||
|
||||
@setup({'timesince09': '{{ later|timesince }}'})
|
||||
def test_timesince09(self):
|
||||
output = render('timesince09', {'later': self.now + timedelta(days=7)})
|
||||
output = self.engine.render_to_string('timesince09', {'later': self.now + timedelta(days=7)})
|
||||
self.assertEqual(output, '0\xa0minutes')
|
||||
|
||||
@setup({'timesince10': '{{ later|timesince:now }}'})
|
||||
def test_timesince10(self):
|
||||
output = render('timesince10', {'now': self.now, 'later': self.now + timedelta(days=7)})
|
||||
output = self.engine.render_to_string('timesince10', {'now': self.now, 'later': self.now + timedelta(days=7)})
|
||||
self.assertEqual(output, '0\xa0minutes')
|
||||
|
||||
# Ensures that differing timezones are calculated correctly.
|
||||
@setup({'timesince11': '{{ a|timesince }}'})
|
||||
def test_timesince11(self):
|
||||
output = render('timesince11', {'a': self.now})
|
||||
output = self.engine.render_to_string('timesince11', {'a': self.now})
|
||||
self.assertEqual(output, '0\xa0minutes')
|
||||
|
||||
@requires_tz_support
|
||||
@setup({'timesince12': '{{ a|timesince }}'})
|
||||
def test_timesince12(self):
|
||||
output = render('timesince12', {'a': self.now_tz})
|
||||
output = self.engine.render_to_string('timesince12', {'a': self.now_tz})
|
||||
self.assertEqual(output, '0\xa0minutes')
|
||||
|
||||
@requires_tz_support
|
||||
@setup({'timesince13': '{{ a|timesince }}'})
|
||||
def test_timesince13(self):
|
||||
output = render('timesince13', {'a': self.now_tz_i})
|
||||
output = self.engine.render_to_string('timesince13', {'a': self.now_tz_i})
|
||||
self.assertEqual(output, '0\xa0minutes')
|
||||
|
||||
@setup({'timesince14': '{{ a|timesince:b }}'})
|
||||
def test_timesince14(self):
|
||||
output = render('timesince14', {'a': self.now_tz, 'b': self.now_tz_i})
|
||||
output = self.engine.render_to_string('timesince14', {'a': self.now_tz, 'b': self.now_tz_i})
|
||||
self.assertEqual(output, '0\xa0minutes')
|
||||
|
||||
@setup({'timesince15': '{{ a|timesince:b }}'})
|
||||
def test_timesince15(self):
|
||||
output = render('timesince15', {'a': self.now, 'b': self.now_tz_i})
|
||||
output = self.engine.render_to_string('timesince15', {'a': self.now, 'b': self.now_tz_i})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'timesince16': '{{ a|timesince:b }}'})
|
||||
def test_timesince16(self):
|
||||
output = render('timesince16', {'a': self.now_tz_i, 'b': self.now})
|
||||
output = self.engine.render_to_string('timesince16', {'a': self.now_tz_i, 'b': self.now})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
# Tests for #9065 (two date objects).
|
||||
@setup({'timesince17': '{{ a|timesince:b }}'})
|
||||
def test_timesince17(self):
|
||||
output = render('timesince17', {'a': self.today, 'b': self.today})
|
||||
output = self.engine.render_to_string('timesince17', {'a': self.today, 'b': self.today})
|
||||
self.assertEqual(output, '0\xa0minutes')
|
||||
|
||||
@setup({'timesince18': '{{ a|timesince:b }}'})
|
||||
def test_timesince18(self):
|
||||
output = render('timesince18', {'a': self.today, 'b': self.today + timedelta(hours=24)})
|
||||
output = self.engine.render_to_string('timesince18', {'a': self.today, 'b': self.today + timedelta(hours=24)})
|
||||
self.assertEqual(output, '1\xa0day')
|
||||
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ from django.test import SimpleTestCase
|
|||
from django.test.utils import requires_tz_support
|
||||
|
||||
from .timezone_utils import TimezoneTestCase
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class TimeuntilTests(TimezoneTestCase):
|
||||
|
@ -15,23 +15,23 @@ class TimeuntilTests(TimezoneTestCase):
|
|||
# Default compare with datetime.now()
|
||||
@setup({'timeuntil01': '{{ a|timeuntil }}'})
|
||||
def test_timeuntil01(self):
|
||||
output = render('timeuntil01', {'a': datetime.now() + timedelta(minutes=2, seconds=10)})
|
||||
output = self.engine.render_to_string('timeuntil01', {'a': datetime.now() + timedelta(minutes=2, seconds=10)})
|
||||
self.assertEqual(output, '2\xa0minutes')
|
||||
|
||||
@setup({'timeuntil02': '{{ a|timeuntil }}'})
|
||||
def test_timeuntil02(self):
|
||||
output = render('timeuntil02', {'a': (datetime.now() + timedelta(days=1, seconds=10))})
|
||||
output = self.engine.render_to_string('timeuntil02', {'a': (datetime.now() + timedelta(days=1, seconds=10))})
|
||||
self.assertEqual(output, '1\xa0day')
|
||||
|
||||
@setup({'timeuntil03': '{{ a|timeuntil }}'})
|
||||
def test_timeuntil03(self):
|
||||
output = render('timeuntil03', {'a': (datetime.now() + timedelta(hours=8, minutes=10, seconds=10))})
|
||||
output = self.engine.render_to_string('timeuntil03', {'a': (datetime.now() + timedelta(hours=8, minutes=10, seconds=10))})
|
||||
self.assertEqual(output, '8\xa0hours, 10\xa0minutes')
|
||||
|
||||
# Compare to a given parameter
|
||||
@setup({'timeuntil04': '{{ a|timeuntil:b }}'})
|
||||
def test_timeuntil04(self):
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'timeuntil04',
|
||||
{'a': self.now - timedelta(days=1), 'b': self.now - timedelta(days=2)},
|
||||
)
|
||||
|
@ -39,7 +39,7 @@ class TimeuntilTests(TimezoneTestCase):
|
|||
|
||||
@setup({'timeuntil05': '{{ a|timeuntil:b }}'})
|
||||
def test_timeuntil05(self):
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'timeuntil05',
|
||||
{'a': self.now - timedelta(days=2), 'b': self.now - timedelta(days=2, minutes=1)},
|
||||
)
|
||||
|
@ -48,51 +48,51 @@ class TimeuntilTests(TimezoneTestCase):
|
|||
# Regression for #7443
|
||||
@setup({'timeuntil06': '{{ earlier|timeuntil }}'})
|
||||
def test_timeuntil06(self):
|
||||
output = render('timeuntil06', {'earlier': self.now - timedelta(days=7)})
|
||||
output = self.engine.render_to_string('timeuntil06', {'earlier': self.now - timedelta(days=7)})
|
||||
self.assertEqual(output, '0\xa0minutes')
|
||||
|
||||
@setup({'timeuntil07': '{{ earlier|timeuntil:now }}'})
|
||||
def test_timeuntil07(self):
|
||||
output = render('timeuntil07', {'now': self.now, 'earlier': self.now - timedelta(days=7)})
|
||||
output = self.engine.render_to_string('timeuntil07', {'now': self.now, 'earlier': self.now - timedelta(days=7)})
|
||||
self.assertEqual(output, '0\xa0minutes')
|
||||
|
||||
@setup({'timeuntil08': '{{ later|timeuntil }}'})
|
||||
def test_timeuntil08(self):
|
||||
output = render('timeuntil08', {'later': self.now + timedelta(days=7, hours=1)})
|
||||
output = self.engine.render_to_string('timeuntil08', {'later': self.now + timedelta(days=7, hours=1)})
|
||||
self.assertEqual(output, '1\xa0week')
|
||||
|
||||
@setup({'timeuntil09': '{{ later|timeuntil:now }}'})
|
||||
def test_timeuntil09(self):
|
||||
output = render('timeuntil09', {'now': self.now, 'later': self.now + timedelta(days=7)})
|
||||
output = self.engine.render_to_string('timeuntil09', {'now': self.now, 'later': self.now + timedelta(days=7)})
|
||||
self.assertEqual(output, '1\xa0week')
|
||||
|
||||
# Ensures that differing timezones are calculated correctly.
|
||||
@requires_tz_support
|
||||
@setup({'timeuntil10': '{{ a|timeuntil }}'})
|
||||
def test_timeuntil10(self):
|
||||
output = render('timeuntil10', {'a': self.now_tz})
|
||||
output = self.engine.render_to_string('timeuntil10', {'a': self.now_tz})
|
||||
self.assertEqual(output, '0\xa0minutes')
|
||||
|
||||
@requires_tz_support
|
||||
@setup({'timeuntil11': '{{ a|timeuntil }}'})
|
||||
def test_timeuntil11(self):
|
||||
output = render('timeuntil11', {'a': self.now_tz_i})
|
||||
output = self.engine.render_to_string('timeuntil11', {'a': self.now_tz_i})
|
||||
self.assertEqual(output, '0\xa0minutes')
|
||||
|
||||
@setup({'timeuntil12': '{{ a|timeuntil:b }}'})
|
||||
def test_timeuntil12(self):
|
||||
output = render('timeuntil12', {'a': self.now_tz_i, 'b': self.now_tz})
|
||||
output = self.engine.render_to_string('timeuntil12', {'a': self.now_tz_i, 'b': self.now_tz})
|
||||
self.assertEqual(output, '0\xa0minutes')
|
||||
|
||||
# Regression for #9065 (two date objects).
|
||||
@setup({'timeuntil13': '{{ a|timeuntil:b }}'})
|
||||
def test_timeuntil13(self):
|
||||
output = render('timeuntil13', {'a': self.today, 'b': self.today})
|
||||
output = self.engine.render_to_string('timeuntil13', {'a': self.today, 'b': self.today})
|
||||
self.assertEqual(output, '0\xa0minutes')
|
||||
|
||||
@setup({'timeuntil14': '{{ a|timeuntil:b }}'})
|
||||
def test_timeuntil14(self):
|
||||
output = render('timeuntil14', {'a': self.today, 'b': self.today - timedelta(hours=24)})
|
||||
output = self.engine.render_to_string('timeuntil14', {'a': self.today, 'b': self.today - timedelta(hours=24)})
|
||||
self.assertEqual(output, '1\xa0day')
|
||||
|
||||
|
||||
|
|
|
@ -4,19 +4,19 @@ from __future__ import unicode_literals
|
|||
from django.template.defaultfilters import title
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class TitleTests(SimpleTestCase):
|
||||
|
||||
@setup({'title1': '{{ a|title }}'})
|
||||
def test_title1(self):
|
||||
output = render('title1', {'a': 'JOE\'S CRAB SHACK'})
|
||||
output = self.engine.render_to_string('title1', {'a': 'JOE\'S CRAB SHACK'})
|
||||
self.assertEqual(output, 'Joe's Crab Shack')
|
||||
|
||||
@setup({'title2': '{{ a|title }}'})
|
||||
def test_title2(self):
|
||||
output = render('title2', {'a': '555 WEST 53RD STREET'})
|
||||
output = self.engine.render_to_string('title2', {'a': '555 WEST 53RD STREET'})
|
||||
self.assertEqual(output, '555 West 53rd Street')
|
||||
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class TruncatecharsTests(SimpleTestCase):
|
||||
|
||||
@setup({'truncatechars01': '{{ a|truncatechars:5 }}'})
|
||||
def test_truncatechars01(self):
|
||||
output = render('truncatechars01', {'a': 'Testing, testing'})
|
||||
output = self.engine.render_to_string('truncatechars01', {'a': 'Testing, testing'})
|
||||
self.assertEqual(output, 'Te...')
|
||||
|
||||
@setup({'truncatechars02': '{{ a|truncatechars:7 }}'})
|
||||
def test_truncatechars02(self):
|
||||
output = render('truncatechars02', {'a': 'Testing'})
|
||||
output = self.engine.render_to_string('truncatechars02', {'a': 'Testing'})
|
||||
self.assertEqual(output, 'Testing')
|
||||
|
|
|
@ -2,7 +2,7 @@ from django.template.defaultfilters import truncatewords
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class TruncatewordsTests(SimpleTestCase):
|
||||
|
@ -10,12 +10,12 @@ class TruncatewordsTests(SimpleTestCase):
|
|||
@setup({'truncatewords01':
|
||||
'{% autoescape off %}{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}{% endautoescape %}'})
|
||||
def test_truncatewords01(self):
|
||||
output = render('truncatewords01', {'a': 'alpha & bravo', 'b': mark_safe('alpha & bravo')})
|
||||
output = self.engine.render_to_string('truncatewords01', {'a': 'alpha & bravo', 'b': mark_safe('alpha & bravo')})
|
||||
self.assertEqual(output, 'alpha & ... alpha & ...')
|
||||
|
||||
@setup({'truncatewords02': '{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}'})
|
||||
def test_truncatewords02(self):
|
||||
output = render('truncatewords02', {'a': 'alpha & bravo', 'b': mark_safe('alpha & bravo')})
|
||||
output = self.engine.render_to_string('truncatewords02', {'a': 'alpha & bravo', 'b': mark_safe('alpha & bravo')})
|
||||
self.assertEqual(output, 'alpha & ... alpha & ...')
|
||||
|
||||
|
||||
|
|
|
@ -6,36 +6,36 @@ from django.utils.deprecation import RemovedInDjango20Warning
|
|||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class UnorderedListTests(SimpleTestCase):
|
||||
|
||||
@setup({'unordered_list01': '{{ a|unordered_list }}'})
|
||||
def test_unordered_list01(self):
|
||||
output = render('unordered_list01', {'a': ['x>', ['<y']]})
|
||||
output = self.engine.render_to_string('unordered_list01', {'a': ['x>', ['<y']]})
|
||||
self.assertEqual(output, '\t<li>x>\n\t<ul>\n\t\t<li><y</li>\n\t</ul>\n\t</li>')
|
||||
|
||||
@setup({'unordered_list02': '{% autoescape off %}{{ a|unordered_list }}{% endautoescape %}'})
|
||||
def test_unordered_list02(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', RemovedInDjango20Warning)
|
||||
output = render('unordered_list02', {'a': ['x>', ['<y']]})
|
||||
output = self.engine.render_to_string('unordered_list02', {'a': ['x>', ['<y']]})
|
||||
self.assertEqual(output, '\t<li>x>\n\t<ul>\n\t\t<li><y</li>\n\t</ul>\n\t</li>')
|
||||
|
||||
@setup({'unordered_list03': '{{ a|unordered_list }}'})
|
||||
def test_unordered_list03(self):
|
||||
output = render('unordered_list03', {'a': ['x>', [mark_safe('<y')]]})
|
||||
output = self.engine.render_to_string('unordered_list03', {'a': ['x>', [mark_safe('<y')]]})
|
||||
self.assertEqual(output, '\t<li>x>\n\t<ul>\n\t\t<li><y</li>\n\t</ul>\n\t</li>')
|
||||
|
||||
@setup({'unordered_list04': '{% autoescape off %}{{ a|unordered_list }}{% endautoescape %}'})
|
||||
def test_unordered_list04(self):
|
||||
output = render('unordered_list04', {'a': ['x>', [mark_safe('<y')]]})
|
||||
output = self.engine.render_to_string('unordered_list04', {'a': ['x>', [mark_safe('<y')]]})
|
||||
self.assertEqual(output, '\t<li>x>\n\t<ul>\n\t\t<li><y</li>\n\t</ul>\n\t</li>')
|
||||
|
||||
@setup({'unordered_list05': '{% autoescape off %}{{ a|unordered_list }}{% endautoescape %}'})
|
||||
def test_unordered_list05(self):
|
||||
output = render('unordered_list05', {'a': ['x>', ['<y']]})
|
||||
output = self.engine.render_to_string('unordered_list05', {'a': ['x>', ['<y']]})
|
||||
self.assertEqual(output, '\t<li>x>\n\t<ul>\n\t\t<li><y</li>\n\t</ul>\n\t</li>')
|
||||
|
||||
|
||||
|
@ -45,35 +45,35 @@ class DeprecatedUnorderedListSyntaxTests(SimpleTestCase):
|
|||
def test_unordered_list01(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', RemovedInDjango20Warning)
|
||||
output = render('unordered_list01', {'a': ['x>', [['<y', []]]]})
|
||||
output = self.engine.render_to_string('unordered_list01', {'a': ['x>', [['<y', []]]]})
|
||||
self.assertEqual(output, '\t<li>x>\n\t<ul>\n\t\t<li><y</li>\n\t</ul>\n\t</li>')
|
||||
|
||||
@setup({'unordered_list02': '{% autoescape off %}{{ a|unordered_list }}{% endautoescape %}'})
|
||||
def test_unordered_list02(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', RemovedInDjango20Warning)
|
||||
output = render('unordered_list02', {'a': ['x>', [['<y', []]]]})
|
||||
output = self.engine.render_to_string('unordered_list02', {'a': ['x>', [['<y', []]]]})
|
||||
self.assertEqual(output, '\t<li>x>\n\t<ul>\n\t\t<li><y</li>\n\t</ul>\n\t</li>')
|
||||
|
||||
@setup({'unordered_list03': '{{ a|unordered_list }}'})
|
||||
def test_unordered_list03(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', RemovedInDjango20Warning)
|
||||
output = render('unordered_list03', {'a': ['x>', [[mark_safe('<y'), []]]]})
|
||||
output = self.engine.render_to_string('unordered_list03', {'a': ['x>', [[mark_safe('<y'), []]]]})
|
||||
self.assertEqual(output, '\t<li>x>\n\t<ul>\n\t\t<li><y</li>\n\t</ul>\n\t</li>')
|
||||
|
||||
@setup({'unordered_list04': '{% autoescape off %}{{ a|unordered_list }}{% endautoescape %}'})
|
||||
def test_unordered_list04(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', RemovedInDjango20Warning)
|
||||
output = render('unordered_list04', {'a': ['x>', [[mark_safe('<y'), []]]]})
|
||||
output = self.engine.render_to_string('unordered_list04', {'a': ['x>', [[mark_safe('<y'), []]]]})
|
||||
self.assertEqual(output, '\t<li>x>\n\t<ul>\n\t\t<li><y</li>\n\t</ul>\n\t</li>')
|
||||
|
||||
@setup({'unordered_list05': '{% autoescape off %}{{ a|unordered_list }}{% endautoescape %}'})
|
||||
def test_unordered_list05(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', RemovedInDjango20Warning)
|
||||
output = render('unordered_list05', {'a': ['x>', [['<y', []]]]})
|
||||
output = self.engine.render_to_string('unordered_list05', {'a': ['x>', [['<y', []]]]})
|
||||
self.assertEqual(output, '\t<li>x>\n\t<ul>\n\t\t<li><y</li>\n\t</ul>\n\t</li>')
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ from django.template.defaultfilters import upper
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class UpperTests(SimpleTestCase):
|
||||
|
@ -16,12 +16,12 @@ class UpperTests(SimpleTestCase):
|
|||
|
||||
@setup({'upper01': '{% autoescape off %}{{ a|upper }} {{ b|upper }}{% endautoescape %}'})
|
||||
def test_upper01(self):
|
||||
output = render('upper01', {'a': 'a & b', 'b': mark_safe('a & b')})
|
||||
output = self.engine.render_to_string('upper01', {'a': 'a & b', 'b': mark_safe('a & b')})
|
||||
self.assertEqual(output, 'A & B A & B')
|
||||
|
||||
@setup({'upper02': '{{ a|upper }} {{ b|upper }}'})
|
||||
def test_upper02(self):
|
||||
output = render('upper02', {'a': 'a & b', 'b': mark_safe('a & b')})
|
||||
output = self.engine.render_to_string('upper02', {'a': 'a & b', 'b': mark_safe('a & b')})
|
||||
self.assertEqual(output, 'A & B A &AMP; B')
|
||||
|
||||
|
||||
|
|
|
@ -4,19 +4,19 @@ from __future__ import unicode_literals
|
|||
from django.template.defaultfilters import urlencode
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class UrlencodeTests(SimpleTestCase):
|
||||
|
||||
@setup({'urlencode01': '{{ url|urlencode }}'})
|
||||
def test_urlencode01(self):
|
||||
output = render('urlencode01', {'url': '/test&"/me?/'})
|
||||
output = self.engine.render_to_string('urlencode01', {'url': '/test&"/me?/'})
|
||||
self.assertEqual(output, '/test%26%22/me%3F/')
|
||||
|
||||
@setup({'urlencode02': '/test/{{ urlbit|urlencode:"" }}/'})
|
||||
def test_urlencode02(self):
|
||||
output = render('urlencode02', {'urlbit': 'escape/slash'})
|
||||
output = self.engine.render_to_string('urlencode02', {'urlbit': 'escape/slash'})
|
||||
self.assertEqual(output, '/test/escape%2Fslash/')
|
||||
|
||||
|
||||
|
|
|
@ -5,14 +5,14 @@ from django.template.defaultfilters import urlize
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class UrlizeTests(SimpleTestCase):
|
||||
|
||||
@setup({'urlize01': '{% autoescape off %}{{ a|urlize }} {{ b|urlize }}{% endautoescape %}'})
|
||||
def test_urlize01(self):
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'urlize01',
|
||||
{'a': 'http://example.com/?x=&y=', 'b': mark_safe('http://example.com?x=&y=<2>')},
|
||||
)
|
||||
|
@ -24,7 +24,7 @@ class UrlizeTests(SimpleTestCase):
|
|||
|
||||
@setup({'urlize02': '{{ a|urlize }} {{ b|urlize }}'})
|
||||
def test_urlize02(self):
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'urlize02',
|
||||
{'a': "http://example.com/?x=&y=", 'b': mark_safe("http://example.com?x=&y=")},
|
||||
)
|
||||
|
@ -36,30 +36,30 @@ class UrlizeTests(SimpleTestCase):
|
|||
|
||||
@setup({'urlize03': '{% autoescape off %}{{ a|urlize }}{% endautoescape %}'})
|
||||
def test_urlize03(self):
|
||||
output = render('urlize03', {'a': mark_safe("a & b")})
|
||||
output = self.engine.render_to_string('urlize03', {'a': mark_safe("a & b")})
|
||||
self.assertEqual(output, 'a & b')
|
||||
|
||||
@setup({'urlize04': '{{ a|urlize }}'})
|
||||
def test_urlize04(self):
|
||||
output = render('urlize04', {'a': mark_safe("a & b")})
|
||||
output = self.engine.render_to_string('urlize04', {'a': mark_safe("a & b")})
|
||||
self.assertEqual(output, 'a & b')
|
||||
|
||||
# This will lead to a nonsense result, but at least it won't be
|
||||
# exploitable for XSS purposes when auto-escaping is on.
|
||||
@setup({'urlize05': '{% autoescape off %}{{ a|urlize }}{% endautoescape %}'})
|
||||
def test_urlize05(self):
|
||||
output = render('urlize05', {'a': "<script>alert('foo')</script>"})
|
||||
output = self.engine.render_to_string('urlize05', {'a': "<script>alert('foo')</script>"})
|
||||
self.assertEqual(output, "<script>alert('foo')</script>")
|
||||
|
||||
@setup({'urlize06': '{{ a|urlize }}'})
|
||||
def test_urlize06(self):
|
||||
output = render('urlize06', {'a': "<script>alert('foo')</script>"})
|
||||
output = self.engine.render_to_string('urlize06', {'a': "<script>alert('foo')</script>"})
|
||||
self.assertEqual(output, '<script>alert('foo')</script>')
|
||||
|
||||
# mailto: testing for urlize
|
||||
@setup({'urlize07': '{{ a|urlize }}'})
|
||||
def test_urlize07(self):
|
||||
output = render('urlize07', {'a': "Email me at me@example.com"})
|
||||
output = self.engine.render_to_string('urlize07', {'a': "Email me at me@example.com"})
|
||||
self.assertEqual(
|
||||
output,
|
||||
'Email me at <a href="mailto:me@example.com">me@example.com</a>',
|
||||
|
@ -67,7 +67,7 @@ class UrlizeTests(SimpleTestCase):
|
|||
|
||||
@setup({'urlize08': '{{ a|urlize }}'})
|
||||
def test_urlize08(self):
|
||||
output = render('urlize08', {'a': "Email me at <me@example.com>"})
|
||||
output = self.engine.render_to_string('urlize08', {'a': "Email me at <me@example.com>"})
|
||||
self.assertEqual(
|
||||
output,
|
||||
'Email me at <<a href="mailto:me@example.com">me@example.com</a>>',
|
||||
|
|
|
@ -2,7 +2,7 @@ from django.template.defaultfilters import urlizetrunc
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class UrlizetruncTests(SimpleTestCase):
|
||||
|
@ -10,7 +10,7 @@ class UrlizetruncTests(SimpleTestCase):
|
|||
@setup({'urlizetrunc01':
|
||||
'{% autoescape off %}{{ a|urlizetrunc:"8" }} {{ b|urlizetrunc:"8" }}{% endautoescape %}'})
|
||||
def test_urlizetrunc01(self):
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'urlizetrunc01',
|
||||
{
|
||||
'a': '"Unsafe" http://example.com/x=&y=',
|
||||
|
@ -25,7 +25,7 @@ class UrlizetruncTests(SimpleTestCase):
|
|||
|
||||
@setup({'urlizetrunc02': '{{ a|urlizetrunc:"8" }} {{ b|urlizetrunc:"8" }}'})
|
||||
def test_urlizetrunc02(self):
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'urlizetrunc02',
|
||||
{
|
||||
'a': '"Unsafe" http://example.com/x=&y=',
|
||||
|
|
|
@ -2,19 +2,19 @@ from django.template.defaultfilters import wordcount
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class WordcountTests(SimpleTestCase):
|
||||
|
||||
@setup({'wordcount01': '{% autoescape off %}{{ a|wordcount }} {{ b|wordcount }}{% endautoescape %}'})
|
||||
def test_wordcount01(self):
|
||||
output = render('wordcount01', {'a': 'a & b', 'b': mark_safe('a & b')})
|
||||
output = self.engine.render_to_string('wordcount01', {'a': 'a & b', 'b': mark_safe('a & b')})
|
||||
self.assertEqual(output, '3 3')
|
||||
|
||||
@setup({'wordcount02': '{{ a|wordcount }} {{ b|wordcount }}'})
|
||||
def test_wordcount02(self):
|
||||
output = render('wordcount02', {'a': 'a & b', 'b': mark_safe('a & b')})
|
||||
output = self.engine.render_to_string('wordcount02', {'a': 'a & b', 'b': mark_safe('a & b')})
|
||||
self.assertEqual(output, '3 3')
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ from django.template.defaultfilters import wordwrap
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class WordwrapTests(SimpleTestCase):
|
||||
|
@ -10,12 +10,12 @@ class WordwrapTests(SimpleTestCase):
|
|||
@setup({'wordwrap01':
|
||||
'{% autoescape off %}{{ a|wordwrap:"3" }} {{ b|wordwrap:"3" }}{% endautoescape %}'})
|
||||
def test_wordwrap01(self):
|
||||
output = render('wordwrap01', {'a': 'a & b', 'b': mark_safe('a & b')})
|
||||
output = self.engine.render_to_string('wordwrap01', {'a': 'a & b', 'b': mark_safe('a & b')})
|
||||
self.assertEqual(output, 'a &\nb a &\nb')
|
||||
|
||||
@setup({'wordwrap02': '{{ a|wordwrap:"3" }} {{ b|wordwrap:"3" }}'})
|
||||
def test_wordwrap02(self):
|
||||
output = render('wordwrap02', {'a': 'a & b', 'b': mark_safe('a & b')})
|
||||
output = self.engine.render_to_string('wordwrap02', {'a': 'a & b', 'b': mark_safe('a & b')})
|
||||
self.assertEqual(output, 'a &\nb a &\nb')
|
||||
|
||||
|
||||
|
|
|
@ -1,49 +1,49 @@
|
|||
from django.template.base import TemplateSyntaxError
|
||||
from django.template import TemplateSyntaxError
|
||||
from django.test import SimpleTestCase
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup, SafeClass, UnsafeClass
|
||||
from ..utils import setup, SafeClass, UnsafeClass
|
||||
|
||||
|
||||
class AutoescapeTagTests(SimpleTestCase):
|
||||
|
||||
@setup({'autoescape-tag01': '{% autoescape off %}hello{% endautoescape %}'})
|
||||
def test_autoescape_tag01(self):
|
||||
output = render('autoescape-tag01')
|
||||
output = self.engine.render_to_string('autoescape-tag01')
|
||||
self.assertEqual(output, 'hello')
|
||||
|
||||
@setup({'autoescape-tag02': '{% autoescape off %}{{ first }}{% endautoescape %}'})
|
||||
def test_autoescape_tag02(self):
|
||||
output = render('autoescape-tag02', {'first': '<b>hello</b>'})
|
||||
output = self.engine.render_to_string('autoescape-tag02', {'first': '<b>hello</b>'})
|
||||
self.assertEqual(output, '<b>hello</b>')
|
||||
|
||||
@setup({'autoescape-tag03': '{% autoescape on %}{{ first }}{% endautoescape %}'})
|
||||
def test_autoescape_tag03(self):
|
||||
output = render('autoescape-tag03', {'first': '<b>hello</b>'})
|
||||
output = self.engine.render_to_string('autoescape-tag03', {'first': '<b>hello</b>'})
|
||||
self.assertEqual(output, '<b>hello</b>')
|
||||
|
||||
# Autoescape disabling and enabling nest in a predictable way.
|
||||
@setup({'autoescape-tag04': '{% autoescape off %}'
|
||||
'{{ first }} {% autoescape on %}{{ first }}{% endautoescape %}{% endautoescape %}'})
|
||||
def test_autoescape_tag04(self):
|
||||
output = render('autoescape-tag04', {'first': '<a>'})
|
||||
output = self.engine.render_to_string('autoescape-tag04', {'first': '<a>'})
|
||||
self.assertEqual(output, '<a> <a>')
|
||||
|
||||
@setup({'autoescape-tag05': '{% autoescape on %}{{ first }}{% endautoescape %}'})
|
||||
def test_autoescape_tag05(self):
|
||||
output = render('autoescape-tag05', {'first': '<b>first</b>'})
|
||||
output = self.engine.render_to_string('autoescape-tag05', {'first': '<b>first</b>'})
|
||||
self.assertEqual(output, '<b>first</b>')
|
||||
|
||||
# Strings (ASCII or unicode) already marked as "safe" are not
|
||||
# auto-escaped
|
||||
@setup({'autoescape-tag06': '{{ first }}'})
|
||||
def test_autoescape_tag06(self):
|
||||
output = render('autoescape-tag06', {'first': mark_safe('<b>first</b>')})
|
||||
output = self.engine.render_to_string('autoescape-tag06', {'first': mark_safe('<b>first</b>')})
|
||||
self.assertEqual(output, '<b>first</b>')
|
||||
|
||||
@setup({'autoescape-tag07': '{% autoescape on %}{{ first }}{% endautoescape %}'})
|
||||
def test_autoescape_tag07(self):
|
||||
output = render('autoescape-tag07', {'first': mark_safe('<b>Apple</b>')})
|
||||
output = self.engine.render_to_string('autoescape-tag07', {'first': mark_safe('<b>Apple</b>')})
|
||||
self.assertEqual(output, '<b>Apple</b>')
|
||||
|
||||
@setup({'autoescape-tag08': r'{% autoescape on %}'
|
||||
|
@ -52,19 +52,19 @@ class AutoescapeTagTests(SimpleTestCase):
|
|||
"""
|
||||
Literal string arguments to filters, if used in the result, are safe.
|
||||
"""
|
||||
output = render('autoescape-tag08', {"var": None})
|
||||
output = self.engine.render_to_string('autoescape-tag08', {"var": None})
|
||||
self.assertEqual(output, ' endquote" hah')
|
||||
|
||||
# Objects which return safe strings as their __str__ method
|
||||
# won't get double-escaped.
|
||||
@setup({'autoescape-tag09': r'{{ unsafe }}'})
|
||||
def test_autoescape_tag09(self):
|
||||
output = render('autoescape-tag09', {'unsafe': UnsafeClass()})
|
||||
output = self.engine.render_to_string('autoescape-tag09', {'unsafe': UnsafeClass()})
|
||||
self.assertEqual(output, 'you & me')
|
||||
|
||||
@setup({'autoescape-tag10': r'{{ safe }}'})
|
||||
def test_autoescape_tag10(self):
|
||||
output = render('autoescape-tag10', {'safe': SafeClass()})
|
||||
output = self.engine.render_to_string('autoescape-tag10', {'safe': SafeClass()})
|
||||
self.assertEqual(output, 'you > me')
|
||||
|
||||
@setup({'autoescape-filtertag01': '{{ first }}{% filter safe %}{{ first }} x<y{% endfilter %}'})
|
||||
|
@ -75,25 +75,25 @@ class AutoescapeTagTests(SimpleTestCase):
|
|||
tags can be used in those cases)
|
||||
"""
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
render('autoescape-filtertag01', {'first': '<a>'})
|
||||
self.engine.render_to_string('autoescape-filtertag01', {'first': '<a>'})
|
||||
|
||||
@setup({'autoescape-ifequal01': '{% ifequal var "this & that" %}yes{% endifequal %}'})
|
||||
def test_autoescape_ifequal01(self):
|
||||
"""
|
||||
ifequal compares unescaped vales.
|
||||
"""
|
||||
output = render('autoescape-ifequal01', {'var': 'this & that'})
|
||||
output = self.engine.render_to_string('autoescape-ifequal01', {'var': 'this & that'})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
# Arguments to filters are 'safe' and manipulate their input unescaped.
|
||||
@setup({'autoescape-filters01': '{{ var|cut:"&" }}'})
|
||||
def test_autoescape_filters01(self):
|
||||
output = render('autoescape-filters01', {'var': 'this & that'})
|
||||
output = self.engine.render_to_string('autoescape-filters01', {'var': 'this & that'})
|
||||
self.assertEqual(output, 'this that')
|
||||
|
||||
@setup({'autoescape-filters02': '{{ var|join:" & " }}'})
|
||||
def test_autoescape_filters02(self):
|
||||
output = render('autoescape-filters02', {'var': ('Tom', 'Dick', 'Harry')})
|
||||
output = self.engine.render_to_string('autoescape-filters02', {'var': ('Tom', 'Dick', 'Harry')})
|
||||
self.assertEqual(output, 'Tom & Dick & Harry')
|
||||
|
||||
@setup({'autoescape-literals01': '{{ "this & that" }}'})
|
||||
|
@ -101,7 +101,7 @@ class AutoescapeTagTests(SimpleTestCase):
|
|||
"""
|
||||
Literal strings are safe.
|
||||
"""
|
||||
output = render('autoescape-literals01')
|
||||
output = self.engine.render_to_string('autoescape-literals01')
|
||||
self.assertEqual(output, 'this & that')
|
||||
|
||||
@setup({'autoescape-stringiterations01': '{% for l in var %}{{ l }},{% endfor %}'})
|
||||
|
@ -109,7 +109,7 @@ class AutoescapeTagTests(SimpleTestCase):
|
|||
"""
|
||||
Iterating over strings outputs safe characters.
|
||||
"""
|
||||
output = render('autoescape-stringiterations01', {'var': 'K&R'})
|
||||
output = self.engine.render_to_string('autoescape-stringiterations01', {'var': 'K&R'})
|
||||
self.assertEqual(output, 'K,&,R,')
|
||||
|
||||
@setup({'autoescape-lookup01': '{{ var.key }}'})
|
||||
|
@ -117,5 +117,5 @@ class AutoescapeTagTests(SimpleTestCase):
|
|||
"""
|
||||
Escape requirement survives lookup.
|
||||
"""
|
||||
output = render('autoescape-lookup01', {'var': {'key': 'this & that'}})
|
||||
output = self.engine.render_to_string('autoescape-lookup01', {'var': {'key': 'this & that'}})
|
||||
self.assertEqual(output, 'this & that')
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
from django.conf import settings
|
||||
from django.template.base import Context, TemplateSyntaxError
|
||||
from django.template.loader import get_template
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup, SilentGetItemClass, SilentAttrClass, SomeClass
|
||||
from ..utils import setup, SilentGetItemClass, SilentAttrClass, SomeClass
|
||||
|
||||
|
||||
basic_templates = {
|
||||
|
@ -20,7 +18,7 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
"""
|
||||
Plain text should go through the template parser untouched.
|
||||
"""
|
||||
output = render('basic-syntax01')
|
||||
output = self.engine.render_to_string('basic-syntax01')
|
||||
self.assertEqual(output, "something cool")
|
||||
|
||||
@setup(basic_templates)
|
||||
|
@ -29,7 +27,7 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
Variables should be replaced with their value in the current
|
||||
context
|
||||
"""
|
||||
output = render('basic-syntax02', {'headline': 'Success'})
|
||||
output = self.engine.render_to_string('basic-syntax02', {'headline': 'Success'})
|
||||
self.assertEqual(output, 'Success')
|
||||
|
||||
@setup(basic_templates)
|
||||
|
@ -37,7 +35,7 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
"""
|
||||
More than one replacement variable is allowed in a template
|
||||
"""
|
||||
output = render('basic-syntax03', {"first": 1, "second": 2})
|
||||
output = self.engine.render_to_string('basic-syntax03', {"first": 1, "second": 2})
|
||||
self.assertEqual(output, '1 --- 2')
|
||||
|
||||
@setup({'basic-syntax04': 'as{{ missing }}df'})
|
||||
|
@ -45,8 +43,8 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
"""
|
||||
Fail silently when a variable is not found in the current context
|
||||
"""
|
||||
output = render('basic-syntax04')
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
output = self.engine.render_to_string('basic-syntax04')
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, 'asINVALIDdf')
|
||||
else:
|
||||
self.assertEqual(output, 'asdf')
|
||||
|
@ -57,7 +55,7 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
A variable may not contain more than one word
|
||||
"""
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('basic-syntax06')
|
||||
self.engine.get_template('basic-syntax06')
|
||||
|
||||
@setup({'basic-syntax07': '{{ }}'})
|
||||
def test_basic_syntax07(self):
|
||||
|
@ -65,7 +63,7 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
Raise TemplateSyntaxError for empty variable tags.
|
||||
"""
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('basic-syntax07')
|
||||
self.engine.get_template('basic-syntax07')
|
||||
|
||||
@setup({'basic-syntax08': '{{ }}'})
|
||||
def test_basic_syntax08(self):
|
||||
|
@ -73,14 +71,14 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
Raise TemplateSyntaxError for empty variable tags.
|
||||
"""
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('basic-syntax08')
|
||||
self.engine.get_template('basic-syntax08')
|
||||
|
||||
@setup({'basic-syntax09': '{{ var.method }}'})
|
||||
def test_basic_syntax09(self):
|
||||
"""
|
||||
Attribute syntax allows a template to call an object's attribute
|
||||
"""
|
||||
output = render('basic-syntax09', {'var': SomeClass()})
|
||||
output = self.engine.render_to_string('basic-syntax09', {'var': SomeClass()})
|
||||
self.assertEqual(output, 'SomeClass.method')
|
||||
|
||||
@setup({'basic-syntax10': '{{ var.otherclass.method }}'})
|
||||
|
@ -88,7 +86,7 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
"""
|
||||
Multiple levels of attribute access are allowed.
|
||||
"""
|
||||
output = render('basic-syntax10', {'var': SomeClass()})
|
||||
output = self.engine.render_to_string('basic-syntax10', {'var': SomeClass()})
|
||||
self.assertEqual(output, 'OtherClass.method')
|
||||
|
||||
@setup({'basic-syntax11': '{{ var.blech }}'})
|
||||
|
@ -96,9 +94,9 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
"""
|
||||
Fail silently when a variable's attribute isn't found.
|
||||
"""
|
||||
output = render('basic-syntax11', {'var': SomeClass()})
|
||||
output = self.engine.render_to_string('basic-syntax11', {'var': SomeClass()})
|
||||
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, 'INVALID')
|
||||
else:
|
||||
self.assertEqual(output, '')
|
||||
|
@ -110,34 +108,34 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
beginning with an underscore.
|
||||
"""
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('basic-syntax12')
|
||||
self.engine.get_template('basic-syntax12')
|
||||
|
||||
# Raise TemplateSyntaxError when trying to access a variable
|
||||
# containing an illegal character.
|
||||
@setup({'basic-syntax13': "{{ va>r }}"})
|
||||
def test_basic_syntax13(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('basic-syntax13')
|
||||
self.engine.get_template('basic-syntax13')
|
||||
|
||||
@setup({'basic-syntax14': "{{ (var.r) }}"})
|
||||
def test_basic_syntax14(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('basic-syntax14')
|
||||
self.engine.get_template('basic-syntax14')
|
||||
|
||||
@setup({'basic-syntax15': "{{ sp%am }}"})
|
||||
def test_basic_syntax15(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('basic-syntax15')
|
||||
self.engine.get_template('basic-syntax15')
|
||||
|
||||
@setup({'basic-syntax16': "{{ eggs! }}"})
|
||||
def test_basic_syntax16(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('basic-syntax16')
|
||||
self.engine.get_template('basic-syntax16')
|
||||
|
||||
@setup({'basic-syntax17': "{{ moo? }}"})
|
||||
def test_basic_syntax17(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('basic-syntax17')
|
||||
self.engine.get_template('basic-syntax17')
|
||||
|
||||
@setup({'basic-syntax18': "{{ foo.bar }}"})
|
||||
def test_basic_syntax18(self):
|
||||
|
@ -145,7 +143,7 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
Attribute syntax allows a template to call a dictionary key's
|
||||
value.
|
||||
"""
|
||||
output = render('basic-syntax18', {"foo": {"bar": "baz"}})
|
||||
output = self.engine.render_to_string('basic-syntax18', {"foo": {"bar": "baz"}})
|
||||
self.assertEqual(output, "baz")
|
||||
|
||||
@setup({'basic-syntax19': "{{ foo.spam }}"})
|
||||
|
@ -153,9 +151,9 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
"""
|
||||
Fail silently when a variable's dictionary key isn't found.
|
||||
"""
|
||||
output = render('basic-syntax19', {"foo": {"bar": "baz"}})
|
||||
output = self.engine.render_to_string('basic-syntax19', {"foo": {"bar": "baz"}})
|
||||
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, 'INVALID')
|
||||
else:
|
||||
self.assertEqual(output, '')
|
||||
|
@ -165,9 +163,9 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
"""
|
||||
Fail silently when accessing a non-simple method
|
||||
"""
|
||||
output = render('basic-syntax20', {'var': SomeClass()})
|
||||
output = self.engine.render_to_string('basic-syntax20', {'var': SomeClass()})
|
||||
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, 'INVALID')
|
||||
else:
|
||||
self.assertEqual(output, '')
|
||||
|
@ -177,7 +175,7 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
"""
|
||||
Don't silence a TypeError if it was raised inside a callable.
|
||||
"""
|
||||
template = get_template('basic-syntax20b')
|
||||
template = self.engine.get_template('basic-syntax20b')
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
template.render(Context({'var': SomeClass()}))
|
||||
|
@ -186,12 +184,12 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
# quite, a template tag.
|
||||
@setup({'basic-syntax21': "a {{ moo %} b"})
|
||||
def test_basic_syntax21(self):
|
||||
output = render('basic-syntax21')
|
||||
output = self.engine.render_to_string('basic-syntax21')
|
||||
self.assertEqual(output, "a {{ moo %} b")
|
||||
|
||||
@setup({'basic-syntax22': "{{ moo #}"})
|
||||
def test_basic_syntax22(self):
|
||||
output = render('basic-syntax22')
|
||||
output = self.engine.render_to_string('basic-syntax22')
|
||||
self.assertEqual(output, "{{ moo #}")
|
||||
|
||||
@setup({'basic-syntax23': "{{ moo #} {{ cow }}"})
|
||||
|
@ -201,47 +199,47 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
around, so this triggers an error.
|
||||
"""
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('basic-syntax23')
|
||||
self.engine.get_template('basic-syntax23')
|
||||
|
||||
@setup({'basic-syntax24': "{{ moo\n }}"})
|
||||
def test_basic_syntax24(self):
|
||||
"""
|
||||
Embedded newlines make it not-a-tag.
|
||||
"""
|
||||
output = render('basic-syntax24')
|
||||
output = self.engine.render_to_string('basic-syntax24')
|
||||
self.assertEqual(output, "{{ moo\n }}")
|
||||
|
||||
# Literal strings are permitted inside variables, mostly for i18n
|
||||
# purposes.
|
||||
@setup({'basic-syntax25': '{{ "fred" }}'})
|
||||
def test_basic_syntax25(self):
|
||||
output = render('basic-syntax25')
|
||||
output = self.engine.render_to_string('basic-syntax25')
|
||||
self.assertEqual(output, "fred")
|
||||
|
||||
@setup({'basic-syntax26': r'{{ "\"fred\"" }}'})
|
||||
def test_basic_syntax26(self):
|
||||
output = render('basic-syntax26')
|
||||
output = self.engine.render_to_string('basic-syntax26')
|
||||
self.assertEqual(output, "\"fred\"")
|
||||
|
||||
@setup({'basic-syntax27': r'{{ _("\"fred\"") }}'})
|
||||
def test_basic_syntax27(self):
|
||||
output = render('basic-syntax27')
|
||||
output = self.engine.render_to_string('basic-syntax27')
|
||||
self.assertEqual(output, "\"fred\"")
|
||||
|
||||
# #12554 -- Make sure a silent_variable_failure Exception is
|
||||
# suppressed on dictionary and attribute lookup.
|
||||
@setup({'basic-syntax28': "{{ a.b }}"})
|
||||
def test_basic_syntax28(self):
|
||||
output = render('basic-syntax28', {'a': SilentGetItemClass()})
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
output = self.engine.render_to_string('basic-syntax28', {'a': SilentGetItemClass()})
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, 'INVALID')
|
||||
else:
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'basic-syntax29': "{{ a.b }}"})
|
||||
def test_basic_syntax29(self):
|
||||
output = render('basic-syntax29', {'a': SilentAttrClass()})
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
output = self.engine.render_to_string('basic-syntax29', {'a': SilentAttrClass()})
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, 'INVALID')
|
||||
else:
|
||||
self.assertEqual(output, '')
|
||||
|
@ -250,7 +248,7 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
# as a lookup.
|
||||
@setup({'basic-syntax30': "{{ 1.2.3 }}"})
|
||||
def test_basic_syntax30(self):
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'basic-syntax30',
|
||||
{"1": {"2": {"3": "d"}}}
|
||||
)
|
||||
|
@ -258,7 +256,7 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
|
||||
@setup({'basic-syntax31': "{{ 1.2.3 }}"})
|
||||
def test_basic_syntax31(self):
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'basic-syntax31',
|
||||
{"1": {"2": ("a", "b", "c", "d")}},
|
||||
)
|
||||
|
@ -266,7 +264,7 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
|
||||
@setup({'basic-syntax32': "{{ 1.2.3 }}"})
|
||||
def test_basic_syntax32(self):
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'basic-syntax32',
|
||||
{"1": (("x", "x", "x", "x"), ("y", "y", "y", "y"), ("a", "b", "c", "d"))},
|
||||
)
|
||||
|
@ -274,7 +272,7 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
|
||||
@setup({'basic-syntax33': "{{ 1.2.3 }}"})
|
||||
def test_basic_syntax33(self):
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'basic-syntax33',
|
||||
{"1": ("xxxx", "yyyy", "abcd")},
|
||||
)
|
||||
|
@ -282,7 +280,7 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
|
||||
@setup({'basic-syntax34': "{{ 1.2.3 }}"})
|
||||
def test_basic_syntax34(self):
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'basic-syntax34',
|
||||
{"1": ({"x": "x"}, {"y": "y"}, {"z": "z", "3": "d"})}
|
||||
)
|
||||
|
@ -291,12 +289,12 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
# Numbers are numbers even if their digits are in the context.
|
||||
@setup({'basic-syntax35': "{{ 1 }}"})
|
||||
def test_basic_syntax35(self):
|
||||
output = render('basic-syntax35', {"1": "abc"})
|
||||
output = self.engine.render_to_string('basic-syntax35', {"1": "abc"})
|
||||
self.assertEqual(output, '1')
|
||||
|
||||
@setup({'basic-syntax36': "{{ 1.2 }}"})
|
||||
def test_basic_syntax36(self):
|
||||
output = render('basic-syntax36', {"1": "abc"})
|
||||
output = self.engine.render_to_string('basic-syntax36', {"1": "abc"})
|
||||
self.assertEqual(output, '1.2')
|
||||
|
||||
@setup({'basic-syntax37': '{{ callable }}'})
|
||||
|
@ -304,7 +302,7 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
"""
|
||||
Call methods in the top level of the context.
|
||||
"""
|
||||
output = render('basic-syntax37', {"callable": lambda: "foo bar"})
|
||||
output = self.engine.render_to_string('basic-syntax37', {"callable": lambda: "foo bar"})
|
||||
self.assertEqual(output, 'foo bar')
|
||||
|
||||
@setup({'basic-syntax38': '{{ var.callable }}'})
|
||||
|
@ -312,5 +310,5 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
"""
|
||||
Call methods returned from dictionary lookups.
|
||||
"""
|
||||
output = render('basic-syntax38', {"var": {"callable": lambda: "foo bar"}})
|
||||
output = self.engine.render_to_string('basic-syntax38', {"var": {"callable": lambda: "foo bar"}})
|
||||
self.assertEqual(output, 'foo bar')
|
||||
|
|
|
@ -1,18 +1,21 @@
|
|||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class BuiltinsTests(SimpleTestCase):
|
||||
|
||||
@setup({'builtins01': '{{ True }}'})
|
||||
def test_builtins01(self):
|
||||
self.assertEqual(render('builtins01'), 'True')
|
||||
output = self.engine.render_to_string('builtins01')
|
||||
self.assertEqual(output, 'True')
|
||||
|
||||
@setup({'builtins02': '{{ False }}'})
|
||||
def test_builtins02(self):
|
||||
self.assertEqual(render('builtins02'), 'False')
|
||||
output = self.engine.render_to_string('builtins02')
|
||||
self.assertEqual(output, 'False')
|
||||
|
||||
@setup({'builtins03': '{{ None }}'})
|
||||
def test_builtins03(self):
|
||||
self.assertEqual(render('builtins03'), 'None')
|
||||
output = self.engine.render_to_string('builtins03')
|
||||
self.assertEqual(output, 'None')
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
from django.core.cache import cache
|
||||
from django.template.base import TemplateSyntaxError
|
||||
from django.template.loader import get_template
|
||||
from django.template import TemplateSyntaxError
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class CacheTagTests(SimpleTestCase):
|
||||
|
@ -13,7 +12,7 @@ class CacheTagTests(SimpleTestCase):
|
|||
|
||||
@setup({'cache03': '{% load cache %}{% cache 2 test %}cache03{% endcache %}'})
|
||||
def test_cache03(self):
|
||||
output = render('cache03')
|
||||
output = self.engine.render_to_string('cache03')
|
||||
self.assertEqual(output, 'cache03')
|
||||
|
||||
@setup({
|
||||
|
@ -21,18 +20,18 @@ class CacheTagTests(SimpleTestCase):
|
|||
'cache04': '{% load cache %}{% cache 2 test %}cache04{% endcache %}',
|
||||
})
|
||||
def test_cache04(self):
|
||||
render('cache03')
|
||||
output = render('cache04')
|
||||
self.engine.render_to_string('cache03')
|
||||
output = self.engine.render_to_string('cache04')
|
||||
self.assertEqual(output, 'cache03')
|
||||
|
||||
@setup({'cache05': '{% load cache %}{% cache 2 test foo %}cache05{% endcache %}'})
|
||||
def test_cache05(self):
|
||||
output = render('cache05', {'foo': 1})
|
||||
output = self.engine.render_to_string('cache05', {'foo': 1})
|
||||
self.assertEqual(output, 'cache05')
|
||||
|
||||
@setup({'cache06': '{% load cache %}{% cache 2 test foo %}cache06{% endcache %}'})
|
||||
def test_cache06(self):
|
||||
output = render('cache06', {'foo': 2})
|
||||
output = self.engine.render_to_string('cache06', {'foo': 2})
|
||||
self.assertEqual(output, 'cache06')
|
||||
|
||||
@setup({
|
||||
|
@ -41,8 +40,8 @@ class CacheTagTests(SimpleTestCase):
|
|||
})
|
||||
def test_cache07(self):
|
||||
context = {'foo': 1}
|
||||
render('cache05', context)
|
||||
output = render('cache07', context)
|
||||
self.engine.render_to_string('cache05', context)
|
||||
output = self.engine.render_to_string('cache07', context)
|
||||
self.assertEqual(output, 'cache05')
|
||||
|
||||
@setup({
|
||||
|
@ -54,42 +53,42 @@ class CacheTagTests(SimpleTestCase):
|
|||
Allow first argument to be a variable.
|
||||
"""
|
||||
context = {'foo': 2, 'time': 2}
|
||||
render('cache06', context)
|
||||
output = render('cache08', context)
|
||||
self.engine.render_to_string('cache06', context)
|
||||
output = self.engine.render_to_string('cache08', context)
|
||||
self.assertEqual(output, 'cache06')
|
||||
|
||||
# Raise exception if we don't have at least 2 args, first one integer.
|
||||
@setup({'cache11': '{% load cache %}{% cache %}{% endcache %}'})
|
||||
def test_cache11(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('cache11')
|
||||
self.engine.get_template('cache11')
|
||||
|
||||
@setup({'cache12': '{% load cache %}{% cache 1 %}{% endcache %}'})
|
||||
def test_cache12(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('cache12')
|
||||
self.engine.get_template('cache12')
|
||||
|
||||
@setup({'cache13': '{% load cache %}{% cache foo bar %}{% endcache %}'})
|
||||
def test_cache13(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
render('cache13')
|
||||
self.engine.render_to_string('cache13')
|
||||
|
||||
@setup({'cache14': '{% load cache %}{% cache foo bar %}{% endcache %}'})
|
||||
def test_cache14(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
render('cache14', {'foo': 'fail'})
|
||||
self.engine.render_to_string('cache14', {'foo': 'fail'})
|
||||
|
||||
@setup({'cache15': '{% load cache %}{% cache foo bar %}{% endcache %}'})
|
||||
def test_cache15(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
render('cache15', {'foo': []})
|
||||
self.engine.render_to_string('cache15', {'foo': []})
|
||||
|
||||
@setup({'cache16': '{% load cache %}{% cache 1 foo bar %}{% endcache %}'})
|
||||
def test_cache16(self):
|
||||
"""
|
||||
Regression test for #7460.
|
||||
"""
|
||||
output = render('cache16', {'foo': 'foo', 'bar': 'with spaces'})
|
||||
output = self.engine.render_to_string('cache16', {'foo': 'foo', 'bar': 'with spaces'})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'cache17': '{% load cache %}{% cache 10 long_cache_key poem %}Some Content{% endcache %}'})
|
||||
|
@ -97,7 +96,7 @@ class CacheTagTests(SimpleTestCase):
|
|||
"""
|
||||
Regression test for #11270.
|
||||
"""
|
||||
output = render('cache17', {'poem': 'Oh freddled gruntbuggly/'
|
||||
output = self.engine.render_to_string('cache17', {'poem': 'Oh freddled gruntbuggly/'
|
||||
'Thy micturations are to me/'
|
||||
'As plurdled gabbleblotchits/'
|
||||
'On a lurgid bee/'
|
||||
|
@ -114,5 +113,5 @@ class CacheTagTests(SimpleTestCase):
|
|||
"""
|
||||
Test whitespace in filter arguments
|
||||
"""
|
||||
output = render('cache18')
|
||||
output = self.engine.render_to_string('cache18')
|
||||
self.assertEqual(output, 'cache18')
|
||||
|
|
|
@ -1,92 +1,92 @@
|
|||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class CommentSyntaxTests(SimpleTestCase):
|
||||
|
||||
@setup({'comment-syntax01': '{# this is hidden #}hello'})
|
||||
def test_comment_syntax01(self):
|
||||
output = render('comment-syntax01')
|
||||
output = self.engine.render_to_string('comment-syntax01')
|
||||
self.assertEqual(output, 'hello')
|
||||
|
||||
@setup({'comment-syntax02': '{# this is hidden #}hello{# foo #}'})
|
||||
def test_comment_syntax02(self):
|
||||
output = render('comment-syntax02')
|
||||
output = self.engine.render_to_string('comment-syntax02')
|
||||
self.assertEqual(output, 'hello')
|
||||
|
||||
@setup({'comment-syntax03': 'foo{# {% if %} #}'})
|
||||
def test_comment_syntax03(self):
|
||||
output = render('comment-syntax03')
|
||||
output = self.engine.render_to_string('comment-syntax03')
|
||||
self.assertEqual(output, 'foo')
|
||||
|
||||
@setup({'comment-syntax04': 'foo{# {% endblock %} #}'})
|
||||
def test_comment_syntax04(self):
|
||||
output = render('comment-syntax04')
|
||||
output = self.engine.render_to_string('comment-syntax04')
|
||||
self.assertEqual(output, 'foo')
|
||||
|
||||
@setup({'comment-syntax05': 'foo{# {% somerandomtag %} #}'})
|
||||
def test_comment_syntax05(self):
|
||||
output = render('comment-syntax05')
|
||||
output = self.engine.render_to_string('comment-syntax05')
|
||||
self.assertEqual(output, 'foo')
|
||||
|
||||
@setup({'comment-syntax06': 'foo{# {% #}'})
|
||||
def test_comment_syntax06(self):
|
||||
output = render('comment-syntax06')
|
||||
output = self.engine.render_to_string('comment-syntax06')
|
||||
self.assertEqual(output, 'foo')
|
||||
|
||||
@setup({'comment-syntax07': 'foo{# %} #}'})
|
||||
def test_comment_syntax07(self):
|
||||
output = render('comment-syntax07')
|
||||
output = self.engine.render_to_string('comment-syntax07')
|
||||
self.assertEqual(output, 'foo')
|
||||
|
||||
@setup({'comment-syntax08': 'foo{# %} #}bar'})
|
||||
def test_comment_syntax08(self):
|
||||
output = render('comment-syntax08')
|
||||
output = self.engine.render_to_string('comment-syntax08')
|
||||
self.assertEqual(output, 'foobar')
|
||||
|
||||
@setup({'comment-syntax09': 'foo{# {{ #}'})
|
||||
def test_comment_syntax09(self):
|
||||
output = render('comment-syntax09')
|
||||
output = self.engine.render_to_string('comment-syntax09')
|
||||
self.assertEqual(output, 'foo')
|
||||
|
||||
@setup({'comment-syntax10': 'foo{# }} #}'})
|
||||
def test_comment_syntax10(self):
|
||||
output = render('comment-syntax10')
|
||||
output = self.engine.render_to_string('comment-syntax10')
|
||||
self.assertEqual(output, 'foo')
|
||||
|
||||
@setup({'comment-syntax11': 'foo{# { #}'})
|
||||
def test_comment_syntax11(self):
|
||||
output = render('comment-syntax11')
|
||||
output = self.engine.render_to_string('comment-syntax11')
|
||||
self.assertEqual(output, 'foo')
|
||||
|
||||
@setup({'comment-syntax12': 'foo{# } #}'})
|
||||
def test_comment_syntax12(self):
|
||||
output = render('comment-syntax12')
|
||||
output = self.engine.render_to_string('comment-syntax12')
|
||||
self.assertEqual(output, 'foo')
|
||||
|
||||
@setup({'comment-tag01': '{% comment %}this is hidden{% endcomment %}hello'})
|
||||
def test_comment_tag01(self):
|
||||
output = render('comment-tag01')
|
||||
output = self.engine.render_to_string('comment-tag01')
|
||||
self.assertEqual(output, 'hello')
|
||||
|
||||
@setup({'comment-tag02': '{% comment %}this is hidden{% endcomment %}'
|
||||
'hello{% comment %}foo{% endcomment %}'})
|
||||
def test_comment_tag02(self):
|
||||
output = render('comment-tag02')
|
||||
output = self.engine.render_to_string('comment-tag02')
|
||||
self.assertEqual(output, 'hello')
|
||||
|
||||
@setup({'comment-tag03': 'foo{% comment %} {% if %} {% endcomment %}'})
|
||||
def test_comment_tag03(self):
|
||||
output = render('comment-tag03')
|
||||
output = self.engine.render_to_string('comment-tag03')
|
||||
self.assertEqual(output, 'foo')
|
||||
|
||||
@setup({'comment-tag04': 'foo{% comment %} {% endblock %} {% endcomment %}'})
|
||||
def test_comment_tag04(self):
|
||||
output = render('comment-tag04')
|
||||
output = self.engine.render_to_string('comment-tag04')
|
||||
self.assertEqual(output, 'foo')
|
||||
|
||||
@setup({'comment-tag05': 'foo{% comment %} {% somerandomtag %} {% endcomment %}'})
|
||||
def test_comment_tag05(self):
|
||||
output = render('comment-tag05')
|
||||
output = self.engine.render_to_string('comment-tag05')
|
||||
self.assertEqual(output, 'foo')
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
import warnings
|
||||
|
||||
from django.template.base import TemplateSyntaxError
|
||||
from django.template.loader import get_template
|
||||
from django.template import TemplateSyntaxError
|
||||
from django.test import SimpleTestCase
|
||||
from django.utils.deprecation import RemovedInDjango20Warning
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class CycleTagTests(SimpleTestCase):
|
||||
|
@ -13,119 +12,119 @@ class CycleTagTests(SimpleTestCase):
|
|||
@setup({'cycle01': '{% cycle a %}'})
|
||||
def test_cycle01(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('cycle01')
|
||||
self.engine.get_template('cycle01')
|
||||
|
||||
@setup({'cycle02': '{% cycle a,b,c as abc %}{% cycle abc %}'})
|
||||
def test_cycle02(self):
|
||||
output = render('cycle02')
|
||||
output = self.engine.render_to_string('cycle02')
|
||||
self.assertEqual(output, 'ab')
|
||||
|
||||
@setup({'cycle03': '{% cycle a,b,c as abc %}{% cycle abc %}{% cycle abc %}'})
|
||||
def test_cycle03(self):
|
||||
output = render('cycle03')
|
||||
output = self.engine.render_to_string('cycle03')
|
||||
self.assertEqual(output, 'abc')
|
||||
|
||||
@setup({'cycle04': '{% cycle a,b,c as abc %}{% cycle abc %}{% cycle abc %}{% cycle abc %}'})
|
||||
def test_cycle04(self):
|
||||
output = render('cycle04')
|
||||
output = self.engine.render_to_string('cycle04')
|
||||
self.assertEqual(output, 'abca')
|
||||
|
||||
@setup({'cycle05': '{% cycle %}'})
|
||||
def test_cycle05(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('cycle05')
|
||||
self.engine.get_template('cycle05')
|
||||
|
||||
@setup({'cycle06': '{% cycle a %}'})
|
||||
def test_cycle06(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('cycle06')
|
||||
self.engine.get_template('cycle06')
|
||||
|
||||
@setup({'cycle07': '{% cycle a,b,c as foo %}{% cycle bar %}'})
|
||||
def test_cycle07(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('cycle07')
|
||||
self.engine.get_template('cycle07')
|
||||
|
||||
@setup({'cycle08': '{% cycle a,b,c as foo %}{% cycle foo %}{{ foo }}{{ foo }}{% cycle foo %}{{ foo }}'})
|
||||
def test_cycle08(self):
|
||||
output = render('cycle08')
|
||||
output = self.engine.render_to_string('cycle08')
|
||||
self.assertEqual(output, 'abbbcc')
|
||||
|
||||
@setup({'cycle09': '{% for i in test %}{% cycle a,b %}{{ i }},{% endfor %}'})
|
||||
def test_cycle09(self):
|
||||
output = render('cycle09', {'test': list(range(5))})
|
||||
output = self.engine.render_to_string('cycle09', {'test': list(range(5))})
|
||||
self.assertEqual(output, 'a0,b1,a2,b3,a4,')
|
||||
|
||||
@setup({'cycle10': "{% cycle 'a' 'b' 'c' as abc %}{% cycle abc %}"})
|
||||
def test_cycle10(self):
|
||||
output = render('cycle10')
|
||||
output = self.engine.render_to_string('cycle10')
|
||||
self.assertEqual(output, 'ab')
|
||||
|
||||
@setup({'cycle11': "{% cycle 'a' 'b' 'c' as abc %}{% cycle abc %}{% cycle abc %}"})
|
||||
def test_cycle11(self):
|
||||
output = render('cycle11')
|
||||
output = self.engine.render_to_string('cycle11')
|
||||
self.assertEqual(output, 'abc')
|
||||
|
||||
@setup({'cycle12': "{% cycle 'a' 'b' 'c' as abc %}{% cycle abc %}{% cycle abc %}{% cycle abc %}"})
|
||||
def test_cycle12(self):
|
||||
output = render('cycle12')
|
||||
output = self.engine.render_to_string('cycle12')
|
||||
self.assertEqual(output, 'abca')
|
||||
|
||||
@setup({'cycle13': "{% for i in test %}{% cycle 'a' 'b' %}{{ i }},{% endfor %}"})
|
||||
def test_cycle13(self):
|
||||
output = render('cycle13', {'test': list(range(5))})
|
||||
output = self.engine.render_to_string('cycle13', {'test': list(range(5))})
|
||||
self.assertEqual(output, 'a0,b1,a2,b3,a4,')
|
||||
|
||||
@setup({'cycle14': '{% cycle one two as foo %}{% cycle foo %}'})
|
||||
def test_cycle14(self):
|
||||
output = render('cycle14', {'one': '1', 'two': '2'})
|
||||
output = self.engine.render_to_string('cycle14', {'one': '1', 'two': '2'})
|
||||
self.assertEqual(output, '12')
|
||||
|
||||
@setup({'cycle15': '{% for i in test %}{% cycle aye bee %}{{ i }},{% endfor %}'})
|
||||
def test_cycle15(self):
|
||||
output = render('cycle15', {'test': list(range(5)), 'aye': 'a', 'bee': 'b'})
|
||||
output = self.engine.render_to_string('cycle15', {'test': list(range(5)), 'aye': 'a', 'bee': 'b'})
|
||||
self.assertEqual(output, 'a0,b1,a2,b3,a4,')
|
||||
|
||||
@setup({'cycle16': '{% cycle one|lower two as foo %}{% cycle foo %}'})
|
||||
def test_cycle16(self):
|
||||
output = render('cycle16', {'one': 'A', 'two': '2'})
|
||||
output = self.engine.render_to_string('cycle16', {'one': 'A', 'two': '2'})
|
||||
self.assertEqual(output, 'a2')
|
||||
|
||||
@setup({'cycle17': "{% cycle 'a' 'b' 'c' as abc silent %}"
|
||||
"{% cycle abc %}{% cycle abc %}{% cycle abc %}{% cycle abc %}"})
|
||||
def test_cycle17(self):
|
||||
output = render('cycle17')
|
||||
output = self.engine.render_to_string('cycle17')
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'cycle18': "{% cycle 'a' 'b' 'c' as foo invalid_flag %}"})
|
||||
def test_cycle18(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('cycle18')
|
||||
self.engine.get_template('cycle18')
|
||||
|
||||
@setup({'cycle19': "{% cycle 'a' 'b' as silent %}{% cycle silent %}"})
|
||||
def test_cycle19(self):
|
||||
output = render('cycle19')
|
||||
output = self.engine.render_to_string('cycle19')
|
||||
self.assertEqual(output, 'ab')
|
||||
|
||||
@setup({'cycle20': '{% cycle one two as foo %} & {% cycle foo %}'})
|
||||
def test_cycle20(self):
|
||||
output = render('cycle20', {'two': 'C & D', 'one': 'A & B'})
|
||||
output = self.engine.render_to_string('cycle20', {'two': 'C & D', 'one': 'A & B'})
|
||||
self.assertEqual(output, 'A & B & C & D')
|
||||
|
||||
@setup({'cycle21': '{% filter force_escape %}'
|
||||
'{% cycle one two as foo %} & {% cycle foo %}{% endfilter %}'})
|
||||
def test_cycle21(self):
|
||||
output = render('cycle21', {'two': 'C & D', 'one': 'A & B'})
|
||||
output = self.engine.render_to_string('cycle21', {'two': 'C & D', 'one': 'A & B'})
|
||||
self.assertEqual(output, 'A &amp; B & C &amp; D')
|
||||
|
||||
@setup({'cycle22': "{% for x in values %}{% cycle 'a' 'b' 'c' as abc silent %}{{ x }}{% endfor %}"})
|
||||
def test_cycle22(self):
|
||||
output = render('cycle22', {'values': [1, 2, 3, 4]})
|
||||
output = self.engine.render_to_string('cycle22', {'values': [1, 2, 3, 4]})
|
||||
self.assertEqual(output, '1234')
|
||||
|
||||
@setup({'cycle23': "{% for x in values %}"
|
||||
"{% cycle 'a' 'b' 'c' as abc silent %}{{ abc }}{{ x }}{% endfor %}"})
|
||||
def test_cycle23(self):
|
||||
output = render('cycle23', {'values': [1, 2, 3, 4]})
|
||||
output = self.engine.render_to_string('cycle23', {'values': [1, 2, 3, 4]})
|
||||
self.assertEqual(output, 'a1b2c3a4')
|
||||
|
||||
@setup({
|
||||
|
@ -134,19 +133,19 @@ class CycleTagTests(SimpleTestCase):
|
|||
'included-cycle': '{{ abc }}',
|
||||
})
|
||||
def test_cycle24(self):
|
||||
output = render('cycle24', {'values': [1, 2, 3, 4]})
|
||||
output = self.engine.render_to_string('cycle24', {'values': [1, 2, 3, 4]})
|
||||
self.assertEqual(output, 'abca')
|
||||
|
||||
@setup({'cycle25': '{% cycle a as abc %}'})
|
||||
def test_cycle25(self):
|
||||
output = render('cycle25', {'a': '<'})
|
||||
output = self.engine.render_to_string('cycle25', {'a': '<'})
|
||||
self.assertEqual(output, '<')
|
||||
|
||||
@setup({'cycle26': '{% load cycle from future %}{% cycle a b as ab %}{% cycle ab %}'})
|
||||
def test_cycle26(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('cycle26', {'a': '<', 'b': '>'})
|
||||
output = self.engine.render_to_string('cycle26', {'a': '<', 'b': '>'})
|
||||
self.assertEqual(output, '<>')
|
||||
|
||||
@setup({'cycle27': '{% load cycle from future %}'
|
||||
|
@ -154,12 +153,12 @@ class CycleTagTests(SimpleTestCase):
|
|||
def test_cycle27(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('cycle27', {'a': '<', 'b': '>'})
|
||||
output = self.engine.render_to_string('cycle27', {'a': '<', 'b': '>'})
|
||||
self.assertEqual(output, '<>')
|
||||
|
||||
@setup({'cycle28': '{% load cycle from future %}{% cycle a|safe b as ab %}{% cycle ab %}'})
|
||||
def test_cycle28(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('cycle28', {'a': '<', 'b': '>'})
|
||||
output = self.engine.render_to_string('cycle28', {'a': '<', 'b': '>'})
|
||||
self.assertEqual(output, '<>')
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
from django.conf import settings
|
||||
from django.template.base import TemplateDoesNotExist, TemplateSyntaxError
|
||||
from django.template.loader import get_template
|
||||
from django.template import TemplateDoesNotExist, TemplateSyntaxError
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from .test_extends import inheritance_templates
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class ExceptionsTests(SimpleTestCase):
|
||||
|
@ -15,19 +13,19 @@ class ExceptionsTests(SimpleTestCase):
|
|||
Raise exception for invalid template name
|
||||
"""
|
||||
with self.assertRaises(TemplateDoesNotExist):
|
||||
render('exception01')
|
||||
self.engine.render_to_string('exception01')
|
||||
|
||||
@setup({'exception02': '{% extends nonexistent %}'})
|
||||
def test_exception02(self):
|
||||
"""
|
||||
Raise exception for invalid variable template name
|
||||
"""
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
if self.engine.string_if_invalid:
|
||||
with self.assertRaises(TemplateDoesNotExist):
|
||||
render('exception02')
|
||||
self.engine.render_to_string('exception02')
|
||||
else:
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
render('exception02')
|
||||
self.engine.render_to_string('exception02')
|
||||
|
||||
@setup(
|
||||
{'exception03': "{% extends 'inheritance01' %}"
|
||||
|
@ -39,7 +37,7 @@ class ExceptionsTests(SimpleTestCase):
|
|||
Raise exception for extra {% extends %} tags
|
||||
"""
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('exception03')
|
||||
self.engine.get_template('exception03')
|
||||
|
||||
@setup(
|
||||
{'exception04': "{% extends 'inheritance17' %}{% block first %}{% echo 400 %}5678{% endblock %}"},
|
||||
|
@ -50,7 +48,7 @@ class ExceptionsTests(SimpleTestCase):
|
|||
Raise exception for custom tags used in child with {% load %} tag in parent, not in child
|
||||
"""
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('exception04')
|
||||
self.engine.get_template('exception04')
|
||||
|
||||
@setup({'exception05': '{% block first %}{{ block.super }}{% endblock %}'})
|
||||
def test_exception05(self):
|
||||
|
@ -58,4 +56,4 @@ class ExceptionsTests(SimpleTestCase):
|
|||
Raise exception for block.super used in base template
|
||||
"""
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
render('exception05')
|
||||
self.engine.render_to_string('exception05')
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
from django.template.base import Template
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
inheritance_templates = {
|
||||
|
@ -64,7 +63,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
Standard template with no inheritance
|
||||
"""
|
||||
output = render('inheritance01')
|
||||
output = self.engine.render_to_string('inheritance01')
|
||||
self.assertEqual(output, '1&3_')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -72,7 +71,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
Standard two-level inheritance
|
||||
"""
|
||||
output = render('inheritance02')
|
||||
output = self.engine.render_to_string('inheritance02')
|
||||
self.assertEqual(output, '1234')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -80,7 +79,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
Three-level with no redefinitions on third level
|
||||
"""
|
||||
output = render('inheritance03')
|
||||
output = self.engine.render_to_string('inheritance03')
|
||||
self.assertEqual(output, '1234')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -88,7 +87,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
Two-level with no redefinitions on second level
|
||||
"""
|
||||
output = render('inheritance04')
|
||||
output = self.engine.render_to_string('inheritance04')
|
||||
self.assertEqual(output, '1&3_')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -96,7 +95,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
Two-level with double quotes instead of single quotes
|
||||
"""
|
||||
output = render('inheritance05')
|
||||
output = self.engine.render_to_string('inheritance05')
|
||||
self.assertEqual(output, '1234')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -104,7 +103,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
Three-level with variable parent-template name
|
||||
"""
|
||||
output = render('inheritance06', {'foo': 'inheritance02'})
|
||||
output = self.engine.render_to_string('inheritance06', {'foo': 'inheritance02'})
|
||||
self.assertEqual(output, '1234')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -112,7 +111,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
Two-level with one block defined, one block not defined
|
||||
"""
|
||||
output = render('inheritance07')
|
||||
output = self.engine.render_to_string('inheritance07')
|
||||
self.assertEqual(output, '1&35')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -121,7 +120,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
Three-level with one block defined on this level, two blocks
|
||||
defined next level
|
||||
"""
|
||||
output = render('inheritance08')
|
||||
output = self.engine.render_to_string('inheritance08')
|
||||
self.assertEqual(output, '1235')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -129,7 +128,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
Three-level with second and third levels blank
|
||||
"""
|
||||
output = render('inheritance09')
|
||||
output = self.engine.render_to_string('inheritance09')
|
||||
self.assertEqual(output, '1&3_')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -137,7 +136,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
Three-level with space NOT in a block -- should be ignored
|
||||
"""
|
||||
output = render('inheritance10')
|
||||
output = self.engine.render_to_string('inheritance10')
|
||||
self.assertEqual(output, '1&3_')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -146,7 +145,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
Three-level with both blocks defined on this level, but none on
|
||||
second level
|
||||
"""
|
||||
output = render('inheritance11')
|
||||
output = self.engine.render_to_string('inheritance11')
|
||||
self.assertEqual(output, '1234')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -155,7 +154,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
Three-level with this level providing one and second level
|
||||
providing the other
|
||||
"""
|
||||
output = render('inheritance12')
|
||||
output = self.engine.render_to_string('inheritance12')
|
||||
self.assertEqual(output, '1235')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -163,7 +162,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
Three-level with this level overriding second level
|
||||
"""
|
||||
output = render('inheritance13')
|
||||
output = self.engine.render_to_string('inheritance13')
|
||||
self.assertEqual(output, '1a3b')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -171,7 +170,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
A block defined only in a child template shouldn't be displayed
|
||||
"""
|
||||
output = render('inheritance14')
|
||||
output = self.engine.render_to_string('inheritance14')
|
||||
self.assertEqual(output, '1&3_')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -179,7 +178,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
A block within another block
|
||||
"""
|
||||
output = render('inheritance15')
|
||||
output = self.engine.render_to_string('inheritance15')
|
||||
self.assertEqual(output, '12inner3_')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -187,7 +186,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
A block within another block (level 2)
|
||||
"""
|
||||
output = render('inheritance16')
|
||||
output = self.engine.render_to_string('inheritance16')
|
||||
self.assertEqual(output, '12out3_')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -195,7 +194,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
{% load %} tag (parent -- setup for exception04)
|
||||
"""
|
||||
output = render('inheritance17')
|
||||
output = self.engine.render_to_string('inheritance17')
|
||||
self.assertEqual(output, '1234')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -203,7 +202,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
{% load %} tag (standard usage, without inheritance)
|
||||
"""
|
||||
output = render('inheritance18')
|
||||
output = self.engine.render_to_string('inheritance18')
|
||||
self.assertEqual(output, 'this that theother5678')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -211,7 +210,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
{% load %} tag (within a child template)
|
||||
"""
|
||||
output = render('inheritance19')
|
||||
output = self.engine.render_to_string('inheritance19')
|
||||
self.assertEqual(output, '140056783_')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -219,7 +218,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
Two-level inheritance with {{ block.super }}
|
||||
"""
|
||||
output = render('inheritance20')
|
||||
output = self.engine.render_to_string('inheritance20')
|
||||
self.assertEqual(output, '1&a3_')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -227,7 +226,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
Three-level inheritance with {{ block.super }} from parent
|
||||
"""
|
||||
output = render('inheritance21')
|
||||
output = self.engine.render_to_string('inheritance21')
|
||||
self.assertEqual(output, '12a34')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -235,7 +234,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
Three-level inheritance with {{ block.super }} from grandparent
|
||||
"""
|
||||
output = render('inheritance22')
|
||||
output = self.engine.render_to_string('inheritance22')
|
||||
self.assertEqual(output, '1&a3_')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -244,7 +243,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
Three-level inheritance with {{ block.super }} from parent and
|
||||
grandparent
|
||||
"""
|
||||
output = render('inheritance23')
|
||||
output = self.engine.render_to_string('inheritance23')
|
||||
self.assertEqual(output, '1&ab3_')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -252,9 +251,8 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
Inheritance from local context without use of template loader
|
||||
"""
|
||||
output = render('inheritance24', {
|
||||
'context_template': Template("1{% block first %}_{% endblock %}3{% block second %}_{% endblock %}")
|
||||
})
|
||||
context_template = self.engine.from_string("1{% block first %}_{% endblock %}3{% block second %}_{% endblock %}")
|
||||
output = self.engine.render_to_string('inheritance24', {'context_template': context_template})
|
||||
self.assertEqual(output, '1234')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -262,12 +260,11 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
Inheritance from local context with variable parent template
|
||||
"""
|
||||
output = render('inheritance25', {
|
||||
'context_template': [
|
||||
Template("Wrong"),
|
||||
Template("1{% block first %}_{% endblock %}3{% block second %}_{% endblock %}"),
|
||||
],
|
||||
})
|
||||
context_template = [
|
||||
self.engine.from_string("Wrong"),
|
||||
self.engine.from_string("1{% block first %}_{% endblock %}3{% block second %}_{% endblock %}"),
|
||||
]
|
||||
output = self.engine.render_to_string('inheritance25', {'context_template': context_template})
|
||||
self.assertEqual(output, '1234')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -275,7 +272,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
Set up a base template to extend
|
||||
"""
|
||||
output = render('inheritance26')
|
||||
output = self.engine.render_to_string('inheritance26')
|
||||
self.assertEqual(output, 'no tags')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -283,7 +280,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
Inheritance from a template that doesn't have any blocks
|
||||
"""
|
||||
output = render('inheritance27')
|
||||
output = self.engine.render_to_string('inheritance27')
|
||||
self.assertEqual(output, 'no tags')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -291,7 +288,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
Set up a base template with a space in it.
|
||||
"""
|
||||
output = render('inheritance 28')
|
||||
output = self.engine.render_to_string('inheritance 28')
|
||||
self.assertEqual(output, '!')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -299,7 +296,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
Inheritance from a template with a space in its name should work.
|
||||
"""
|
||||
output = render('inheritance29')
|
||||
output = self.engine.render_to_string('inheritance29')
|
||||
self.assertEqual(output, '!')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -307,19 +304,19 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
Base template, putting block in a conditional {% if %} tag
|
||||
"""
|
||||
output = render('inheritance30', {'optional': True})
|
||||
output = self.engine.render_to_string('inheritance30', {'optional': True})
|
||||
self.assertEqual(output, '123')
|
||||
|
||||
# Inherit from a template with block wrapped in an {% if %} tag
|
||||
# (in parent), still gets overridden
|
||||
@setup(inheritance_templates)
|
||||
def test_inheritance31(self):
|
||||
output = render('inheritance31', {'optional': True})
|
||||
output = self.engine.render_to_string('inheritance31', {'optional': True})
|
||||
self.assertEqual(output, '1two3')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
def test_inheritance32(self):
|
||||
output = render('inheritance32')
|
||||
output = self.engine.render_to_string('inheritance32')
|
||||
self.assertEqual(output, '13')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -327,7 +324,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
Base template, putting block in a conditional {% ifequal %} tag
|
||||
"""
|
||||
output = render('inheritance33', {'optional': 1})
|
||||
output = self.engine.render_to_string('inheritance33', {'optional': 1})
|
||||
self.assertEqual(output, '123')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -336,7 +333,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
Inherit from a template with block wrapped in an {% ifequal %} tag
|
||||
(in parent), still gets overridden
|
||||
"""
|
||||
output = render('inheritance34', {'optional': 1})
|
||||
output = self.engine.render_to_string('inheritance34', {'optional': 1})
|
||||
self.assertEqual(output, '1two3')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -345,7 +342,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
Inherit from a template with block wrapped in an {% ifequal %} tag
|
||||
(in parent), still gets overridden
|
||||
"""
|
||||
output = render('inheritance35', {'optional': 2})
|
||||
output = self.engine.render_to_string('inheritance35', {'optional': 2})
|
||||
self.assertEqual(output, '13')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -353,7 +350,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
Base template, putting block in a {% for %} tag
|
||||
"""
|
||||
output = render('inheritance36', {'numbers': '123'})
|
||||
output = self.engine.render_to_string('inheritance36', {'numbers': '123'})
|
||||
self.assertEqual(output, '_1_2_3_')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -362,7 +359,7 @@ class InheritanceTests(SimpleTestCase):
|
|||
Inherit from a template with block wrapped in an {% for %} tag
|
||||
(in parent), still gets overridden
|
||||
"""
|
||||
output = render('inheritance37', {'numbers': '123'})
|
||||
output = self.engine.render_to_string('inheritance37', {'numbers': '123'})
|
||||
self.assertEqual(output, '_X_X_X_')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -371,23 +368,23 @@ class InheritanceTests(SimpleTestCase):
|
|||
Inherit from a template with block wrapped in an {% for %} tag
|
||||
(in parent), still gets overridden
|
||||
"""
|
||||
output = render('inheritance38')
|
||||
output = self.engine.render_to_string('inheritance38')
|
||||
self.assertEqual(output, '_')
|
||||
|
||||
# The super block will still be found.
|
||||
@setup(inheritance_templates)
|
||||
def test_inheritance39(self):
|
||||
output = render('inheritance39', {'optional': True})
|
||||
output = self.engine.render_to_string('inheritance39', {'optional': True})
|
||||
self.assertEqual(output, '1new23')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
def test_inheritance40(self):
|
||||
output = render('inheritance40', {'optional': 1})
|
||||
output = self.engine.render_to_string('inheritance40', {'optional': 1})
|
||||
self.assertEqual(output, '1new23')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
def test_inheritance41(self):
|
||||
output = render('inheritance41', {'numbers': '123'})
|
||||
output = self.engine.render_to_string('inheritance41', {'numbers': '123'})
|
||||
self.assertEqual(output, '_new1_new2_new3_')
|
||||
|
||||
@setup(inheritance_templates)
|
||||
|
@ -395,5 +392,5 @@ class InheritanceTests(SimpleTestCase):
|
|||
"""
|
||||
Expression starting and ending with a quote
|
||||
"""
|
||||
output = render('inheritance42')
|
||||
output = self.engine.render_to_string('inheritance42')
|
||||
self.assertEqual(output, '1234')
|
||||
|
|
|
@ -2,13 +2,11 @@
|
|||
from __future__ import unicode_literals
|
||||
import warnings
|
||||
|
||||
from django.conf import settings
|
||||
from django.template.base import TemplateSyntaxError
|
||||
from django.template.loader import get_template
|
||||
from django.template import TemplateSyntaxError
|
||||
from django.test import SimpleTestCase
|
||||
from django.utils.deprecation import RemovedInDjango20Warning
|
||||
|
||||
from ..utils import render, setup, SomeClass, SomeOtherException, UTF8Class
|
||||
from ..utils import setup, SomeClass, SomeOtherException, UTF8Class
|
||||
|
||||
|
||||
class FilterSyntaxTests(SimpleTestCase):
|
||||
|
@ -18,7 +16,7 @@ class FilterSyntaxTests(SimpleTestCase):
|
|||
"""
|
||||
Basic filter usage
|
||||
"""
|
||||
output = render('filter-syntax01', {"var": "Django is the greatest!"})
|
||||
output = self.engine.render_to_string('filter-syntax01', {"var": "Django is the greatest!"})
|
||||
self.assertEqual(output, "DJANGO IS THE GREATEST!")
|
||||
|
||||
@setup({'filter-syntax02': '{{ var|upper|lower }}'})
|
||||
|
@ -26,7 +24,7 @@ class FilterSyntaxTests(SimpleTestCase):
|
|||
"""
|
||||
Chained filters
|
||||
"""
|
||||
output = render('filter-syntax02', {"var": "Django is the greatest!"})
|
||||
output = self.engine.render_to_string('filter-syntax02', {"var": "Django is the greatest!"})
|
||||
self.assertEqual(output, "django is the greatest!")
|
||||
|
||||
@setup({'filter-syntax03': '{{ var |upper }}'})
|
||||
|
@ -34,7 +32,7 @@ class FilterSyntaxTests(SimpleTestCase):
|
|||
"""
|
||||
Allow spaces before the filter pipe
|
||||
"""
|
||||
output = render('filter-syntax03', {'var': 'Django is the greatest!'})
|
||||
output = self.engine.render_to_string('filter-syntax03', {'var': 'Django is the greatest!'})
|
||||
self.assertEqual(output, 'DJANGO IS THE GREATEST!')
|
||||
|
||||
@setup({'filter-syntax04': '{{ var| upper }}'})
|
||||
|
@ -42,7 +40,7 @@ class FilterSyntaxTests(SimpleTestCase):
|
|||
"""
|
||||
Allow spaces after the filter pipe
|
||||
"""
|
||||
output = render('filter-syntax04', {'var': 'Django is the greatest!'})
|
||||
output = self.engine.render_to_string('filter-syntax04', {'var': 'Django is the greatest!'})
|
||||
self.assertEqual(output, 'DJANGO IS THE GREATEST!')
|
||||
|
||||
@setup({'filter-syntax05': '{{ var|does_not_exist }}'})
|
||||
|
@ -51,7 +49,7 @@ class FilterSyntaxTests(SimpleTestCase):
|
|||
Raise TemplateSyntaxError for a nonexistent filter
|
||||
"""
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('filter-syntax05')
|
||||
self.engine.get_template('filter-syntax05')
|
||||
|
||||
@setup({'filter-syntax06': '{{ var|fil(ter) }}'})
|
||||
def test_filter_syntax06(self):
|
||||
|
@ -60,7 +58,7 @@ class FilterSyntaxTests(SimpleTestCase):
|
|||
an illegal character
|
||||
"""
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('filter-syntax06')
|
||||
self.engine.get_template('filter-syntax06')
|
||||
|
||||
@setup({'filter-syntax07': "{% nothing_to_see_here %}"})
|
||||
def test_filter_syntax07(self):
|
||||
|
@ -68,7 +66,7 @@ class FilterSyntaxTests(SimpleTestCase):
|
|||
Raise TemplateSyntaxError for invalid block tags
|
||||
"""
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('filter-syntax07')
|
||||
self.engine.get_template('filter-syntax07')
|
||||
|
||||
@setup({'filter-syntax08': "{% %}"})
|
||||
def test_filter_syntax08(self):
|
||||
|
@ -76,7 +74,7 @@ class FilterSyntaxTests(SimpleTestCase):
|
|||
Raise TemplateSyntaxError for empty block tags
|
||||
"""
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('filter-syntax08')
|
||||
self.engine.get_template('filter-syntax08')
|
||||
|
||||
@setup({'filter-syntax09': '{{ var|removetags:"b i"|upper|lower }}'})
|
||||
def test_filter_syntax09(self):
|
||||
|
@ -85,7 +83,7 @@ class FilterSyntaxTests(SimpleTestCase):
|
|||
"""
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('filter-syntax09', {'var': '<b><i>Yes</i></b>'})
|
||||
output = self.engine.render_to_string('filter-syntax09', {'var': '<b><i>Yes</i></b>'})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'filter-syntax10': r'{{ var|default_if_none:" endquote\" hah" }}'})
|
||||
|
@ -93,7 +91,7 @@ class FilterSyntaxTests(SimpleTestCase):
|
|||
"""
|
||||
Literal string as argument is always "safe" from auto-escaping.
|
||||
"""
|
||||
output = render('filter-syntax10', {"var": None})
|
||||
output = self.engine.render_to_string('filter-syntax10', {"var": None})
|
||||
self.assertEqual(output, ' endquote" hah')
|
||||
|
||||
@setup({'filter-syntax11': r'{{ var|default_if_none:var2 }}'})
|
||||
|
@ -101,7 +99,7 @@ class FilterSyntaxTests(SimpleTestCase):
|
|||
"""
|
||||
Variable as argument
|
||||
"""
|
||||
output = render('filter-syntax11', {"var": None, "var2": "happy"})
|
||||
output = self.engine.render_to_string('filter-syntax11', {"var": None, "var2": "happy"})
|
||||
self.assertEqual(output, 'happy')
|
||||
|
||||
@setup({'filter-syntax12': r'{{ var|yesno:"yup,nup,mup" }} {{ var|yesno }}'})
|
||||
|
@ -109,7 +107,7 @@ class FilterSyntaxTests(SimpleTestCase):
|
|||
"""
|
||||
Default argument testing
|
||||
"""
|
||||
output = render('filter-syntax12', {"var": True})
|
||||
output = self.engine.render_to_string('filter-syntax12', {"var": True})
|
||||
self.assertEqual(output, 'yup yes')
|
||||
|
||||
@setup({'filter-syntax13': r'1{{ var.method3 }}2'})
|
||||
|
@ -118,8 +116,8 @@ class FilterSyntaxTests(SimpleTestCase):
|
|||
Fail silently for methods that raise an exception with a
|
||||
`silent_variable_failure` attribute
|
||||
"""
|
||||
output = render('filter-syntax13', {"var": SomeClass()})
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
output = self.engine.render_to_string('filter-syntax13', {"var": SomeClass()})
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, "1INVALID2")
|
||||
else:
|
||||
self.assertEqual(output, "12")
|
||||
|
@ -131,14 +129,14 @@ class FilterSyntaxTests(SimpleTestCase):
|
|||
`silent_variable_attribute` set to True, the exception propagates
|
||||
"""
|
||||
with self.assertRaises(SomeOtherException):
|
||||
render('filter-syntax14', {"var": SomeClass()})
|
||||
self.engine.render_to_string('filter-syntax14', {"var": SomeClass()})
|
||||
|
||||
@setup({'filter-syntax15': r'{{ var|default_if_none:"foo\bar" }}'})
|
||||
def test_filter_syntax15(self):
|
||||
"""
|
||||
Escaped backslash in argument
|
||||
"""
|
||||
output = render('filter-syntax15', {"var": None})
|
||||
output = self.engine.render_to_string('filter-syntax15', {"var": None})
|
||||
self.assertEqual(output, r'foo\bar')
|
||||
|
||||
@setup({'filter-syntax16': r'{{ var|default_if_none:"foo\now" }}'})
|
||||
|
@ -146,7 +144,7 @@ class FilterSyntaxTests(SimpleTestCase):
|
|||
"""
|
||||
Escaped backslash using known escape char
|
||||
"""
|
||||
output = render('filter-syntax16', {"var": None})
|
||||
output = self.engine.render_to_string('filter-syntax16', {"var": None})
|
||||
self.assertEqual(output, r'foo\now')
|
||||
|
||||
@setup({'filter-syntax17': r'{{ var|join:"" }}'})
|
||||
|
@ -154,7 +152,7 @@ class FilterSyntaxTests(SimpleTestCase):
|
|||
"""
|
||||
Empty strings can be passed as arguments to filters
|
||||
"""
|
||||
output = render('filter-syntax17', {'var': ['a', 'b', 'c']})
|
||||
output = self.engine.render_to_string('filter-syntax17', {'var': ['a', 'b', 'c']})
|
||||
self.assertEqual(output, 'abc')
|
||||
|
||||
@setup({'filter-syntax18': r'{{ var }}'})
|
||||
|
@ -163,7 +161,7 @@ class FilterSyntaxTests(SimpleTestCase):
|
|||
Make sure that any unicode strings are converted to bytestrings
|
||||
in the final output.
|
||||
"""
|
||||
output = render('filter-syntax18', {'var': UTF8Class()})
|
||||
output = self.engine.render_to_string('filter-syntax18', {'var': UTF8Class()})
|
||||
self.assertEqual(output, '\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111')
|
||||
|
||||
@setup({'filter-syntax19': '{{ var|truncatewords:1 }}'})
|
||||
|
@ -171,7 +169,7 @@ class FilterSyntaxTests(SimpleTestCase):
|
|||
"""
|
||||
Numbers as filter arguments should work
|
||||
"""
|
||||
output = render('filter-syntax19', {"var": "hello world"})
|
||||
output = self.engine.render_to_string('filter-syntax19', {"var": "hello world"})
|
||||
self.assertEqual(output, "hello ...")
|
||||
|
||||
@setup({'filter-syntax20': '{{ ""|default_if_none:"was none" }}'})
|
||||
|
@ -179,7 +177,7 @@ class FilterSyntaxTests(SimpleTestCase):
|
|||
"""
|
||||
Filters should accept empty string constants
|
||||
"""
|
||||
output = render('filter-syntax20')
|
||||
output = self.engine.render_to_string('filter-syntax20')
|
||||
self.assertEqual(output, "")
|
||||
|
||||
@setup({'filter-syntax21': r'1{{ var.silent_fail_key }}2'})
|
||||
|
@ -188,8 +186,8 @@ class FilterSyntaxTests(SimpleTestCase):
|
|||
Fail silently for non-callable attribute and dict lookups which
|
||||
raise an exception with a "silent_variable_failure" attribute
|
||||
"""
|
||||
output = render('filter-syntax21', {"var": SomeClass()})
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
output = self.engine.render_to_string('filter-syntax21', {"var": SomeClass()})
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, "1INVALID2")
|
||||
else:
|
||||
self.assertEqual(output, "12")
|
||||
|
@ -200,8 +198,8 @@ class FilterSyntaxTests(SimpleTestCase):
|
|||
Fail silently for non-callable attribute and dict lookups which
|
||||
raise an exception with a `silent_variable_failure` attribute
|
||||
"""
|
||||
output = render('filter-syntax22', {"var": SomeClass()})
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
output = self.engine.render_to_string('filter-syntax22', {"var": SomeClass()})
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, "1INVALID2")
|
||||
else:
|
||||
self.assertEqual(output, "12")
|
||||
|
@ -214,7 +212,7 @@ class FilterSyntaxTests(SimpleTestCase):
|
|||
propagates
|
||||
"""
|
||||
with self.assertRaises(SomeOtherException):
|
||||
render('filter-syntax23', {"var": SomeClass()})
|
||||
self.engine.render_to_string('filter-syntax23', {"var": SomeClass()})
|
||||
|
||||
@setup({'filter-syntax24': r'1{{ var.noisy_fail_attribute }}2'})
|
||||
def test_filter_syntax24(self):
|
||||
|
@ -224,7 +222,7 @@ class FilterSyntaxTests(SimpleTestCase):
|
|||
propagates
|
||||
"""
|
||||
with self.assertRaises(SomeOtherException):
|
||||
render('filter-syntax24', {"var": SomeClass()})
|
||||
self.engine.render_to_string('filter-syntax24', {"var": SomeClass()})
|
||||
|
||||
@setup({'filter-syntax25': '{{ var.attribute_error_attribute }}'})
|
||||
def test_filter_syntax25(self):
|
||||
|
@ -233,4 +231,4 @@ class FilterSyntaxTests(SimpleTestCase):
|
|||
reraised.
|
||||
"""
|
||||
with self.assertRaises(AttributeError):
|
||||
render('filter-syntax25', {'var': SomeClass()})
|
||||
self.engine.render_to_string('filter-syntax25', {'var': SomeClass()})
|
||||
|
|
|
@ -1,48 +1,47 @@
|
|||
from django.template.base import TemplateSyntaxError
|
||||
from django.template.loader import get_template
|
||||
from django.template import TemplateSyntaxError
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class FilterTagTests(SimpleTestCase):
|
||||
|
||||
@setup({'filter01': '{% filter upper %}{% endfilter %}'})
|
||||
def test_filter01(self):
|
||||
output = render('filter01')
|
||||
output = self.engine.render_to_string('filter01')
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'filter02': '{% filter upper %}django{% endfilter %}'})
|
||||
def test_filter02(self):
|
||||
output = render('filter02')
|
||||
output = self.engine.render_to_string('filter02')
|
||||
self.assertEqual(output, 'DJANGO')
|
||||
|
||||
@setup({'filter03': '{% filter upper|lower %}django{% endfilter %}'})
|
||||
def test_filter03(self):
|
||||
output = render('filter03')
|
||||
output = self.engine.render_to_string('filter03')
|
||||
self.assertEqual(output, 'django')
|
||||
|
||||
@setup({'filter04': '{% filter cut:remove %}djangospam{% endfilter %}'})
|
||||
def test_filter04(self):
|
||||
output = render('filter04', {'remove': 'spam'})
|
||||
output = self.engine.render_to_string('filter04', {'remove': 'spam'})
|
||||
self.assertEqual(output, 'django')
|
||||
|
||||
@setup({'filter05': '{% filter safe %}fail{% endfilter %}'})
|
||||
def test_filter05(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('filter05')
|
||||
self.engine.get_template('filter05')
|
||||
|
||||
@setup({'filter05bis': '{% filter upper|safe %}fail{% endfilter %}'})
|
||||
def test_filter05bis(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('filter05bis')
|
||||
self.engine.get_template('filter05bis')
|
||||
|
||||
@setup({'filter06': '{% filter escape %}fail{% endfilter %}'})
|
||||
def test_filter06(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('filter06')
|
||||
self.engine.get_template('filter06')
|
||||
|
||||
@setup({'filter06bis': '{% filter upper|escape %}fail{% endfilter %}'})
|
||||
def test_filter06bis(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('filter06bis')
|
||||
self.engine.get_template('filter06bis')
|
||||
|
|
|
@ -1,77 +1,76 @@
|
|||
import warnings
|
||||
|
||||
from django.template.base import TemplateSyntaxError
|
||||
from django.template.loader import get_template
|
||||
from django.template import TemplateSyntaxError
|
||||
from django.test import SimpleTestCase
|
||||
from django.utils.deprecation import RemovedInDjango20Warning
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class FirstOfTagTests(SimpleTestCase):
|
||||
|
||||
@setup({'firstof01': '{% firstof a b c %}'})
|
||||
def test_firstof01(self):
|
||||
output = render('firstof01', {'a': 0, 'c': 0, 'b': 0})
|
||||
output = self.engine.render_to_string('firstof01', {'a': 0, 'c': 0, 'b': 0})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'firstof02': '{% firstof a b c %}'})
|
||||
def test_firstof02(self):
|
||||
output = render('firstof02', {'a': 1, 'c': 0, 'b': 0})
|
||||
output = self.engine.render_to_string('firstof02', {'a': 1, 'c': 0, 'b': 0})
|
||||
self.assertEqual(output, '1')
|
||||
|
||||
@setup({'firstof03': '{% firstof a b c %}'})
|
||||
def test_firstof03(self):
|
||||
output = render('firstof03', {'a': 0, 'c': 0, 'b': 2})
|
||||
output = self.engine.render_to_string('firstof03', {'a': 0, 'c': 0, 'b': 2})
|
||||
self.assertEqual(output, '2')
|
||||
|
||||
@setup({'firstof04': '{% firstof a b c %}'})
|
||||
def test_firstof04(self):
|
||||
output = render('firstof04', {'a': 0, 'c': 3, 'b': 0})
|
||||
output = self.engine.render_to_string('firstof04', {'a': 0, 'c': 3, 'b': 0})
|
||||
self.assertEqual(output, '3')
|
||||
|
||||
@setup({'firstof05': '{% firstof a b c %}'})
|
||||
def test_firstof05(self):
|
||||
output = render('firstof05', {'a': 1, 'c': 3, 'b': 2})
|
||||
output = self.engine.render_to_string('firstof05', {'a': 1, 'c': 3, 'b': 2})
|
||||
self.assertEqual(output, '1')
|
||||
|
||||
@setup({'firstof06': '{% firstof a b c %}'})
|
||||
def test_firstof06(self):
|
||||
output = render('firstof06', {'c': 3, 'b': 0})
|
||||
output = self.engine.render_to_string('firstof06', {'c': 3, 'b': 0})
|
||||
self.assertEqual(output, '3')
|
||||
|
||||
@setup({'firstof07': '{% firstof a b "c" %}'})
|
||||
def test_firstof07(self):
|
||||
output = render('firstof07', {'a': 0})
|
||||
output = self.engine.render_to_string('firstof07', {'a': 0})
|
||||
self.assertEqual(output, 'c')
|
||||
|
||||
@setup({'firstof08': '{% firstof a b "c and d" %}'})
|
||||
def test_firstof08(self):
|
||||
output = render('firstof08', {'a': 0, 'b': 0})
|
||||
output = self.engine.render_to_string('firstof08', {'a': 0, 'b': 0})
|
||||
self.assertEqual(output, 'c and d')
|
||||
|
||||
@setup({'firstof09': '{% firstof %}'})
|
||||
def test_firstof09(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('firstof09')
|
||||
self.engine.get_template('firstof09')
|
||||
|
||||
@setup({'firstof10': '{% firstof a %}'})
|
||||
def test_firstof10(self):
|
||||
output = render('firstof10', {'a': '<'})
|
||||
output = self.engine.render_to_string('firstof10', {'a': '<'})
|
||||
self.assertEqual(output, '<')
|
||||
|
||||
@setup({'firstof11': '{% load firstof from future %}{% firstof a b %}'})
|
||||
def test_firstof11(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('firstof11', {'a': '<', 'b': '>'})
|
||||
output = self.engine.render_to_string('firstof11', {'a': '<', 'b': '>'})
|
||||
self.assertEqual(output, '<')
|
||||
|
||||
@setup({'firstof12': '{% load firstof from future %}{% firstof a b %}'})
|
||||
def test_firstof12(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('firstof12', {'a': '', 'b': '>'})
|
||||
output = self.engine.render_to_string('firstof12', {'a': '', 'b': '>'})
|
||||
self.assertEqual(output, '>')
|
||||
|
||||
@setup({'firstof13': '{% load firstof from future %}'
|
||||
|
@ -79,12 +78,12 @@ class FirstOfTagTests(SimpleTestCase):
|
|||
def test_firstof13(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('firstof13', {'a': '<'})
|
||||
output = self.engine.render_to_string('firstof13', {'a': '<'})
|
||||
self.assertEqual(output, '<')
|
||||
|
||||
@setup({'firstof14': '{% load firstof from future %}{% firstof a|safe b %}'})
|
||||
def test_firstof14(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('firstof14', {'a': '<'})
|
||||
output = self.engine.render_to_string('firstof14', {'a': '<'})
|
||||
self.assertEqual(output, '<')
|
||||
|
|
|
@ -1,122 +1,121 @@
|
|||
import warnings
|
||||
|
||||
from django.conf import settings
|
||||
from django.template.base import TemplateSyntaxError
|
||||
from django.template import TemplateSyntaxError
|
||||
from django.test import SimpleTestCase
|
||||
from django.utils.deprecation import RemovedInDjango20Warning
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class ForTagTests(SimpleTestCase):
|
||||
|
||||
@setup({'for-tag01': '{% for val in values %}{{ val }}{% endfor %}'})
|
||||
def test_for_tag01(self):
|
||||
output = render('for-tag01', {'values': [1, 2, 3]})
|
||||
output = self.engine.render_to_string('for-tag01', {'values': [1, 2, 3]})
|
||||
self.assertEqual(output, '123')
|
||||
|
||||
@setup({'for-tag02': '{% for val in values reversed %}{{ val }}{% endfor %}'})
|
||||
def test_for_tag02(self):
|
||||
output = render('for-tag02', {'values': [1, 2, 3]})
|
||||
output = self.engine.render_to_string('for-tag02', {'values': [1, 2, 3]})
|
||||
self.assertEqual(output, '321')
|
||||
|
||||
@setup({'for-tag-vars01': '{% for val in values %}{{ forloop.counter }}{% endfor %}'})
|
||||
def test_for_tag_vars01(self):
|
||||
output = render('for-tag-vars01', {'values': [6, 6, 6]})
|
||||
output = self.engine.render_to_string('for-tag-vars01', {'values': [6, 6, 6]})
|
||||
self.assertEqual(output, '123')
|
||||
|
||||
@setup({'for-tag-vars02': '{% for val in values %}{{ forloop.counter0 }}{% endfor %}'})
|
||||
def test_for_tag_vars02(self):
|
||||
output = render('for-tag-vars02', {'values': [6, 6, 6]})
|
||||
output = self.engine.render_to_string('for-tag-vars02', {'values': [6, 6, 6]})
|
||||
self.assertEqual(output, '012')
|
||||
|
||||
@setup({'for-tag-vars03': '{% for val in values %}{{ forloop.revcounter }}{% endfor %}'})
|
||||
def test_for_tag_vars03(self):
|
||||
output = render('for-tag-vars03', {'values': [6, 6, 6]})
|
||||
output = self.engine.render_to_string('for-tag-vars03', {'values': [6, 6, 6]})
|
||||
self.assertEqual(output, '321')
|
||||
|
||||
@setup({'for-tag-vars04': '{% for val in values %}{{ forloop.revcounter0 }}{% endfor %}'})
|
||||
def test_for_tag_vars04(self):
|
||||
output = render('for-tag-vars04', {'values': [6, 6, 6]})
|
||||
output = self.engine.render_to_string('for-tag-vars04', {'values': [6, 6, 6]})
|
||||
self.assertEqual(output, '210')
|
||||
|
||||
@setup({'for-tag-vars05': '{% for val in values %}'
|
||||
'{% if forloop.first %}f{% else %}x{% endif %}{% endfor %}'})
|
||||
def test_for_tag_vars05(self):
|
||||
output = render('for-tag-vars05', {'values': [6, 6, 6]})
|
||||
output = self.engine.render_to_string('for-tag-vars05', {'values': [6, 6, 6]})
|
||||
self.assertEqual(output, 'fxx')
|
||||
|
||||
@setup({'for-tag-vars06': '{% for val in values %}'
|
||||
'{% if forloop.last %}l{% else %}x{% endif %}{% endfor %}'})
|
||||
def test_for_tag_vars06(self):
|
||||
output = render('for-tag-vars06', {'values': [6, 6, 6]})
|
||||
output = self.engine.render_to_string('for-tag-vars06', {'values': [6, 6, 6]})
|
||||
self.assertEqual(output, 'xxl')
|
||||
|
||||
@setup({'for-tag-unpack01': '{% for key,value in items %}{{ key }}:{{ value }}/{% endfor %}'})
|
||||
def test_for_tag_unpack01(self):
|
||||
output = render('for-tag-unpack01', {'items': (('one', 1), ('two', 2))})
|
||||
output = self.engine.render_to_string('for-tag-unpack01', {'items': (('one', 1), ('two', 2))})
|
||||
self.assertEqual(output, 'one:1/two:2/')
|
||||
|
||||
@setup({'for-tag-unpack03': '{% for key, value in items %}{{ key }}:{{ value }}/{% endfor %}'})
|
||||
def test_for_tag_unpack03(self):
|
||||
output = render('for-tag-unpack03', {'items': (('one', 1), ('two', 2))})
|
||||
output = self.engine.render_to_string('for-tag-unpack03', {'items': (('one', 1), ('two', 2))})
|
||||
self.assertEqual(output, 'one:1/two:2/')
|
||||
|
||||
@setup({'for-tag-unpack04': '{% for key , value in items %}{{ key }}:{{ value }}/{% endfor %}'})
|
||||
def test_for_tag_unpack04(self):
|
||||
output = render('for-tag-unpack04', {'items': (('one', 1), ('two', 2))})
|
||||
output = self.engine.render_to_string('for-tag-unpack04', {'items': (('one', 1), ('two', 2))})
|
||||
self.assertEqual(output, 'one:1/two:2/')
|
||||
|
||||
@setup({'for-tag-unpack05': '{% for key ,value in items %}{{ key }}:{{ value }}/{% endfor %}'})
|
||||
def test_for_tag_unpack05(self):
|
||||
output = render('for-tag-unpack05', {'items': (('one', 1), ('two', 2))})
|
||||
output = self.engine.render_to_string('for-tag-unpack05', {'items': (('one', 1), ('two', 2))})
|
||||
self.assertEqual(output, 'one:1/two:2/')
|
||||
|
||||
@setup({'for-tag-unpack06': '{% for key value in items %}{{ key }}:{{ value }}/{% endfor %}'})
|
||||
def test_for_tag_unpack06(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
render('for-tag-unpack06', {'items': (('one', 1), ('two', 2))})
|
||||
self.engine.render_to_string('for-tag-unpack06', {'items': (('one', 1), ('two', 2))})
|
||||
|
||||
@setup({'for-tag-unpack07': '{% for key,,value in items %}{{ key }}:{{ value }}/{% endfor %}'})
|
||||
def test_for_tag_unpack07(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
render('for-tag-unpack07', {'items': (('one', 1), ('two', 2))})
|
||||
self.engine.render_to_string('for-tag-unpack07', {'items': (('one', 1), ('two', 2))})
|
||||
|
||||
@setup({'for-tag-unpack08': '{% for key,value, in items %}{{ key }}:{{ value }}/{% endfor %}'})
|
||||
def test_for_tag_unpack08(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
render('for-tag-unpack08', {'items': (('one', 1), ('two', 2))})
|
||||
self.engine.render_to_string('for-tag-unpack08', {'items': (('one', 1), ('two', 2))})
|
||||
|
||||
@setup({'for-tag-unpack09': '{% for val in items %}{{ val.0 }}:{{ val.1 }}/{% endfor %}'})
|
||||
def test_for_tag_unpack09(self):
|
||||
"""
|
||||
Ensure that a single loopvar doesn't truncate the list in val.
|
||||
"""
|
||||
output = render('for-tag-unpack09', {'items': (('one', 1), ('two', 2))})
|
||||
output = self.engine.render_to_string('for-tag-unpack09', {'items': (('one', 1), ('two', 2))})
|
||||
self.assertEqual(output, 'one:1/two:2/')
|
||||
|
||||
@setup({'for-tag-unpack13': '{% for x,y,z in items %}{{ x }}:{{ y }},{{ z }}/{% endfor %}'})
|
||||
def test_for_tag_unpack13(self):
|
||||
output = render('for-tag-unpack13', {'items': (('one', 1, 'carrot'), ('two', 2, 'cheese'))})
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
output = self.engine.render_to_string('for-tag-unpack13', {'items': (('one', 1, 'carrot'), ('two', 2, 'cheese'))})
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, 'one:1,carrot/two:2,cheese/')
|
||||
else:
|
||||
self.assertEqual(output, 'one:1,carrot/two:2,cheese/')
|
||||
|
||||
@setup({'for-tag-empty01': '{% for val in values %}{{ val }}{% empty %}empty text{% endfor %}'})
|
||||
def test_for_tag_empty01(self):
|
||||
output = render('for-tag-empty01', {'values': [1, 2, 3]})
|
||||
output = self.engine.render_to_string('for-tag-empty01', {'values': [1, 2, 3]})
|
||||
self.assertEqual(output, '123')
|
||||
|
||||
@setup({'for-tag-empty02': '{% for val in values %}{{ val }}{% empty %}values array empty{% endfor %}'})
|
||||
def test_for_tag_empty02(self):
|
||||
output = render('for-tag-empty02', {'values': []})
|
||||
output = self.engine.render_to_string('for-tag-empty02', {'values': []})
|
||||
self.assertEqual(output, 'values array empty')
|
||||
|
||||
@setup({'for-tag-empty03': '{% for val in values %}'
|
||||
'{{ val }}{% empty %}values array not found{% endfor %}'})
|
||||
def test_for_tag_empty03(self):
|
||||
output = render('for-tag-empty03')
|
||||
output = self.engine.render_to_string('for-tag-empty03')
|
||||
self.assertEqual(output, 'values array not found')
|
||||
|
||||
@setup({'for-tag-filter-ws': "{% load custom %}{% for x in s|noop:'x y' %}{{ x }}{% endfor %}"})
|
||||
|
@ -124,7 +123,7 @@ class ForTagTests(SimpleTestCase):
|
|||
"""
|
||||
#19882
|
||||
"""
|
||||
output = render('for-tag-filter-ws', {'s': 'abc'})
|
||||
output = self.engine.render_to_string('for-tag-filter-ws', {'s': 'abc'})
|
||||
self.assertEqual(output, 'abc')
|
||||
|
||||
# These tests raise deprecation warnings and will raise an exception
|
||||
|
@ -134,7 +133,7 @@ class ForTagTests(SimpleTestCase):
|
|||
def test_for_tag_unpack10(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'for-tag-unpack10',
|
||||
{'items': (('one', 1, 'carrot'), ('two', 2, 'orange'))},
|
||||
)
|
||||
|
@ -144,12 +143,12 @@ class ForTagTests(SimpleTestCase):
|
|||
def test_for_tag_unpack11(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'for-tag-unpack11',
|
||||
{'items': (('one', 1), ('two', 2))},
|
||||
)
|
||||
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, 'one:1,INVALID/two:2,INVALID/')
|
||||
else:
|
||||
self.assertEqual(output, 'one:1,/two:2,/')
|
||||
|
@ -158,11 +157,11 @@ class ForTagTests(SimpleTestCase):
|
|||
def test_for_tag_unpack12(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'for-tag-unpack12',
|
||||
{'items': (('one', 1, 'carrot'), ('two', 2))}
|
||||
)
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, 'one:1,carrot/two:2,INVALID/')
|
||||
else:
|
||||
self.assertEqual(output, 'one:1,carrot/two:2,/')
|
||||
|
@ -171,9 +170,9 @@ class ForTagTests(SimpleTestCase):
|
|||
def test_for_tag_unpack14(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('for-tag-unpack14', {'items': (1, 2)})
|
||||
output = self.engine.render_to_string('for-tag-unpack14', {'items': (1, 2)})
|
||||
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, 'INVALID:INVALID/INVALID:INVALID/')
|
||||
else:
|
||||
self.assertEqual(output, ':/:/')
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
# coding: utf-8
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
from django.test import SimpleTestCase
|
||||
from django.utils import translation
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class I18nTagTests(SimpleTestCase):
|
||||
|
@ -15,7 +15,7 @@ class I18nTagTests(SimpleTestCase):
|
|||
"""
|
||||
simple translation of a string delimited by '
|
||||
"""
|
||||
output = render('i18n01')
|
||||
output = self.engine.render_to_string('i18n01')
|
||||
self.assertEqual(output, 'xxxyyyxxx')
|
||||
|
||||
@setup({'i18n02': '{% load i18n %}{% trans "xxxyyyxxx" %}'})
|
||||
|
@ -23,7 +23,7 @@ class I18nTagTests(SimpleTestCase):
|
|||
"""
|
||||
simple translation of a string delimited by "
|
||||
"""
|
||||
output = render('i18n02')
|
||||
output = self.engine.render_to_string('i18n02')
|
||||
self.assertEqual(output, 'xxxyyyxxx')
|
||||
|
||||
@setup({'i18n03': '{% load i18n %}{% blocktrans %}{{ anton }}{% endblocktrans %}'})
|
||||
|
@ -31,7 +31,7 @@ class I18nTagTests(SimpleTestCase):
|
|||
"""
|
||||
simple translation of a variable
|
||||
"""
|
||||
output = render('i18n03', {'anton': b'\xc3\x85'})
|
||||
output = self.engine.render_to_string('i18n03', {'anton': b'\xc3\x85'})
|
||||
self.assertEqual(output, 'Å')
|
||||
|
||||
@setup({'i18n04': '{% load i18n %}{% blocktrans with berta=anton|lower %}{{ berta }}{% endblocktrans %}'})
|
||||
|
@ -39,7 +39,7 @@ class I18nTagTests(SimpleTestCase):
|
|||
"""
|
||||
simple translation of a variable and filter
|
||||
"""
|
||||
output = render('i18n04', {'anton': b'\xc3\x85'})
|
||||
output = self.engine.render_to_string('i18n04', {'anton': b'\xc3\x85'})
|
||||
self.assertEqual(output, 'å')
|
||||
|
||||
@setup({'legacyi18n04': '{% load i18n %}'
|
||||
|
@ -48,7 +48,7 @@ class I18nTagTests(SimpleTestCase):
|
|||
"""
|
||||
simple translation of a variable and filter
|
||||
"""
|
||||
output = render('legacyi18n04', {'anton': b'\xc3\x85'})
|
||||
output = self.engine.render_to_string('legacyi18n04', {'anton': b'\xc3\x85'})
|
||||
self.assertEqual(output, 'å')
|
||||
|
||||
@setup({'i18n05': '{% load i18n %}{% blocktrans %}xxx{{ anton }}xxx{% endblocktrans %}'})
|
||||
|
@ -56,7 +56,7 @@ class I18nTagTests(SimpleTestCase):
|
|||
"""
|
||||
simple translation of a string with interpolation
|
||||
"""
|
||||
output = render('i18n05', {'anton': 'yyy'})
|
||||
output = self.engine.render_to_string('i18n05', {'anton': 'yyy'})
|
||||
self.assertEqual(output, 'xxxyyyxxx')
|
||||
|
||||
@setup({'i18n06': '{% load i18n %}{% trans "Page not found" %}'})
|
||||
|
@ -64,7 +64,8 @@ class I18nTagTests(SimpleTestCase):
|
|||
"""
|
||||
simple translation of a string to german
|
||||
"""
|
||||
output = render('i18n06', {'LANGUAGE_CODE': 'de'})
|
||||
with translation.override('de'):
|
||||
output = self.engine.render_to_string('i18n06')
|
||||
self.assertEqual(output, 'Seite nicht gefunden')
|
||||
|
||||
@setup({'i18n07': '{% load i18n %}'
|
||||
|
@ -74,7 +75,7 @@ class I18nTagTests(SimpleTestCase):
|
|||
"""
|
||||
translation of singular form
|
||||
"""
|
||||
output = render('i18n07', {'number': 1})
|
||||
output = self.engine.render_to_string('i18n07', {'number': 1})
|
||||
self.assertEqual(output, 'singular')
|
||||
|
||||
@setup({'legacyi18n07': '{% load i18n %}'
|
||||
|
@ -84,7 +85,7 @@ class I18nTagTests(SimpleTestCase):
|
|||
"""
|
||||
translation of singular form
|
||||
"""
|
||||
output = render('legacyi18n07', {'number': 1})
|
||||
output = self.engine.render_to_string('legacyi18n07', {'number': 1})
|
||||
self.assertEqual(output, 'singular')
|
||||
|
||||
@setup({'i18n08': '{% load i18n %}'
|
||||
|
@ -94,7 +95,7 @@ class I18nTagTests(SimpleTestCase):
|
|||
"""
|
||||
translation of plural form
|
||||
"""
|
||||
output = render('i18n08', {'number': 2})
|
||||
output = self.engine.render_to_string('i18n08', {'number': 2})
|
||||
self.assertEqual(output, '2 plural')
|
||||
|
||||
@setup({'legacyi18n08': '{% load i18n %}'
|
||||
|
@ -104,7 +105,7 @@ class I18nTagTests(SimpleTestCase):
|
|||
"""
|
||||
translation of plural form
|
||||
"""
|
||||
output = render('legacyi18n08', {'number': 2})
|
||||
output = self.engine.render_to_string('legacyi18n08', {'number': 2})
|
||||
self.assertEqual(output, '2 plural')
|
||||
|
||||
@setup({'i18n09': '{% load i18n %}{% trans "Page not found" noop %}'})
|
||||
|
@ -112,7 +113,8 @@ class I18nTagTests(SimpleTestCase):
|
|||
"""
|
||||
simple non-translation (only marking) of a string to german
|
||||
"""
|
||||
output = render('i18n09', {'LANGUAGE_CODE': 'de'})
|
||||
with translation.override('de'):
|
||||
output = self.engine.render_to_string('i18n09')
|
||||
self.assertEqual(output, 'Page not found')
|
||||
|
||||
@setup({'i18n10': '{{ bool|yesno:_("yes,no,maybe") }}'})
|
||||
|
@ -120,7 +122,8 @@ class I18nTagTests(SimpleTestCase):
|
|||
"""
|
||||
translation of a variable with a translated filter
|
||||
"""
|
||||
output = render('i18n10', {'bool': True, 'LANGUAGE_CODE': 'de'})
|
||||
with translation.override('de'):
|
||||
output = self.engine.render_to_string('i18n10', {'bool': True})
|
||||
self.assertEqual(output, 'Ja')
|
||||
|
||||
@setup({'i18n11': '{{ bool|yesno:"ja,nein" }}'})
|
||||
|
@ -128,7 +131,7 @@ class I18nTagTests(SimpleTestCase):
|
|||
"""
|
||||
translation of a variable with a non-translated filter
|
||||
"""
|
||||
output = render('i18n11', {'bool': True})
|
||||
output = self.engine.render_to_string('i18n11', {'bool': True})
|
||||
self.assertEqual(output, 'ja')
|
||||
|
||||
@setup({'i18n12': '{% load i18n %}'
|
||||
|
@ -138,7 +141,7 @@ class I18nTagTests(SimpleTestCase):
|
|||
"""
|
||||
usage of the get_available_languages tag
|
||||
"""
|
||||
output = render('i18n12')
|
||||
output = self.engine.render_to_string('i18n12')
|
||||
self.assertEqual(output, 'de')
|
||||
|
||||
@setup({'i18n13': '{{ _("Password") }}'})
|
||||
|
@ -146,7 +149,8 @@ class I18nTagTests(SimpleTestCase):
|
|||
"""
|
||||
translation of constant strings
|
||||
"""
|
||||
output = render('i18n13', {'LANGUAGE_CODE': 'de'})
|
||||
with translation.override('de'):
|
||||
output = self.engine.render_to_string('i18n13')
|
||||
self.assertEqual(output, 'Passwort')
|
||||
|
||||
@setup({'i18n14': '{% cycle "foo" _("Password") _(\'Password\') as c %} {% cycle c %} {% cycle c %}'})
|
||||
|
@ -154,7 +158,8 @@ class I18nTagTests(SimpleTestCase):
|
|||
"""
|
||||
translation of constant strings
|
||||
"""
|
||||
output = render('i18n14', {'LANGUAGE_CODE': 'de'})
|
||||
with translation.override('de'):
|
||||
output = self.engine.render_to_string('i18n14')
|
||||
self.assertEqual(output, 'foo Passwort Passwort')
|
||||
|
||||
@setup({'i18n15': '{{ absent|default:_("Password") }}'})
|
||||
|
@ -162,7 +167,8 @@ class I18nTagTests(SimpleTestCase):
|
|||
"""
|
||||
translation of constant strings
|
||||
"""
|
||||
output = render('i18n15', {'absent': '', 'LANGUAGE_CODE': 'de'})
|
||||
with translation.override('de'):
|
||||
output = self.engine.render_to_string('i18n15', {'absent': ''})
|
||||
self.assertEqual(output, 'Passwort')
|
||||
|
||||
@setup({'i18n16': '{{ _("<") }}'})
|
||||
|
@ -170,7 +176,8 @@ class I18nTagTests(SimpleTestCase):
|
|||
"""
|
||||
translation of constant strings
|
||||
"""
|
||||
output = render('i18n16', {'LANGUAGE_CODE': 'de'})
|
||||
with translation.override('de'):
|
||||
output = self.engine.render_to_string('i18n16')
|
||||
self.assertEqual(output, '<')
|
||||
|
||||
@setup({'i18n17': '{% load i18n %}'
|
||||
|
@ -179,46 +186,46 @@ class I18nTagTests(SimpleTestCase):
|
|||
"""
|
||||
Escaping inside blocktrans and trans works as if it was directly in the template.
|
||||
"""
|
||||
output = render('i18n17', {'anton': 'α & β'})
|
||||
output = self.engine.render_to_string('i18n17', {'anton': 'α & β'})
|
||||
self.assertEqual(output, 'α & β')
|
||||
|
||||
@setup({'i18n18': '{% load i18n %}'
|
||||
'{% blocktrans with berta=anton|force_escape %}{{ berta }}{% endblocktrans %}'})
|
||||
def test_i18n18(self):
|
||||
output = render('i18n18', {'anton': 'α & β'})
|
||||
output = self.engine.render_to_string('i18n18', {'anton': 'α & β'})
|
||||
self.assertEqual(output, 'α & β')
|
||||
|
||||
@setup({'i18n19': '{% load i18n %}{% blocktrans %}{{ andrew }}{% endblocktrans %}'})
|
||||
def test_i18n19(self):
|
||||
output = render('i18n19', {'andrew': 'a & b'})
|
||||
output = self.engine.render_to_string('i18n19', {'andrew': 'a & b'})
|
||||
self.assertEqual(output, 'a & b')
|
||||
|
||||
@setup({'i18n20': '{% load i18n %}{% trans andrew %}'})
|
||||
def test_i18n20(self):
|
||||
output = render('i18n20', {'andrew': 'a & b'})
|
||||
output = self.engine.render_to_string('i18n20', {'andrew': 'a & b'})
|
||||
self.assertEqual(output, 'a & b')
|
||||
|
||||
@setup({'i18n21': '{% load i18n %}{% blocktrans %}{{ andrew }}{% endblocktrans %}'})
|
||||
def test_i18n21(self):
|
||||
output = render('i18n21', {'andrew': mark_safe('a & b')})
|
||||
output = self.engine.render_to_string('i18n21', {'andrew': mark_safe('a & b')})
|
||||
self.assertEqual(output, 'a & b')
|
||||
|
||||
@setup({'i18n22': '{% load i18n %}{% trans andrew %}'})
|
||||
def test_i18n22(self):
|
||||
output = render('i18n22', {'andrew': mark_safe('a & b')})
|
||||
output = self.engine.render_to_string('i18n22', {'andrew': mark_safe('a & b')})
|
||||
self.assertEqual(output, 'a & b')
|
||||
|
||||
@setup({'legacyi18n17': '{% load i18n %}'
|
||||
'{% blocktrans with anton|escape as berta %}{{ berta }}{% endblocktrans %}'})
|
||||
def test_legacyi18n17(self):
|
||||
output = render('legacyi18n17', {'anton': 'α & β'})
|
||||
output = self.engine.render_to_string('legacyi18n17', {'anton': 'α & β'})
|
||||
self.assertEqual(output, 'α & β')
|
||||
|
||||
@setup({'legacyi18n18': '{% load i18n %}'
|
||||
'{% blocktrans with anton|force_escape as berta %}'
|
||||
'{{ berta }}{% endblocktrans %}'})
|
||||
def test_legacyi18n18(self):
|
||||
output = render('legacyi18n18', {'anton': 'α & β'})
|
||||
output = self.engine.render_to_string('legacyi18n18', {'anton': 'α & β'})
|
||||
self.assertEqual(output, 'α & β')
|
||||
|
||||
@setup({'i18n23': '{% load i18n %}{% trans "Page not found"|capfirst|slice:"6:" %}'})
|
||||
|
@ -226,17 +233,20 @@ class I18nTagTests(SimpleTestCase):
|
|||
"""
|
||||
#5972 - Use filters with the {% trans %} tag
|
||||
"""
|
||||
output = render('i18n23', {'LANGUAGE_CODE': 'de'})
|
||||
with translation.override('de'):
|
||||
output = self.engine.render_to_string('i18n23')
|
||||
self.assertEqual(output, 'nicht gefunden')
|
||||
|
||||
@setup({'i18n24': '{% load i18n %}{% trans \'Page not found\'|upper %}'})
|
||||
def test_i18n24(self):
|
||||
output = render('i18n24', {'LANGUAGE_CODE': 'de'})
|
||||
with translation.override('de'):
|
||||
output = self.engine.render_to_string('i18n24')
|
||||
self.assertEqual(output, 'SEITE NICHT GEFUNDEN')
|
||||
|
||||
@setup({'i18n25': '{% load i18n %}{% trans somevar|upper %}'})
|
||||
def test_i18n25(self):
|
||||
output = render('i18n25', {'somevar': 'Page not found', 'LANGUAGE_CODE': 'de'})
|
||||
with translation.override('de'):
|
||||
output = self.engine.render_to_string('i18n25', {'somevar': 'Page not found'})
|
||||
self.assertEqual(output, 'SEITE NICHT GEFUNDEN')
|
||||
|
||||
@setup({'i18n26': '{% load i18n %}'
|
||||
|
@ -246,14 +256,14 @@ class I18nTagTests(SimpleTestCase):
|
|||
"""
|
||||
translation of plural form with extra field in singular form (#13568)
|
||||
"""
|
||||
output = render('i18n26', {'myextra_field': 'test', 'number': 1})
|
||||
output = self.engine.render_to_string('i18n26', {'myextra_field': 'test', 'number': 1})
|
||||
self.assertEqual(output, 'singular test')
|
||||
|
||||
@setup({'legacyi18n26': '{% load i18n %}'
|
||||
'{% blocktrans with myextra_field as extra_field count number as counter %}'
|
||||
'singular {{ extra_field }}{% plural %}plural{% endblocktrans %}'})
|
||||
def test_legacyi18n26(self):
|
||||
output = render('legacyi18n26', {'myextra_field': 'test', 'number': 1})
|
||||
output = self.engine.render_to_string('legacyi18n26', {'myextra_field': 'test', 'number': 1})
|
||||
self.assertEqual(output, 'singular test')
|
||||
|
||||
@setup({'i18n27': '{% load i18n %}{% blocktrans count counter=number %}'
|
||||
|
@ -263,14 +273,16 @@ class I18nTagTests(SimpleTestCase):
|
|||
"""
|
||||
translation of singular form in russian (#14126)
|
||||
"""
|
||||
output = render('i18n27', {'number': 1, 'LANGUAGE_CODE': 'ru'})
|
||||
with translation.override('ru'):
|
||||
output = self.engine.render_to_string('i18n27', {'number': 1})
|
||||
self.assertEqual(output, '1 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442')
|
||||
|
||||
@setup({'legacyi18n27': '{% load i18n %}'
|
||||
'{% blocktrans count number as counter %}{{ counter }} result'
|
||||
'{% plural %}{{ counter }} results{% endblocktrans %}'})
|
||||
def test_legacyi18n27(self):
|
||||
output = render('legacyi18n27', {'number': 1, 'LANGUAGE_CODE': 'ru'})
|
||||
with translation.override('ru'):
|
||||
output = self.engine.render_to_string('legacyi18n27', {'number': 1})
|
||||
self.assertEqual(output, '1 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442')
|
||||
|
||||
@setup({'i18n28': '{% load i18n %}'
|
||||
|
@ -279,14 +291,14 @@ class I18nTagTests(SimpleTestCase):
|
|||
"""
|
||||
simple translation of multiple variables
|
||||
"""
|
||||
output = render('i18n28', {'anton': 'α', 'berta': 'β'})
|
||||
output = self.engine.render_to_string('i18n28', {'anton': 'α', 'berta': 'β'})
|
||||
self.assertEqual(output, 'α + β')
|
||||
|
||||
@setup({'legacyi18n28': '{% load i18n %}'
|
||||
'{% blocktrans with anton as a and berta as b %}'
|
||||
'{{ a }} + {{ b }}{% endblocktrans %}'})
|
||||
def test_legacyi18n28(self):
|
||||
output = render('legacyi18n28', {'anton': 'α', 'berta': 'β'})
|
||||
output = self.engine.render_to_string('legacyi18n28', {'anton': 'α', 'berta': 'β'})
|
||||
self.assertEqual(output, 'α + β')
|
||||
|
||||
# retrieving language information
|
||||
|
@ -294,14 +306,14 @@ class I18nTagTests(SimpleTestCase):
|
|||
'{% get_language_info for "de" as l %}'
|
||||
'{{ l.code }}: {{ l.name }}/{{ l.name_local }} bidi={{ l.bidi }}'})
|
||||
def test_i18n28_2(self):
|
||||
output = render('i18n28_2')
|
||||
output = self.engine.render_to_string('i18n28_2')
|
||||
self.assertEqual(output, 'de: German/Deutsch bidi=False')
|
||||
|
||||
@setup({'i18n29': '{% load i18n %}'
|
||||
'{% get_language_info for LANGUAGE_CODE as l %}'
|
||||
'{{ l.code }}: {{ l.name }}/{{ l.name_local }} bidi={{ l.bidi }}'})
|
||||
def test_i18n29(self):
|
||||
output = render('i18n29', {'LANGUAGE_CODE': 'fi'})
|
||||
output = self.engine.render_to_string('i18n29', {'LANGUAGE_CODE': 'fi'})
|
||||
self.assertEqual(output, 'fi: Finnish/suomi bidi=False')
|
||||
|
||||
@setup({'i18n30': '{% load i18n %}'
|
||||
|
@ -309,7 +321,7 @@ class I18nTagTests(SimpleTestCase):
|
|||
'{% for l in langs %}{{ l.code }}: {{ l.name }}/'
|
||||
'{{ l.name_local }} bidi={{ l.bidi }}; {% endfor %}'})
|
||||
def test_i18n30(self):
|
||||
output = render('i18n30', {'langcodes': ['it', 'no']})
|
||||
output = self.engine.render_to_string('i18n30', {'langcodes': ['it', 'no']})
|
||||
self.assertEqual(output, 'it: Italian/italiano bidi=False; no: Norwegian/norsk bidi=False; ')
|
||||
|
||||
@setup({'i18n31': '{% load i18n %}'
|
||||
|
@ -317,7 +329,7 @@ class I18nTagTests(SimpleTestCase):
|
|||
'{% for l in langs %}{{ l.code }}: {{ l.name }}/'
|
||||
'{{ l.name_local }} bidi={{ l.bidi }}; {% endfor %}'})
|
||||
def test_i18n31(self):
|
||||
output = render('i18n31', {'langcodes': (('sl', 'Slovenian'), ('fa', 'Persian'))})
|
||||
output = self.engine.render_to_string('i18n31', {'langcodes': (('sl', 'Slovenian'), ('fa', 'Persian'))})
|
||||
self.assertEqual(
|
||||
output,
|
||||
'sl: Slovenian/Sloven\u0161\u010dina bidi=False; '
|
||||
|
@ -327,38 +339,38 @@ class I18nTagTests(SimpleTestCase):
|
|||
@setup({'i18n32': '{% load i18n %}{{ "hu"|language_name }} '
|
||||
'{{ "hu"|language_name_local }} {{ "hu"|language_bidi }}'})
|
||||
def test_i18n32(self):
|
||||
output = render('i18n32')
|
||||
output = self.engine.render_to_string('i18n32')
|
||||
self.assertEqual(output, 'Hungarian Magyar False')
|
||||
|
||||
@setup({'i18n33': '{% load i18n %}'
|
||||
'{{ langcode|language_name }} {{ langcode|language_name_local }} '
|
||||
'{{ langcode|language_bidi }}'})
|
||||
def test_i18n33(self):
|
||||
output = render('i18n33', {'langcode': 'nl'})
|
||||
output = self.engine.render_to_string('i18n33', {'langcode': 'nl'})
|
||||
self.assertEqual(output, 'Dutch Nederlands False')
|
||||
|
||||
# blocktrans handling of variables which are not in the context.
|
||||
# this should work as if blocktrans was not there (#19915)
|
||||
@setup({'i18n34': '{% load i18n %}{% blocktrans %}{{ missing }}{% endblocktrans %}'})
|
||||
def test_i18n34(self):
|
||||
output = render('i18n34')
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
output = self.engine.render_to_string('i18n34')
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, 'INVALID')
|
||||
else:
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'i18n34_2': '{% load i18n %}{% blocktrans with a=\'α\' %}{{ missing }}{% endblocktrans %}'})
|
||||
def test_i18n34_2(self):
|
||||
output = render('i18n34_2')
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
output = self.engine.render_to_string('i18n34_2')
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, 'INVALID')
|
||||
else:
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'i18n34_3': '{% load i18n %}{% blocktrans with a=anton %}{{ missing }}{% endblocktrans %}'})
|
||||
def test_i18n34_3(self):
|
||||
output = render('i18n34_3', {'anton': '\xce\xb1'})
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
output = self.engine.render_to_string('i18n34_3', {'anton': '\xce\xb1'})
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, 'INVALID')
|
||||
else:
|
||||
self.assertEqual(output, '')
|
||||
|
@ -366,20 +378,23 @@ class I18nTagTests(SimpleTestCase):
|
|||
# trans tag with as var
|
||||
@setup({'i18n35': '{% load i18n %}{% trans "Page not found" as page_not_found %}{{ page_not_found }}'})
|
||||
def test_i18n35(self):
|
||||
output = render('i18n35', {'LANGUAGE_CODE': 'de'})
|
||||
with translation.override('de'):
|
||||
output = self.engine.render_to_string('i18n35')
|
||||
self.assertEqual(output, 'Seite nicht gefunden')
|
||||
|
||||
@setup({'i18n36': '{% load i18n %}'
|
||||
'{% trans "Page not found" noop as page_not_found %}{{ page_not_found }}'})
|
||||
def test_i18n36(self):
|
||||
output = render('i18n36', {'LANGUAGE_CODE': 'de'})
|
||||
with translation.override('de'):
|
||||
output = self.engine.render_to_string('i18n36')
|
||||
self.assertEqual(output, 'Page not found')
|
||||
|
||||
@setup({'i18n37': '{% load i18n %}'
|
||||
'{% trans "Page not found" as page_not_found %}'
|
||||
'{% blocktrans %}Error: {{ page_not_found }}{% endblocktrans %}'})
|
||||
def test_i18n37(self):
|
||||
output = render('i18n37', {'LANGUAGE_CODE': 'de'})
|
||||
with translation.override('de'):
|
||||
output = self.engine.render_to_string('i18n37')
|
||||
self.assertEqual(output, 'Error: Seite nicht gefunden')
|
||||
|
||||
# Test whitespace in filter arguments
|
||||
|
@ -387,7 +402,7 @@ class I18nTagTests(SimpleTestCase):
|
|||
'{% get_language_info for "de"|noop:"x y" as l %}'
|
||||
'{{ l.code }}: {{ l.name }}/{{ l.name_local }} bidi={{ l.bidi }}'})
|
||||
def test_i18n38(self):
|
||||
output = render('i18n38')
|
||||
output = self.engine.render_to_string('i18n38')
|
||||
self.assertEqual(output, 'de: German/Deutsch bidi=False')
|
||||
|
||||
@setup({'i18n38_2': '{% load i18n custom %}'
|
||||
|
@ -395,5 +410,5 @@ class I18nTagTests(SimpleTestCase):
|
|||
'{% for l in langs %}{{ l.code }}: {{ l.name }}/'
|
||||
'{{ l.name_local }} bidi={{ l.bidi }}; {% endfor %}'})
|
||||
def test_i18n38_2(self):
|
||||
output = render('i18n38_2', {'langcodes': ['it', 'no']})
|
||||
output = self.engine.render_to_string('i18n38_2', {'langcodes': ['it', 'no']})
|
||||
self.assertEqual(output, 'it: Italian/italiano bidi=False; no: Norwegian/norsk bidi=False; ')
|
||||
|
|
|
@ -1,256 +1,255 @@
|
|||
from django.template.base import TemplateSyntaxError
|
||||
from django.template.loader import get_template
|
||||
from django.template import TemplateSyntaxError
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup, TestObj
|
||||
from ..utils import setup, TestObj
|
||||
|
||||
|
||||
class IfTagTests(SimpleTestCase):
|
||||
|
||||
@setup({'if-tag01': '{% if foo %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag01(self):
|
||||
output = render('if-tag01', {'foo': True})
|
||||
output = self.engine.render_to_string('if-tag01', {'foo': True})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag02': '{% if foo %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag02(self):
|
||||
output = render('if-tag02', {'foo': False})
|
||||
output = self.engine.render_to_string('if-tag02', {'foo': False})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag03': '{% if foo %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag03(self):
|
||||
output = render('if-tag03')
|
||||
output = self.engine.render_to_string('if-tag03')
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag04': '{% if foo %}foo{% elif bar %}bar{% endif %}'})
|
||||
def test_if_tag04(self):
|
||||
output = render('if-tag04', {'foo': True})
|
||||
output = self.engine.render_to_string('if-tag04', {'foo': True})
|
||||
self.assertEqual(output, 'foo')
|
||||
|
||||
@setup({'if-tag05': '{% if foo %}foo{% elif bar %}bar{% endif %}'})
|
||||
def test_if_tag05(self):
|
||||
output = render('if-tag05', {'bar': True})
|
||||
output = self.engine.render_to_string('if-tag05', {'bar': True})
|
||||
self.assertEqual(output, 'bar')
|
||||
|
||||
@setup({'if-tag06': '{% if foo %}foo{% elif bar %}bar{% endif %}'})
|
||||
def test_if_tag06(self):
|
||||
output = render('if-tag06')
|
||||
output = self.engine.render_to_string('if-tag06')
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'if-tag07': '{% if foo %}foo{% elif bar %}bar{% else %}nothing{% endif %}'})
|
||||
def test_if_tag07(self):
|
||||
output = render('if-tag07', {'foo': True})
|
||||
output = self.engine.render_to_string('if-tag07', {'foo': True})
|
||||
self.assertEqual(output, 'foo')
|
||||
|
||||
@setup({'if-tag08': '{% if foo %}foo{% elif bar %}bar{% else %}nothing{% endif %}'})
|
||||
def test_if_tag08(self):
|
||||
output = render('if-tag08', {'bar': True})
|
||||
output = self.engine.render_to_string('if-tag08', {'bar': True})
|
||||
self.assertEqual(output, 'bar')
|
||||
|
||||
@setup({'if-tag09': '{% if foo %}foo{% elif bar %}bar{% else %}nothing{% endif %}'})
|
||||
def test_if_tag09(self):
|
||||
output = render('if-tag09')
|
||||
output = self.engine.render_to_string('if-tag09')
|
||||
self.assertEqual(output, 'nothing')
|
||||
|
||||
@setup({'if-tag10': '{% if foo %}foo{% elif bar %}bar{% elif baz %}baz{% else %}nothing{% endif %}'})
|
||||
def test_if_tag10(self):
|
||||
output = render('if-tag10', {'foo': True})
|
||||
output = self.engine.render_to_string('if-tag10', {'foo': True})
|
||||
self.assertEqual(output, 'foo')
|
||||
|
||||
@setup({'if-tag11': '{% if foo %}foo{% elif bar %}bar{% elif baz %}baz{% else %}nothing{% endif %}'})
|
||||
def test_if_tag11(self):
|
||||
output = render('if-tag11', {'bar': True})
|
||||
output = self.engine.render_to_string('if-tag11', {'bar': True})
|
||||
self.assertEqual(output, 'bar')
|
||||
|
||||
@setup({'if-tag12': '{% if foo %}foo{% elif bar %}bar{% elif baz %}baz{% else %}nothing{% endif %}'})
|
||||
def test_if_tag12(self):
|
||||
output = render('if-tag12', {'baz': True})
|
||||
output = self.engine.render_to_string('if-tag12', {'baz': True})
|
||||
self.assertEqual(output, 'baz')
|
||||
|
||||
@setup({'if-tag13': '{% if foo %}foo{% elif bar %}bar{% elif baz %}baz{% else %}nothing{% endif %}'})
|
||||
def test_if_tag13(self):
|
||||
output = render('if-tag13')
|
||||
output = self.engine.render_to_string('if-tag13')
|
||||
self.assertEqual(output, 'nothing')
|
||||
|
||||
# Filters
|
||||
@setup({'if-tag-filter01': '{% if foo|length == 5 %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_filter01(self):
|
||||
output = render('if-tag-filter01', {'foo': 'abcde'})
|
||||
output = self.engine.render_to_string('if-tag-filter01', {'foo': 'abcde'})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-filter02': '{% if foo|upper == \'ABC\' %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_filter02(self):
|
||||
output = render('if-tag-filter02')
|
||||
output = self.engine.render_to_string('if-tag-filter02')
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
# Equality
|
||||
@setup({'if-tag-eq01': '{% if foo == bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_eq01(self):
|
||||
output = render('if-tag-eq01')
|
||||
output = self.engine.render_to_string('if-tag-eq01')
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-eq02': '{% if foo == bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_eq02(self):
|
||||
output = render('if-tag-eq02', {'foo': 1})
|
||||
output = self.engine.render_to_string('if-tag-eq02', {'foo': 1})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-eq03': '{% if foo == bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_eq03(self):
|
||||
output = render('if-tag-eq03', {'foo': 1, 'bar': 1})
|
||||
output = self.engine.render_to_string('if-tag-eq03', {'foo': 1, 'bar': 1})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-eq04': '{% if foo == bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_eq04(self):
|
||||
output = render('if-tag-eq04', {'foo': 1, 'bar': 2})
|
||||
output = self.engine.render_to_string('if-tag-eq04', {'foo': 1, 'bar': 2})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-eq05': '{% if foo == \'\' %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_eq05(self):
|
||||
output = render('if-tag-eq05')
|
||||
output = self.engine.render_to_string('if-tag-eq05')
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
# Comparison
|
||||
@setup({'if-tag-gt-01': '{% if 2 > 1 %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_gt_01(self):
|
||||
output = render('if-tag-gt-01')
|
||||
output = self.engine.render_to_string('if-tag-gt-01')
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-gt-02': '{% if 1 > 1 %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_gt_02(self):
|
||||
output = render('if-tag-gt-02')
|
||||
output = self.engine.render_to_string('if-tag-gt-02')
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-gte-01': '{% if 1 >= 1 %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_gte_01(self):
|
||||
output = render('if-tag-gte-01')
|
||||
output = self.engine.render_to_string('if-tag-gte-01')
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-gte-02': '{% if 1 >= 2 %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_gte_02(self):
|
||||
output = render('if-tag-gte-02')
|
||||
output = self.engine.render_to_string('if-tag-gte-02')
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-lt-01': '{% if 1 < 2 %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_lt_01(self):
|
||||
output = render('if-tag-lt-01')
|
||||
output = self.engine.render_to_string('if-tag-lt-01')
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-lt-02': '{% if 1 < 1 %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_lt_02(self):
|
||||
output = render('if-tag-lt-02')
|
||||
output = self.engine.render_to_string('if-tag-lt-02')
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-lte-01': '{% if 1 <= 1 %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_lte_01(self):
|
||||
output = render('if-tag-lte-01')
|
||||
output = self.engine.render_to_string('if-tag-lte-01')
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-lte-02': '{% if 2 <= 1 %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_lte_02(self):
|
||||
output = render('if-tag-lte-02')
|
||||
output = self.engine.render_to_string('if-tag-lte-02')
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
# Contains
|
||||
@setup({'if-tag-in-01': '{% if 1 in x %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_in_01(self):
|
||||
output = render('if-tag-in-01', {'x': [1]})
|
||||
output = self.engine.render_to_string('if-tag-in-01', {'x': [1]})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-in-02': '{% if 2 in x %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_in_02(self):
|
||||
output = render('if-tag-in-02', {'x': [1]})
|
||||
output = self.engine.render_to_string('if-tag-in-02', {'x': [1]})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-not-in-01': '{% if 1 not in x %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not_in_01(self):
|
||||
output = render('if-tag-not-in-01', {'x': [1]})
|
||||
output = self.engine.render_to_string('if-tag-not-in-01', {'x': [1]})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-not-in-02': '{% if 2 not in x %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not_in_02(self):
|
||||
output = render('if-tag-not-in-02', {'x': [1]})
|
||||
output = self.engine.render_to_string('if-tag-not-in-02', {'x': [1]})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
# AND
|
||||
@setup({'if-tag-and01': '{% if foo and bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_and01(self):
|
||||
output = render('if-tag-and01', {'foo': True, 'bar': True})
|
||||
output = self.engine.render_to_string('if-tag-and01', {'foo': True, 'bar': True})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-and02': '{% if foo and bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_and02(self):
|
||||
output = render('if-tag-and02', {'foo': True, 'bar': False})
|
||||
output = self.engine.render_to_string('if-tag-and02', {'foo': True, 'bar': False})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-and03': '{% if foo and bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_and03(self):
|
||||
output = render('if-tag-and03', {'foo': False, 'bar': True})
|
||||
output = self.engine.render_to_string('if-tag-and03', {'foo': False, 'bar': True})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-and04': '{% if foo and bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_and04(self):
|
||||
output = render('if-tag-and04', {'foo': False, 'bar': False})
|
||||
output = self.engine.render_to_string('if-tag-and04', {'foo': False, 'bar': False})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-and05': '{% if foo and bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_and05(self):
|
||||
output = render('if-tag-and05', {'foo': False})
|
||||
output = self.engine.render_to_string('if-tag-and05', {'foo': False})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-and06': '{% if foo and bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_and06(self):
|
||||
output = render('if-tag-and06', {'bar': False})
|
||||
output = self.engine.render_to_string('if-tag-and06', {'bar': False})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-and07': '{% if foo and bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_and07(self):
|
||||
output = render('if-tag-and07', {'foo': True})
|
||||
output = self.engine.render_to_string('if-tag-and07', {'foo': True})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-and08': '{% if foo and bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_and08(self):
|
||||
output = render('if-tag-and08', {'bar': True})
|
||||
output = self.engine.render_to_string('if-tag-and08', {'bar': True})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
# OR
|
||||
@setup({'if-tag-or01': '{% if foo or bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_or01(self):
|
||||
output = render('if-tag-or01', {'foo': True, 'bar': True})
|
||||
output = self.engine.render_to_string('if-tag-or01', {'foo': True, 'bar': True})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-or02': '{% if foo or bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_or02(self):
|
||||
output = render('if-tag-or02', {'foo': True, 'bar': False})
|
||||
output = self.engine.render_to_string('if-tag-or02', {'foo': True, 'bar': False})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-or03': '{% if foo or bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_or03(self):
|
||||
output = render('if-tag-or03', {'foo': False, 'bar': True})
|
||||
output = self.engine.render_to_string('if-tag-or03', {'foo': False, 'bar': True})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-or04': '{% if foo or bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_or04(self):
|
||||
output = render('if-tag-or04', {'foo': False, 'bar': False})
|
||||
output = self.engine.render_to_string('if-tag-or04', {'foo': False, 'bar': False})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-or05': '{% if foo or bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_or05(self):
|
||||
output = render('if-tag-or05', {'foo': False})
|
||||
output = self.engine.render_to_string('if-tag-or05', {'foo': False})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-or06': '{% if foo or bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_or06(self):
|
||||
output = render('if-tag-or06', {'bar': False})
|
||||
output = self.engine.render_to_string('if-tag-or06', {'bar': False})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-or07': '{% if foo or bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_or07(self):
|
||||
output = render('if-tag-or07', {'foo': True})
|
||||
output = self.engine.render_to_string('if-tag-or07', {'foo': True})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-or08': '{% if foo or bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_or08(self):
|
||||
output = render('if-tag-or08', {'bar': True})
|
||||
output = self.engine.render_to_string('if-tag-or08', {'bar': True})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-or09': '{% if foo or bar or baz %}yes{% else %}no{% endif %}'})
|
||||
|
@ -258,237 +257,237 @@ class IfTagTests(SimpleTestCase):
|
|||
"""
|
||||
multiple ORs
|
||||
"""
|
||||
output = render('if-tag-or09', {'baz': True})
|
||||
output = self.engine.render_to_string('if-tag-or09', {'baz': True})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
# NOT
|
||||
@setup({'if-tag-not01': '{% if not foo %}no{% else %}yes{% endif %}'})
|
||||
def test_if_tag_not01(self):
|
||||
output = render('if-tag-not01', {'foo': True})
|
||||
output = self.engine.render_to_string('if-tag-not01', {'foo': True})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-not02': '{% if not not foo %}no{% else %}yes{% endif %}'})
|
||||
def test_if_tag_not02(self):
|
||||
output = render('if-tag-not02', {'foo': True})
|
||||
output = self.engine.render_to_string('if-tag-not02', {'foo': True})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-not06': '{% if foo and not bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not06(self):
|
||||
output = render('if-tag-not06')
|
||||
output = self.engine.render_to_string('if-tag-not06')
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-not07': '{% if foo and not bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not07(self):
|
||||
output = render('if-tag-not07', {'foo': True, 'bar': True})
|
||||
output = self.engine.render_to_string('if-tag-not07', {'foo': True, 'bar': True})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-not08': '{% if foo and not bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not08(self):
|
||||
output = render('if-tag-not08', {'foo': True, 'bar': False})
|
||||
output = self.engine.render_to_string('if-tag-not08', {'foo': True, 'bar': False})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-not09': '{% if foo and not bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not09(self):
|
||||
output = render('if-tag-not09', {'foo': False, 'bar': True})
|
||||
output = self.engine.render_to_string('if-tag-not09', {'foo': False, 'bar': True})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-not10': '{% if foo and not bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not10(self):
|
||||
output = render('if-tag-not10', {'foo': False, 'bar': False})
|
||||
output = self.engine.render_to_string('if-tag-not10', {'foo': False, 'bar': False})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-not11': '{% if not foo and bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not11(self):
|
||||
output = render('if-tag-not11')
|
||||
output = self.engine.render_to_string('if-tag-not11')
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-not12': '{% if not foo and bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not12(self):
|
||||
output = render('if-tag-not12', {'foo': True, 'bar': True})
|
||||
output = self.engine.render_to_string('if-tag-not12', {'foo': True, 'bar': True})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-not13': '{% if not foo and bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not13(self):
|
||||
output = render('if-tag-not13', {'foo': True, 'bar': False})
|
||||
output = self.engine.render_to_string('if-tag-not13', {'foo': True, 'bar': False})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-not14': '{% if not foo and bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not14(self):
|
||||
output = render('if-tag-not14', {'foo': False, 'bar': True})
|
||||
output = self.engine.render_to_string('if-tag-not14', {'foo': False, 'bar': True})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-not15': '{% if not foo and bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not15(self):
|
||||
output = render('if-tag-not15', {'foo': False, 'bar': False})
|
||||
output = self.engine.render_to_string('if-tag-not15', {'foo': False, 'bar': False})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-not16': '{% if foo or not bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not16(self):
|
||||
output = render('if-tag-not16')
|
||||
output = self.engine.render_to_string('if-tag-not16')
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-not17': '{% if foo or not bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not17(self):
|
||||
output = render('if-tag-not17', {'foo': True, 'bar': True})
|
||||
output = self.engine.render_to_string('if-tag-not17', {'foo': True, 'bar': True})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-not18': '{% if foo or not bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not18(self):
|
||||
output = render('if-tag-not18', {'foo': True, 'bar': False})
|
||||
output = self.engine.render_to_string('if-tag-not18', {'foo': True, 'bar': False})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-not19': '{% if foo or not bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not19(self):
|
||||
output = render('if-tag-not19', {'foo': False, 'bar': True})
|
||||
output = self.engine.render_to_string('if-tag-not19', {'foo': False, 'bar': True})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-not20': '{% if foo or not bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not20(self):
|
||||
output = render('if-tag-not20', {'foo': False, 'bar': False})
|
||||
output = self.engine.render_to_string('if-tag-not20', {'foo': False, 'bar': False})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-not21': '{% if not foo or bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not21(self):
|
||||
output = render('if-tag-not21')
|
||||
output = self.engine.render_to_string('if-tag-not21')
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-not22': '{% if not foo or bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not22(self):
|
||||
output = render('if-tag-not22', {'foo': True, 'bar': True})
|
||||
output = self.engine.render_to_string('if-tag-not22', {'foo': True, 'bar': True})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-not23': '{% if not foo or bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not23(self):
|
||||
output = render('if-tag-not23', {'foo': True, 'bar': False})
|
||||
output = self.engine.render_to_string('if-tag-not23', {'foo': True, 'bar': False})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-not24': '{% if not foo or bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not24(self):
|
||||
output = render('if-tag-not24', {'foo': False, 'bar': True})
|
||||
output = self.engine.render_to_string('if-tag-not24', {'foo': False, 'bar': True})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-not25': '{% if not foo or bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not25(self):
|
||||
output = render('if-tag-not25', {'foo': False, 'bar': False})
|
||||
output = self.engine.render_to_string('if-tag-not25', {'foo': False, 'bar': False})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-not26': '{% if not foo and not bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not26(self):
|
||||
output = render('if-tag-not26')
|
||||
output = self.engine.render_to_string('if-tag-not26')
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-not27': '{% if not foo and not bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not27(self):
|
||||
output = render('if-tag-not27', {'foo': True, 'bar': True})
|
||||
output = self.engine.render_to_string('if-tag-not27', {'foo': True, 'bar': True})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-not28': '{% if not foo and not bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not28(self):
|
||||
output = render('if-tag-not28', {'foo': True, 'bar': False})
|
||||
output = self.engine.render_to_string('if-tag-not28', {'foo': True, 'bar': False})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-not29': '{% if not foo and not bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not29(self):
|
||||
output = render('if-tag-not29', {'foo': False, 'bar': True})
|
||||
output = self.engine.render_to_string('if-tag-not29', {'foo': False, 'bar': True})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-not30': '{% if not foo and not bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not30(self):
|
||||
output = render('if-tag-not30', {'foo': False, 'bar': False})
|
||||
output = self.engine.render_to_string('if-tag-not30', {'foo': False, 'bar': False})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-not31': '{% if not foo or not bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not31(self):
|
||||
output = render('if-tag-not31')
|
||||
output = self.engine.render_to_string('if-tag-not31')
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-not32': '{% if not foo or not bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not32(self):
|
||||
output = render('if-tag-not32', {'foo': True, 'bar': True})
|
||||
output = self.engine.render_to_string('if-tag-not32', {'foo': True, 'bar': True})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-not33': '{% if not foo or not bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not33(self):
|
||||
output = render('if-tag-not33', {'foo': True, 'bar': False})
|
||||
output = self.engine.render_to_string('if-tag-not33', {'foo': True, 'bar': False})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-not34': '{% if not foo or not bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not34(self):
|
||||
output = render('if-tag-not34', {'foo': False, 'bar': True})
|
||||
output = self.engine.render_to_string('if-tag-not34', {'foo': False, 'bar': True})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-not35': '{% if not foo or not bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_not35(self):
|
||||
output = render('if-tag-not35', {'foo': False, 'bar': False})
|
||||
output = self.engine.render_to_string('if-tag-not35', {'foo': False, 'bar': False})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
# Various syntax errors
|
||||
@setup({'if-tag-error01': '{% if %}yes{% endif %}'})
|
||||
def test_if_tag_error01(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('if-tag-error01')
|
||||
self.engine.get_template('if-tag-error01')
|
||||
|
||||
@setup({'if-tag-error02': '{% if foo and %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_error02(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
render('if-tag-error02', {'foo': True})
|
||||
self.engine.render_to_string('if-tag-error02', {'foo': True})
|
||||
|
||||
@setup({'if-tag-error03': '{% if foo or %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_error03(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
render('if-tag-error03', {'foo': True})
|
||||
self.engine.render_to_string('if-tag-error03', {'foo': True})
|
||||
|
||||
@setup({'if-tag-error04': '{% if not foo and %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_error04(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
render('if-tag-error04', {'foo': True})
|
||||
self.engine.render_to_string('if-tag-error04', {'foo': True})
|
||||
|
||||
@setup({'if-tag-error05': '{% if not foo or %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_error05(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
render('if-tag-error05', {'foo': True})
|
||||
self.engine.render_to_string('if-tag-error05', {'foo': True})
|
||||
|
||||
@setup({'if-tag-error06': '{% if abc def %}yes{% endif %}'})
|
||||
def test_if_tag_error06(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('if-tag-error06')
|
||||
self.engine.get_template('if-tag-error06')
|
||||
|
||||
@setup({'if-tag-error07': '{% if not %}yes{% endif %}'})
|
||||
def test_if_tag_error07(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('if-tag-error07')
|
||||
self.engine.get_template('if-tag-error07')
|
||||
|
||||
@setup({'if-tag-error08': '{% if and %}yes{% endif %}'})
|
||||
def test_if_tag_error08(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('if-tag-error08')
|
||||
self.engine.get_template('if-tag-error08')
|
||||
|
||||
@setup({'if-tag-error09': '{% if or %}yes{% endif %}'})
|
||||
def test_if_tag_error09(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('if-tag-error09')
|
||||
self.engine.get_template('if-tag-error09')
|
||||
|
||||
@setup({'if-tag-error10': '{% if == %}yes{% endif %}'})
|
||||
def test_if_tag_error10(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('if-tag-error10')
|
||||
self.engine.get_template('if-tag-error10')
|
||||
|
||||
@setup({'if-tag-error11': '{% if 1 == %}yes{% endif %}'})
|
||||
def test_if_tag_error11(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('if-tag-error11')
|
||||
self.engine.get_template('if-tag-error11')
|
||||
|
||||
@setup({'if-tag-error12': '{% if a not b %}yes{% endif %}'})
|
||||
def test_if_tag_error12(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('if-tag-error12')
|
||||
self.engine.get_template('if-tag-error12')
|
||||
|
||||
@setup({'if-tag-shortcircuit01': '{% if x.is_true or x.is_bad %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_shortcircuit01(self):
|
||||
"""
|
||||
If evaluations are shortcircuited where possible
|
||||
"""
|
||||
output = render('if-tag-shortcircuit01', {'x': TestObj()})
|
||||
output = self.engine.render_to_string('if-tag-shortcircuit01', {'x': TestObj()})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-shortcircuit02': '{% if x.is_false and x.is_bad %}yes{% else %}no{% endif %}'})
|
||||
|
@ -497,7 +496,7 @@ class IfTagTests(SimpleTestCase):
|
|||
The is_bad() function should not be evaluated. If it is, an
|
||||
exception is raised.
|
||||
"""
|
||||
output = render('if-tag-shortcircuit02', {'x': TestObj()})
|
||||
output = self.engine.render_to_string('if-tag-shortcircuit02', {'x': TestObj()})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'if-tag-badarg01': '{% if x|default_if_none:y %}yes{% endif %}'})
|
||||
|
@ -505,20 +504,20 @@ class IfTagTests(SimpleTestCase):
|
|||
"""
|
||||
Non-existent args
|
||||
"""
|
||||
output = render('if-tag-badarg01')
|
||||
output = self.engine.render_to_string('if-tag-badarg01')
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'if-tag-badarg02': '{% if x|default_if_none:y %}yes{% endif %}'})
|
||||
def test_if_tag_badarg02(self):
|
||||
output = render('if-tag-badarg02', {'y': 0})
|
||||
output = self.engine.render_to_string('if-tag-badarg02', {'y': 0})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'if-tag-badarg03': '{% if x|default_if_none:y %}yes{% endif %}'})
|
||||
def test_if_tag_badarg03(self):
|
||||
output = render('if-tag-badarg03', {'y': 1})
|
||||
output = self.engine.render_to_string('if-tag-badarg03', {'y': 1})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'if-tag-badarg04': '{% if x|default_if_none:y %}yes{% else %}no{% endif %}'})
|
||||
def test_if_tag_badarg04(self):
|
||||
output = render('if-tag-badarg04')
|
||||
output = self.engine.render_to_string('if-tag-badarg04')
|
||||
self.assertEqual(output, 'no')
|
||||
|
|
|
@ -1,44 +1,44 @@
|
|||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class IfChangedTagTests(SimpleTestCase):
|
||||
|
||||
@setup({'ifchanged01': '{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}{% endfor %}'})
|
||||
def test_ifchanged01(self):
|
||||
output = render('ifchanged01', {'num': (1, 2, 3)})
|
||||
output = self.engine.render_to_string('ifchanged01', {'num': (1, 2, 3)})
|
||||
self.assertEqual(output, '123')
|
||||
|
||||
@setup({'ifchanged02': '{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}{% endfor %}'})
|
||||
def test_ifchanged02(self):
|
||||
output = render('ifchanged02', {'num': (1, 1, 3)})
|
||||
output = self.engine.render_to_string('ifchanged02', {'num': (1, 1, 3)})
|
||||
self.assertEqual(output, '13')
|
||||
|
||||
@setup({'ifchanged03': '{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}{% endfor %}'})
|
||||
def test_ifchanged03(self):
|
||||
output = render('ifchanged03', {'num': (1, 1, 1)})
|
||||
output = self.engine.render_to_string('ifchanged03', {'num': (1, 1, 1)})
|
||||
self.assertEqual(output, '1')
|
||||
|
||||
@setup({'ifchanged04': '{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}'
|
||||
'{% for x in numx %}{% ifchanged %}{{ x }}{% endifchanged %}'
|
||||
'{% endfor %}{% endfor %}'})
|
||||
def test_ifchanged04(self):
|
||||
output = render('ifchanged04', {'num': (1, 2, 3), 'numx': (2, 2, 2)})
|
||||
output = self.engine.render_to_string('ifchanged04', {'num': (1, 2, 3), 'numx': (2, 2, 2)})
|
||||
self.assertEqual(output, '122232')
|
||||
|
||||
@setup({'ifchanged05': '{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}'
|
||||
'{% for x in numx %}{% ifchanged %}{{ x }}{% endifchanged %}'
|
||||
'{% endfor %}{% endfor %}'})
|
||||
def test_ifchanged05(self):
|
||||
output = render('ifchanged05', {'num': (1, 1, 1), 'numx': (1, 2, 3)})
|
||||
output = self.engine.render_to_string('ifchanged05', {'num': (1, 1, 1), 'numx': (1, 2, 3)})
|
||||
self.assertEqual(output, '1123123123')
|
||||
|
||||
@setup({'ifchanged06': '{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}'
|
||||
'{% for x in numx %}{% ifchanged %}{{ x }}{% endifchanged %}'
|
||||
'{% endfor %}{% endfor %}'})
|
||||
def test_ifchanged06(self):
|
||||
output = render('ifchanged06', {'num': (1, 1, 1), 'numx': (2, 2, 2)})
|
||||
output = self.engine.render_to_string('ifchanged06', {'num': (1, 1, 1), 'numx': (2, 2, 2)})
|
||||
self.assertEqual(output, '1222')
|
||||
|
||||
@setup({'ifchanged07': '{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}'
|
||||
|
@ -46,14 +46,14 @@ class IfChangedTagTests(SimpleTestCase):
|
|||
'{% for y in numy %}{% ifchanged %}{{ y }}{% endifchanged %}'
|
||||
'{% endfor %}{% endfor %}{% endfor %}'})
|
||||
def test_ifchanged07(self):
|
||||
output = render('ifchanged07', {'num': (1, 1, 1), 'numx': (2, 2, 2), 'numy': (3, 3, 3)})
|
||||
output = self.engine.render_to_string('ifchanged07', {'num': (1, 1, 1), 'numx': (2, 2, 2), 'numy': (3, 3, 3)})
|
||||
self.assertEqual(output, '1233323332333')
|
||||
|
||||
@setup({'ifchanged08': '{% for data in datalist %}{% for c,d in data %}'
|
||||
'{% if c %}{% ifchanged %}{{ d }}{% endifchanged %}'
|
||||
'{% endif %}{% endfor %}{% endfor %}'})
|
||||
def test_ifchanged08(self):
|
||||
output = render('ifchanged08', {'datalist': [
|
||||
output = self.engine.render_to_string('ifchanged08', {'datalist': [
|
||||
[(1, 'a'), (1, 'a'), (0, 'b'), (1, 'c')],
|
||||
[(0, 'a'), (1, 'c'), (1, 'd'), (1, 'd'), (0, 'e')]
|
||||
]})
|
||||
|
@ -65,13 +65,13 @@ class IfChangedTagTests(SimpleTestCase):
|
|||
"""
|
||||
Test one parameter given to ifchanged.
|
||||
"""
|
||||
output = render('ifchanged-param01', {'num': (1, 2, 3)})
|
||||
output = self.engine.render_to_string('ifchanged-param01', {'num': (1, 2, 3)})
|
||||
self.assertEqual(output, '..1..2..3')
|
||||
|
||||
@setup({'ifchanged-param02': '{% for n in num %}{% for x in numx %}{% ifchanged n %}..{% endifchanged %}'
|
||||
'{{ x }}{% endfor %}{% endfor %}'})
|
||||
def test_ifchanged_param02(self):
|
||||
output = render('ifchanged-param02', {'num': (1, 2, 3), 'numx': (5, 6, 7)})
|
||||
output = self.engine.render_to_string('ifchanged-param02', {'num': (1, 2, 3), 'numx': (5, 6, 7)})
|
||||
self.assertEqual(output, '..567..567..567')
|
||||
|
||||
@setup({'ifchanged-param03': '{% for n in num %}{{ n }}{% for x in numx %}'
|
||||
|
@ -81,7 +81,7 @@ class IfChangedTagTests(SimpleTestCase):
|
|||
"""
|
||||
Test multiple parameters to ifchanged.
|
||||
"""
|
||||
output = render('ifchanged-param03', {'num': (1, 1, 2), 'numx': (5, 6, 6)})
|
||||
output = self.engine.render_to_string('ifchanged-param03', {'num': (1, 1, 2), 'numx': (5, 6, 6)})
|
||||
self.assertEqual(output, '156156256')
|
||||
|
||||
@setup({'ifchanged-param04': '{% for d in days %}{% ifchanged %}{{ d.day }}{% endifchanged %}'
|
||||
|
@ -92,7 +92,7 @@ class IfChangedTagTests(SimpleTestCase):
|
|||
Test a date+hour like construct, where the hour of the last day is
|
||||
the same but the date had changed, so print the hour anyway.
|
||||
"""
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'ifchanged-param04',
|
||||
{'days': [{'hours': [1, 2, 3], 'day': 1}, {'hours': [3], 'day': 2}]},
|
||||
)
|
||||
|
@ -106,7 +106,7 @@ class IfChangedTagTests(SimpleTestCase):
|
|||
Logically the same as above, just written with explicit ifchanged
|
||||
for the day.
|
||||
"""
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'ifchanged-param05',
|
||||
{'days': [{'hours': [1, 2, 3], 'day': 1}, {'hours': [3], 'day': 2}]},
|
||||
)
|
||||
|
@ -119,28 +119,28 @@ class IfChangedTagTests(SimpleTestCase):
|
|||
"""
|
||||
Test the else clause of ifchanged.
|
||||
"""
|
||||
output = render('ifchanged-else01', {'ids': [1, 1, 2, 2, 2, 3]})
|
||||
output = self.engine.render_to_string('ifchanged-else01', {'ids': [1, 1, 2, 2, 2, 3]})
|
||||
self.assertEqual(output, '1-first,1-other,2-first,2-other,2-other,3-first,')
|
||||
|
||||
@setup({'ifchanged-else02': '{% for id in ids %}{{ id }}-'
|
||||
'{% ifchanged id %}{% cycle red,blue %}{% else %}grey{% endifchanged %}'
|
||||
',{% endfor %}'})
|
||||
def test_ifchanged_else02(self):
|
||||
output = render('ifchanged-else02', {'ids': [1, 1, 2, 2, 2, 3]})
|
||||
output = self.engine.render_to_string('ifchanged-else02', {'ids': [1, 1, 2, 2, 2, 3]})
|
||||
self.assertEqual(output, '1-red,1-grey,2-blue,2-grey,2-grey,3-red,')
|
||||
|
||||
@setup({'ifchanged-else03': '{% for id in ids %}{{ id }}'
|
||||
'{% ifchanged id %}-{% cycle red,blue %}{% else %}{% endifchanged %}'
|
||||
',{% endfor %}'})
|
||||
def test_ifchanged_else03(self):
|
||||
output = render('ifchanged-else03', {'ids': [1, 1, 2, 2, 2, 3]})
|
||||
output = self.engine.render_to_string('ifchanged-else03', {'ids': [1, 1, 2, 2, 2, 3]})
|
||||
self.assertEqual(output, '1-red,1,2-blue,2,2,3-red,')
|
||||
|
||||
@setup({'ifchanged-else04': '{% for id in ids %}'
|
||||
'{% ifchanged %}***{{ id }}*{% else %}...{% endifchanged %}'
|
||||
'{{ forloop.counter }}{% endfor %}'})
|
||||
def test_ifchanged_else04(self):
|
||||
output = render('ifchanged-else04', {'ids': [1, 1, 2, 2, 2, 3, 4]})
|
||||
output = self.engine.render_to_string('ifchanged-else04', {'ids': [1, 1, 2, 2, 2, 3, 4]})
|
||||
self.assertEqual(output, '***1*1...2***2*3...4...5***3*6***4*7')
|
||||
|
||||
@setup({'ifchanged-filter-ws': '{% load custom %}{% for n in num %}'
|
||||
|
@ -150,5 +150,5 @@ class IfChangedTagTests(SimpleTestCase):
|
|||
"""
|
||||
Test whitespace in filter arguments
|
||||
"""
|
||||
output = render('ifchanged-filter-ws', {'num': (1, 2, 3)})
|
||||
output = self.engine.render_to_string('ifchanged-filter-ws', {'num': (1, 2, 3)})
|
||||
self.assertEqual(output, '..1..2..3')
|
||||
|
|
|
@ -1,196 +1,196 @@
|
|||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class IfEqualTagTests(SimpleTestCase):
|
||||
|
||||
@setup({'ifequal01': '{% ifequal a b %}yes{% endifequal %}'})
|
||||
def test_ifequal01(self):
|
||||
output = render('ifequal01', {'a': 1, 'b': 2})
|
||||
output = self.engine.render_to_string('ifequal01', {'a': 1, 'b': 2})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'ifequal02': '{% ifequal a b %}yes{% endifequal %}'})
|
||||
def test_ifequal02(self):
|
||||
output = render('ifequal02', {'a': 1, 'b': 1})
|
||||
output = self.engine.render_to_string('ifequal02', {'a': 1, 'b': 1})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'ifequal03': '{% ifequal a b %}yes{% else %}no{% endifequal %}'})
|
||||
def test_ifequal03(self):
|
||||
output = render('ifequal03', {'a': 1, 'b': 2})
|
||||
output = self.engine.render_to_string('ifequal03', {'a': 1, 'b': 2})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'ifequal04': '{% ifequal a b %}yes{% else %}no{% endifequal %}'})
|
||||
def test_ifequal04(self):
|
||||
output = render('ifequal04', {'a': 1, 'b': 1})
|
||||
output = self.engine.render_to_string('ifequal04', {'a': 1, 'b': 1})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'ifequal05': '{% ifequal a \'test\' %}yes{% else %}no{% endifequal %}'})
|
||||
def test_ifequal05(self):
|
||||
output = render('ifequal05', {'a': 'test'})
|
||||
output = self.engine.render_to_string('ifequal05', {'a': 'test'})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'ifequal06': '{% ifequal a \'test\' %}yes{% else %}no{% endifequal %}'})
|
||||
def test_ifequal06(self):
|
||||
output = render('ifequal06', {'a': 'no'})
|
||||
output = self.engine.render_to_string('ifequal06', {'a': 'no'})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'ifequal07': '{% ifequal a "test" %}yes{% else %}no{% endifequal %}'})
|
||||
def test_ifequal07(self):
|
||||
output = render('ifequal07', {'a': 'test'})
|
||||
output = self.engine.render_to_string('ifequal07', {'a': 'test'})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'ifequal08': '{% ifequal a "test" %}yes{% else %}no{% endifequal %}'})
|
||||
def test_ifequal08(self):
|
||||
output = render('ifequal08', {'a': 'no'})
|
||||
output = self.engine.render_to_string('ifequal08', {'a': 'no'})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'ifequal09': '{% ifequal a "test" %}yes{% else %}no{% endifequal %}'})
|
||||
def test_ifequal09(self):
|
||||
output = render('ifequal09')
|
||||
output = self.engine.render_to_string('ifequal09')
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'ifequal10': '{% ifequal a b %}yes{% else %}no{% endifequal %}'})
|
||||
def test_ifequal10(self):
|
||||
output = render('ifequal10')
|
||||
output = self.engine.render_to_string('ifequal10')
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
# SMART SPLITTING
|
||||
@setup({'ifequal-split01': '{% ifequal a "test man" %}yes{% else %}no{% endifequal %}'})
|
||||
def test_ifequal_split01(self):
|
||||
output = render('ifequal-split01')
|
||||
output = self.engine.render_to_string('ifequal-split01')
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'ifequal-split02': '{% ifequal a "test man" %}yes{% else %}no{% endifequal %}'})
|
||||
def test_ifequal_split02(self):
|
||||
output = render('ifequal-split02', {'a': 'foo'})
|
||||
output = self.engine.render_to_string('ifequal-split02', {'a': 'foo'})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'ifequal-split03': '{% ifequal a "test man" %}yes{% else %}no{% endifequal %}'})
|
||||
def test_ifequal_split03(self):
|
||||
output = render('ifequal-split03', {'a': 'test man'})
|
||||
output = self.engine.render_to_string('ifequal-split03', {'a': 'test man'})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'ifequal-split04': '{% ifequal a \'test man\' %}yes{% else %}no{% endifequal %}'})
|
||||
def test_ifequal_split04(self):
|
||||
output = render('ifequal-split04', {'a': 'test man'})
|
||||
output = self.engine.render_to_string('ifequal-split04', {'a': 'test man'})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'ifequal-split05': '{% ifequal a \'i "love" you\' %}yes{% else %}no{% endifequal %}'})
|
||||
def test_ifequal_split05(self):
|
||||
output = render('ifequal-split05', {'a': ''})
|
||||
output = self.engine.render_to_string('ifequal-split05', {'a': ''})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'ifequal-split06': '{% ifequal a \'i "love" you\' %}yes{% else %}no{% endifequal %}'})
|
||||
def test_ifequal_split06(self):
|
||||
output = render('ifequal-split06', {'a': 'i "love" you'})
|
||||
output = self.engine.render_to_string('ifequal-split06', {'a': 'i "love" you'})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'ifequal-split07': '{% ifequal a \'i "love" you\' %}yes{% else %}no{% endifequal %}'})
|
||||
def test_ifequal_split07(self):
|
||||
output = render('ifequal-split07', {'a': 'i love you'})
|
||||
output = self.engine.render_to_string('ifequal-split07', {'a': 'i love you'})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'ifequal-split08': r"{% ifequal a 'I\'m happy' %}yes{% else %}no{% endifequal %}"})
|
||||
def test_ifequal_split08(self):
|
||||
output = render('ifequal-split08', {'a': "I'm happy"})
|
||||
output = self.engine.render_to_string('ifequal-split08', {'a': "I'm happy"})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'ifequal-split09': r"{% ifequal a 'slash\man' %}yes{% else %}no{% endifequal %}"})
|
||||
def test_ifequal_split09(self):
|
||||
output = render('ifequal-split09', {'a': 'slash\man'})
|
||||
output = self.engine.render_to_string('ifequal-split09', {'a': 'slash\man'})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'ifequal-split10': r"{% ifequal a 'slash\man' %}yes{% else %}no{% endifequal %}"})
|
||||
def test_ifequal_split10(self):
|
||||
output = render('ifequal-split10', {'a': 'slashman'})
|
||||
output = self.engine.render_to_string('ifequal-split10', {'a': 'slashman'})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
# NUMERIC RESOLUTION
|
||||
@setup({'ifequal-numeric01': '{% ifequal x 5 %}yes{% endifequal %}'})
|
||||
def test_ifequal_numeric01(self):
|
||||
output = render('ifequal-numeric01', {'x': '5'})
|
||||
output = self.engine.render_to_string('ifequal-numeric01', {'x': '5'})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'ifequal-numeric02': '{% ifequal x 5 %}yes{% endifequal %}'})
|
||||
def test_ifequal_numeric02(self):
|
||||
output = render('ifequal-numeric02', {'x': 5})
|
||||
output = self.engine.render_to_string('ifequal-numeric02', {'x': 5})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'ifequal-numeric03': '{% ifequal x 5.2 %}yes{% endifequal %}'})
|
||||
def test_ifequal_numeric03(self):
|
||||
output = render('ifequal-numeric03', {'x': 5})
|
||||
output = self.engine.render_to_string('ifequal-numeric03', {'x': 5})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'ifequal-numeric04': '{% ifequal x 5.2 %}yes{% endifequal %}'})
|
||||
def test_ifequal_numeric04(self):
|
||||
output = render('ifequal-numeric04', {'x': 5.2})
|
||||
output = self.engine.render_to_string('ifequal-numeric04', {'x': 5.2})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'ifequal-numeric05': '{% ifequal x 0.2 %}yes{% endifequal %}'})
|
||||
def test_ifequal_numeric05(self):
|
||||
output = render('ifequal-numeric05', {'x': 0.2})
|
||||
output = self.engine.render_to_string('ifequal-numeric05', {'x': 0.2})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'ifequal-numeric06': '{% ifequal x .2 %}yes{% endifequal %}'})
|
||||
def test_ifequal_numeric06(self):
|
||||
output = render('ifequal-numeric06', {'x': 0.2})
|
||||
output = self.engine.render_to_string('ifequal-numeric06', {'x': 0.2})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'ifequal-numeric07': '{% ifequal x 2. %}yes{% endifequal %}'})
|
||||
def test_ifequal_numeric07(self):
|
||||
output = render('ifequal-numeric07', {'x': 2})
|
||||
output = self.engine.render_to_string('ifequal-numeric07', {'x': 2})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'ifequal-numeric08': '{% ifequal x "5" %}yes{% endifequal %}'})
|
||||
def test_ifequal_numeric08(self):
|
||||
output = render('ifequal-numeric08', {'x': 5})
|
||||
output = self.engine.render_to_string('ifequal-numeric08', {'x': 5})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'ifequal-numeric09': '{% ifequal x "5" %}yes{% endifequal %}'})
|
||||
def test_ifequal_numeric09(self):
|
||||
output = render('ifequal-numeric09', {'x': '5'})
|
||||
output = self.engine.render_to_string('ifequal-numeric09', {'x': '5'})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'ifequal-numeric10': '{% ifequal x -5 %}yes{% endifequal %}'})
|
||||
def test_ifequal_numeric10(self):
|
||||
output = render('ifequal-numeric10', {'x': -5})
|
||||
output = self.engine.render_to_string('ifequal-numeric10', {'x': -5})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'ifequal-numeric11': '{% ifequal x -5.2 %}yes{% endifequal %}'})
|
||||
def test_ifequal_numeric11(self):
|
||||
output = render('ifequal-numeric11', {'x': -5.2})
|
||||
output = self.engine.render_to_string('ifequal-numeric11', {'x': -5.2})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'ifequal-numeric12': '{% ifequal x +5 %}yes{% endifequal %}'})
|
||||
def test_ifequal_numeric12(self):
|
||||
output = render('ifequal-numeric12', {'x': 5})
|
||||
output = self.engine.render_to_string('ifequal-numeric12', {'x': 5})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
# FILTER EXPRESSIONS AS ARGUMENTS
|
||||
@setup({'ifequal-filter01': '{% ifequal a|upper "A" %}x{% endifequal %}'})
|
||||
def test_ifequal_filter01(self):
|
||||
output = render('ifequal-filter01', {'a': 'a'})
|
||||
output = self.engine.render_to_string('ifequal-filter01', {'a': 'a'})
|
||||
self.assertEqual(output, 'x')
|
||||
|
||||
@setup({'ifequal-filter02': '{% ifequal "A" a|upper %}x{% endifequal %}'})
|
||||
def test_ifequal_filter02(self):
|
||||
output = render('ifequal-filter02', {'a': 'a'})
|
||||
output = self.engine.render_to_string('ifequal-filter02', {'a': 'a'})
|
||||
self.assertEqual(output, 'x')
|
||||
|
||||
@setup({'ifequal-filter03': '{% ifequal a|upper b|upper %}x{% endifequal %}'})
|
||||
def test_ifequal_filter03(self):
|
||||
output = render('ifequal-filter03', {'a': 'x', 'b': 'X'})
|
||||
output = self.engine.render_to_string('ifequal-filter03', {'a': 'x', 'b': 'X'})
|
||||
self.assertEqual(output, 'x')
|
||||
|
||||
@setup({'ifequal-filter04': '{% ifequal x|slice:"1" "a" %}x{% endifequal %}'})
|
||||
def test_ifequal_filter04(self):
|
||||
output = render('ifequal-filter04', {'x': 'aaa'})
|
||||
output = self.engine.render_to_string('ifequal-filter04', {'x': 'aaa'})
|
||||
self.assertEqual(output, 'x')
|
||||
|
||||
@setup({'ifequal-filter05': '{% ifequal x|slice:"1"|upper "A" %}x{% endifequal %}'})
|
||||
def test_ifequal_filter05(self):
|
||||
output = render('ifequal-filter05', {'x': 'aaa'})
|
||||
output = self.engine.render_to_string('ifequal-filter05', {'x': 'aaa'})
|
||||
self.assertEqual(output, 'x')
|
||||
|
||||
|
||||
|
@ -198,20 +198,20 @@ class IfNotEqualTagTests(SimpleTestCase):
|
|||
|
||||
@setup({'ifnotequal01': '{% ifnotequal a b %}yes{% endifnotequal %}'})
|
||||
def test_ifnotequal01(self):
|
||||
output = render('ifnotequal01', {'a': 1, 'b': 2})
|
||||
output = self.engine.render_to_string('ifnotequal01', {'a': 1, 'b': 2})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'ifnotequal02': '{% ifnotequal a b %}yes{% endifnotequal %}'})
|
||||
def test_ifnotequal02(self):
|
||||
output = render('ifnotequal02', {'a': 1, 'b': 1})
|
||||
output = self.engine.render_to_string('ifnotequal02', {'a': 1, 'b': 1})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'ifnotequal03': '{% ifnotequal a b %}yes{% else %}no{% endifnotequal %}'})
|
||||
def test_ifnotequal03(self):
|
||||
output = render('ifnotequal03', {'a': 1, 'b': 2})
|
||||
output = self.engine.render_to_string('ifnotequal03', {'a': 1, 'b': 2})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'ifnotequal04': '{% ifnotequal a b %}yes{% else %}no{% endifnotequal %}'})
|
||||
def test_ifnotequal04(self):
|
||||
output = render('ifnotequal04', {'a': 1, 'b': 1})
|
||||
output = self.engine.render_to_string('ifnotequal04', {'a': 1, 'b': 1})
|
||||
self.assertEqual(output, 'no')
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
from django.conf import settings
|
||||
from django.template.base import Context, TemplateDoesNotExist, TemplateSyntaxError
|
||||
from django.template.loader import get_template
|
||||
from django.template import Context, TemplateDoesNotExist, TemplateSyntaxError
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from .test_basic import basic_templates
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
include_fail_templates = {
|
||||
|
@ -17,17 +15,17 @@ class IncludeTagTests(SimpleTestCase):
|
|||
|
||||
@setup({'include01': '{% include "basic-syntax01" %}'}, basic_templates)
|
||||
def test_include01(self):
|
||||
output = render('include01')
|
||||
output = self.engine.render_to_string('include01')
|
||||
self.assertEqual(output, 'something cool')
|
||||
|
||||
@setup({'include02': '{% include "basic-syntax02" %}'}, basic_templates)
|
||||
def test_include02(self):
|
||||
output = render('include02', {'headline': 'Included'})
|
||||
output = self.engine.render_to_string('include02', {'headline': 'Included'})
|
||||
self.assertEqual(output, 'Included')
|
||||
|
||||
@setup({'include03': '{% include template_name %}'}, basic_templates)
|
||||
def test_include03(self):
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'include03',
|
||||
{'template_name': 'basic-syntax02', 'headline': 'Included'},
|
||||
)
|
||||
|
@ -35,9 +33,9 @@ class IncludeTagTests(SimpleTestCase):
|
|||
|
||||
@setup({'include04': 'a{% include "nonexistent" %}b'})
|
||||
def test_include04(self):
|
||||
template = get_template('include04')
|
||||
template = self.engine.get_template('include04')
|
||||
|
||||
if settings.TEMPLATE_DEBUG:
|
||||
if self.engine.debug:
|
||||
with self.assertRaises(TemplateDoesNotExist):
|
||||
template.render(Context({}))
|
||||
else:
|
||||
|
@ -49,17 +47,17 @@ class IncludeTagTests(SimpleTestCase):
|
|||
'include06': '{% include "include 05"%}',
|
||||
})
|
||||
def test_include06(self):
|
||||
output = render('include06')
|
||||
output = self.engine.render_to_string('include06')
|
||||
self.assertEqual(output, "template with a space")
|
||||
|
||||
@setup({'include07': '{% include "basic-syntax02" with headline="Inline" %}'}, basic_templates)
|
||||
def test_include07(self):
|
||||
output = render('include07', {'headline': 'Included'})
|
||||
output = self.engine.render_to_string('include07', {'headline': 'Included'})
|
||||
self.assertEqual(output, 'Inline')
|
||||
|
||||
@setup({'include08': '{% include headline with headline="Dynamic" %}'}, basic_templates)
|
||||
def test_include08(self):
|
||||
output = render('include08', {'headline': 'basic-syntax02'})
|
||||
output = self.engine.render_to_string('include08', {'headline': 'basic-syntax02'})
|
||||
self.assertEqual(output, 'Dynamic')
|
||||
|
||||
@setup(
|
||||
|
@ -69,29 +67,29 @@ class IncludeTagTests(SimpleTestCase):
|
|||
basic_templates,
|
||||
)
|
||||
def test_include09(self):
|
||||
output = render('include09', {'first': 'Ul', 'second': 'lU'})
|
||||
output = self.engine.render_to_string('include09', {'first': 'Ul', 'second': 'lU'})
|
||||
self.assertEqual(output, 'Ul--LU --- UL--lU')
|
||||
|
||||
@setup({'include10': '{% include "basic-syntax03" only %}'}, basic_templates)
|
||||
def test_include10(self):
|
||||
output = render('include10', {'first': '1'})
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
output = self.engine.render_to_string('include10', {'first': '1'})
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, 'INVALID --- INVALID')
|
||||
else:
|
||||
self.assertEqual(output, ' --- ')
|
||||
|
||||
@setup({'include11': '{% include "basic-syntax03" only with second=2 %}'}, basic_templates)
|
||||
def test_include11(self):
|
||||
output = render('include11', {'first': '1'})
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
output = self.engine.render_to_string('include11', {'first': '1'})
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, 'INVALID --- 2')
|
||||
else:
|
||||
self.assertEqual(output, ' --- 2')
|
||||
|
||||
@setup({'include12': '{% include "basic-syntax03" with first=1 only %}'}, basic_templates)
|
||||
def test_include12(self):
|
||||
output = render('include12', {'second': '2'})
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
output = self.engine.render_to_string('include12', {'second': '2'})
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, '1 --- INVALID')
|
||||
else:
|
||||
self.assertEqual(output, '1 --- ')
|
||||
|
@ -101,8 +99,8 @@ class IncludeTagTests(SimpleTestCase):
|
|||
basic_templates,
|
||||
)
|
||||
def test_include13(self):
|
||||
output = render('include13', {'first': '&'})
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
output = self.engine.render_to_string('include13', {'first': '&'})
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, '& --- INVALID')
|
||||
else:
|
||||
self.assertEqual(output, '& --- ')
|
||||
|
@ -114,8 +112,8 @@ class IncludeTagTests(SimpleTestCase):
|
|||
basic_templates,
|
||||
)
|
||||
def test_include14(self):
|
||||
output = render('include14', {'var1': '&'})
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
output = self.engine.render_to_string('include14', {'var1': '&'})
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, '& --- INVALID')
|
||||
else:
|
||||
self.assertEqual(output, '& --- ')
|
||||
|
@ -124,81 +122,81 @@ class IncludeTagTests(SimpleTestCase):
|
|||
@setup({'include-error01': '{% include "basic-syntax01" with %}'})
|
||||
def test_include_error01(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('include-error01')
|
||||
self.engine.get_template('include-error01')
|
||||
|
||||
@setup({'include-error02': '{% include "basic-syntax01" with "no key" %}'})
|
||||
def test_include_error02(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('include-error02')
|
||||
self.engine.get_template('include-error02')
|
||||
|
||||
@setup({'include-error03': '{% include "basic-syntax01" with dotted.arg="error" %}'})
|
||||
def test_include_error03(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('include-error03')
|
||||
self.engine.get_template('include-error03')
|
||||
|
||||
@setup({'include-error04': '{% include "basic-syntax01" something_random %}'})
|
||||
def test_include_error04(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('include-error04')
|
||||
self.engine.get_template('include-error04')
|
||||
|
||||
@setup({'include-error05': '{% include "basic-syntax01" foo="duplicate" foo="key" %}'})
|
||||
def test_include_error05(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('include-error05')
|
||||
self.engine.get_template('include-error05')
|
||||
|
||||
@setup({'include-error06': '{% include "basic-syntax01" only only %}'})
|
||||
def test_include_error06(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('include-error06')
|
||||
self.engine.get_template('include-error06')
|
||||
|
||||
@setup(include_fail_templates)
|
||||
def test_include_fail1(self):
|
||||
with self.assertRaises(RuntimeError):
|
||||
get_template('include-fail1')
|
||||
self.engine.get_template('include-fail1')
|
||||
|
||||
@setup(include_fail_templates)
|
||||
def test_include_fail2(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('include-fail2')
|
||||
self.engine.get_template('include-fail2')
|
||||
|
||||
@setup({'include-error07': '{% include "include-fail1" %}'}, include_fail_templates)
|
||||
def test_include_error07(self):
|
||||
t = get_template('include-error07')
|
||||
template = self.engine.get_template('include-error07')
|
||||
|
||||
if settings.TEMPLATE_DEBUG:
|
||||
if self.engine.debug:
|
||||
with self.assertRaises(RuntimeError):
|
||||
t.render(Context())
|
||||
template.render(Context())
|
||||
else:
|
||||
self.assertEqual(t.render(Context()), '')
|
||||
self.assertEqual(template.render(Context()), '')
|
||||
|
||||
@setup({'include-error08': '{% include "include-fail2" %}'}, include_fail_templates)
|
||||
def test_include_error08(self):
|
||||
t = get_template('include-error08')
|
||||
template = self.engine.get_template('include-error08')
|
||||
|
||||
if settings.TEMPLATE_DEBUG:
|
||||
if self.engine.debug:
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
t.render(Context())
|
||||
template.render(Context())
|
||||
else:
|
||||
self.assertEqual(t.render(Context()), '')
|
||||
self.assertEqual(template.render(Context()), '')
|
||||
|
||||
@setup({'include-error09': '{% include failed_include %}'}, include_fail_templates)
|
||||
def test_include_error09(self):
|
||||
c = Context({'failed_include': 'include-fail1'})
|
||||
t = get_template('include-error09')
|
||||
context = Context({'failed_include': 'include-fail1'})
|
||||
template = self.engine.get_template('include-error09')
|
||||
|
||||
if settings.TEMPLATE_DEBUG:
|
||||
if self.engine.debug:
|
||||
with self.assertRaises(RuntimeError):
|
||||
t.render(c)
|
||||
template.render(context)
|
||||
else:
|
||||
self.assertEqual(t.render(c), '')
|
||||
self.assertEqual(template.render(context), '')
|
||||
|
||||
@setup({'include-error10': '{% include failed_include %}'}, include_fail_templates)
|
||||
def test_include_error10(self):
|
||||
c = Context({'failed_include': 'include-fail2'})
|
||||
t = get_template('include-error10')
|
||||
context = Context({'failed_include': 'include-fail2'})
|
||||
template = self.engine.get_template('include-error10')
|
||||
|
||||
if settings.TEMPLATE_DEBUG:
|
||||
if self.engine.debug:
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
t.render(c)
|
||||
template.render(context)
|
||||
else:
|
||||
self.assertEqual(t.render(c), '')
|
||||
self.assertEqual(template.render(context), '')
|
||||
|
|
|
@ -1,62 +1,61 @@
|
|||
from django.conf import settings
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class InvalidStringTests(SimpleTestCase):
|
||||
|
||||
@setup({'invalidstr01': '{{ var|default:"Foo" }}'})
|
||||
def test_invalidstr01(self):
|
||||
output = render('invalidstr01')
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
output = self.engine.render_to_string('invalidstr01')
|
||||
if self.engine.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:
|
||||
output = self.engine.render_to_string('invalidstr02')
|
||||
if self.engine.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')
|
||||
output = self.engine.render_to_string('invalidstr03')
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'invalidstr04': '{% if var %}Yes{% else %}No{% endif %}'})
|
||||
def test_invalidstr04(self):
|
||||
output = render('invalidstr04')
|
||||
output = self.engine.render_to_string('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')
|
||||
output = self.engine.render_to_string('invalidstr04_2')
|
||||
self.assertEqual(output, 'Yes')
|
||||
|
||||
@setup({'invalidstr05': '{{ var }}'})
|
||||
def test_invalidstr05(self):
|
||||
output = render('invalidstr05')
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
output = self.engine.render_to_string('invalidstr05')
|
||||
if self.engine.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:
|
||||
output = self.engine.render_to_string('invalidstr06')
|
||||
if self.engine.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:
|
||||
output = self.engine.render_to_string('invalidstr07')
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, 'INVALID')
|
||||
else:
|
||||
self.assertEqual(output, '')
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
from django.conf import settings
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class ListIndexTests(SimpleTestCase):
|
||||
|
@ -12,7 +11,7 @@ class ListIndexTests(SimpleTestCase):
|
|||
List-index syntax allows a template to access a certain item of a
|
||||
subscriptable object.
|
||||
"""
|
||||
output = render('list-index01', {'var': ['first item', 'second item']})
|
||||
output = self.engine.render_to_string('list-index01', {'var': ['first item', 'second item']})
|
||||
self.assertEqual(output, 'second item')
|
||||
|
||||
@setup({'list-index02': '{{ var.5 }}'})
|
||||
|
@ -20,8 +19,8 @@ class ListIndexTests(SimpleTestCase):
|
|||
"""
|
||||
Fail silently when the list index is out of range.
|
||||
"""
|
||||
output = render('list-index02', {'var': ['first item', 'second item']})
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
output = self.engine.render_to_string('list-index02', {'var': ['first item', 'second item']})
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, 'INVALID')
|
||||
else:
|
||||
self.assertEqual(output, '')
|
||||
|
@ -31,8 +30,8 @@ class ListIndexTests(SimpleTestCase):
|
|||
"""
|
||||
Fail silently when the list index is out of range.
|
||||
"""
|
||||
output = render('list-index03', {'var': None})
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
output = self.engine.render_to_string('list-index03', {'var': None})
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, 'INVALID')
|
||||
else:
|
||||
self.assertEqual(output, '')
|
||||
|
@ -42,8 +41,8 @@ class ListIndexTests(SimpleTestCase):
|
|||
"""
|
||||
Fail silently when variable is a dict without the specified key.
|
||||
"""
|
||||
output = render('list-index04', {'var': {}})
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
output = self.engine.render_to_string('list-index04', {'var': {}})
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, 'INVALID')
|
||||
else:
|
||||
self.assertEqual(output, '')
|
||||
|
@ -53,7 +52,7 @@ class ListIndexTests(SimpleTestCase):
|
|||
"""
|
||||
Dictionary lookup wins out when dict's key is a string.
|
||||
"""
|
||||
output = render('list-index05', {'var': {'1': "hello"}})
|
||||
output = self.engine.render_to_string('list-index05', {'var': {'1': "hello"}})
|
||||
self.assertEqual(output, 'hello')
|
||||
|
||||
@setup({'list-index06': '{{ var.1 }}'})
|
||||
|
@ -63,7 +62,7 @@ class ListIndexTests(SimpleTestCase):
|
|||
behind the scenes is really a dictionary lookup (for a dict)
|
||||
after converting the key to an int.
|
||||
"""
|
||||
output = render('list-index06', {"var": {1: "hello"}})
|
||||
output = self.engine.render_to_string('list-index06', {"var": {1: "hello"}})
|
||||
self.assertEqual(output, 'hello')
|
||||
|
||||
@setup({'list-index07': '{{ var.1 }}'})
|
||||
|
@ -72,5 +71,5 @@ class ListIndexTests(SimpleTestCase):
|
|||
Dictionary lookup wins out when there is a string and int version
|
||||
of the key.
|
||||
"""
|
||||
output = render('list-index07', {"var": {'1': "hello", 1: "world"}})
|
||||
output = self.engine.render_to_string('list-index07', {"var": {'1': "hello", 1: "world"}})
|
||||
self.assertEqual(output, 'hello')
|
||||
|
|
|
@ -1,72 +1,71 @@
|
|||
from django.template.base import TemplateSyntaxError
|
||||
from django.template.loader import get_template
|
||||
from django.template import TemplateSyntaxError
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class LoadTagTests(SimpleTestCase):
|
||||
|
||||
@setup({'load01': '{% load testtags subpackage.echo %}{% echo test %} {% echo2 "test" %}'})
|
||||
def test_load01(self):
|
||||
output = render('load01')
|
||||
output = self.engine.render_to_string('load01')
|
||||
self.assertEqual(output, 'test test')
|
||||
|
||||
@setup({'load02': '{% load subpackage.echo %}{% echo2 "test" %}'})
|
||||
def test_load02(self):
|
||||
output = render('load02')
|
||||
output = self.engine.render_to_string('load02')
|
||||
self.assertEqual(output, 'test')
|
||||
|
||||
# {% load %} tag, importing individual tags
|
||||
@setup({'load03': '{% load echo from testtags %}{% echo this that theother %}'})
|
||||
def test_load03(self):
|
||||
output = render('load03')
|
||||
output = self.engine.render_to_string('load03')
|
||||
self.assertEqual(output, 'this that theother')
|
||||
|
||||
@setup({'load04': '{% load echo other_echo from testtags %}'
|
||||
'{% echo this that theother %} {% other_echo and another thing %}'})
|
||||
def test_load04(self):
|
||||
output = render('load04')
|
||||
output = self.engine.render_to_string('load04')
|
||||
self.assertEqual(output, 'this that theother and another thing')
|
||||
|
||||
@setup({'load05': '{% load echo upper from testtags %}'
|
||||
'{% echo this that theother %} {{ statement|upper }}'})
|
||||
def test_load05(self):
|
||||
output = render('load05', {'statement': 'not shouting'})
|
||||
output = self.engine.render_to_string('load05', {'statement': 'not shouting'})
|
||||
self.assertEqual(output, 'this that theother NOT SHOUTING')
|
||||
|
||||
@setup({'load06': '{% load echo2 from subpackage.echo %}{% echo2 "test" %}'})
|
||||
def test_load06(self):
|
||||
output = render('load06')
|
||||
output = self.engine.render_to_string('load06')
|
||||
self.assertEqual(output, 'test')
|
||||
|
||||
# {% load %} tag errors
|
||||
@setup({'load07': '{% load echo other_echo bad_tag from testtags %}'})
|
||||
def test_load07(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('load07')
|
||||
self.engine.get_template('load07')
|
||||
|
||||
@setup({'load08': '{% load echo other_echo bad_tag from %}'})
|
||||
def test_load08(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('load08')
|
||||
self.engine.get_template('load08')
|
||||
|
||||
@setup({'load09': '{% load from testtags %}'})
|
||||
def test_load09(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('load09')
|
||||
self.engine.get_template('load09')
|
||||
|
||||
@setup({'load10': '{% load echo from bad_library %}'})
|
||||
def test_load10(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('load10')
|
||||
self.engine.get_template('load10')
|
||||
|
||||
@setup({'load11': '{% load subpackage.echo_invalid %}'})
|
||||
def test_load11(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('load11')
|
||||
self.engine.get_template('load11')
|
||||
|
||||
@setup({'load12': '{% load subpackage.missing %}'})
|
||||
def test_load12(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('load12')
|
||||
self.engine.get_template('load12')
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class LoremTagTests(SimpleTestCase):
|
||||
|
||||
@setup({'lorem1': '{% lorem 3 w %}'})
|
||||
def test_lorem1(self):
|
||||
output = render('lorem1')
|
||||
output = self.engine.render_to_string('lorem1')
|
||||
self.assertEqual(output, 'lorem ipsum dolor')
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
multiline_string = """
|
||||
|
@ -17,5 +17,5 @@ class MultilineTests(SimpleTestCase):
|
|||
|
||||
@setup({'multiline01': multiline_string})
|
||||
def test_multiline01(self):
|
||||
output = render('multiline01')
|
||||
output = self.engine.render_to_string('multiline01')
|
||||
self.assertEqual(output, multiline_string)
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
from django.template.base import TemplateSyntaxError
|
||||
from django.template.loader import get_template
|
||||
from django.template import TemplateSyntaxError
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class NamedEndblockTests(SimpleTestCase):
|
||||
|
@ -10,7 +9,7 @@ class NamedEndblockTests(SimpleTestCase):
|
|||
@setup({'namedendblocks01': '1{% block first %}_{% block second %}'
|
||||
'2{% endblock second %}_{% endblock first %}3'})
|
||||
def test_namedendblocks01(self):
|
||||
output = render('namedendblocks01')
|
||||
output = self.engine.render_to_string('namedendblocks01')
|
||||
self.assertEqual(output, '1_2_3')
|
||||
|
||||
# Unbalanced blocks
|
||||
|
@ -18,24 +17,24 @@ class NamedEndblockTests(SimpleTestCase):
|
|||
'2{% endblock first %}_{% endblock second %}3'})
|
||||
def test_namedendblocks02(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('namedendblocks02')
|
||||
self.engine.get_template('namedendblocks02')
|
||||
|
||||
@setup({'namedendblocks03': '1{% block first %}_{% block second %}'
|
||||
'2{% endblock %}_{% endblock second %}3'})
|
||||
def test_namedendblocks03(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('namedendblocks03')
|
||||
self.engine.get_template('namedendblocks03')
|
||||
|
||||
@setup({'namedendblocks04': '1{% block first %}_{% block second %}'
|
||||
'2{% endblock second %}_{% endblock third %}3'})
|
||||
def test_namedendblocks04(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('namedendblocks04')
|
||||
self.engine.get_template('namedendblocks04')
|
||||
|
||||
@setup({'namedendblocks05': '1{% block first %}_{% block second %}2{% endblock first %}'})
|
||||
def test_namedendblocks05(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('namedendblocks05')
|
||||
self.engine.get_template('namedendblocks05')
|
||||
|
||||
# Mixed named and unnamed endblocks
|
||||
@setup({'namedendblocks06': '1{% block first %}_{% block second %}'
|
||||
|
@ -44,11 +43,11 @@ class NamedEndblockTests(SimpleTestCase):
|
|||
"""
|
||||
Mixed named and unnamed endblocks
|
||||
"""
|
||||
output = render('namedendblocks06')
|
||||
output = self.engine.render_to_string('namedendblocks06')
|
||||
self.assertEqual(output, '1_2_3')
|
||||
|
||||
@setup({'namedendblocks07': '1{% block first %}_{% block second %}'
|
||||
'2{% endblock second %}_{% endblock %}3'})
|
||||
def test_namedendblocks07(self):
|
||||
output = render('namedendblocks07')
|
||||
output = self.engine.render_to_string('namedendblocks07')
|
||||
self.assertEqual(output, '1_2_3')
|
||||
|
|
|
@ -3,7 +3,7 @@ from datetime import datetime
|
|||
from django.test import SimpleTestCase
|
||||
from django.utils.formats import date_format
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class NowTagTests(SimpleTestCase):
|
||||
|
@ -13,7 +13,7 @@ class NowTagTests(SimpleTestCase):
|
|||
"""
|
||||
Simple case
|
||||
"""
|
||||
output = render('now01')
|
||||
output = self.engine.render_to_string('now01')
|
||||
self.assertEqual(output, "%d %d %d" % (
|
||||
datetime.now().day, datetime.now().month, datetime.now().year,
|
||||
))
|
||||
|
@ -21,7 +21,7 @@ class NowTagTests(SimpleTestCase):
|
|||
# Check parsing of locale strings
|
||||
@setup({'now02': '{% now "DATE_FORMAT" %}'})
|
||||
def test_now02(self):
|
||||
output = render('now02')
|
||||
output = self.engine.render_to_string('now02')
|
||||
self.assertEqual(output, date_format(datetime.now()))
|
||||
|
||||
@setup({'now03': '{% now \'j n Y\' %}'})
|
||||
|
@ -29,33 +29,33 @@ class NowTagTests(SimpleTestCase):
|
|||
"""
|
||||
#15092 - Also accept simple quotes
|
||||
"""
|
||||
output = render('now03')
|
||||
output = self.engine.render_to_string('now03')
|
||||
self.assertEqual(output, "%d %d %d" % (
|
||||
datetime.now().day, datetime.now().month, datetime.now().year,
|
||||
))
|
||||
|
||||
@setup({'now04': '{% now \'DATE_FORMAT\' %}'})
|
||||
def test_now04(self):
|
||||
output = render('now04')
|
||||
output = self.engine.render_to_string('now04')
|
||||
self.assertEqual(output, date_format(datetime.now()))
|
||||
|
||||
@setup({'now05': '{% now \'j "n" Y\'%}'})
|
||||
def test_now05(self):
|
||||
output = render('now05')
|
||||
output = self.engine.render_to_string('now05')
|
||||
self.assertEqual(output, '%d "%d" %d' % (
|
||||
datetime.now().day, datetime.now().month, datetime.now().year,
|
||||
))
|
||||
|
||||
@setup({'now06': '{% now "j \'n\' Y"%}'})
|
||||
def test_now06(self):
|
||||
output = render('now06')
|
||||
output = self.engine.render_to_string('now06')
|
||||
self.assertEqual(output, "%d '%d' %d" % (
|
||||
datetime.now().day, datetime.now().month, datetime.now().year,
|
||||
))
|
||||
|
||||
@setup({'now07': '{% now "j n Y" as N %}-{{N}}-'})
|
||||
def test_now07(self):
|
||||
output = render('now07')
|
||||
output = self.engine.render_to_string('now07')
|
||||
self.assertEqual(output, '-%d %d %d-' % (
|
||||
datetime.now().day, datetime.now().month, datetime.now().year,
|
||||
))
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
from unittest import skipIf
|
||||
import warnings
|
||||
|
||||
from django.conf import settings
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
try:
|
||||
import numpy
|
||||
|
@ -28,7 +27,7 @@ class NumpyTests(SimpleTestCase):
|
|||
Numpy's array-index syntax allows a template to access a certain
|
||||
item of a subscriptable object.
|
||||
"""
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'numpy-array-index01',
|
||||
{'var': numpy.array(["first item", "second item"])},
|
||||
)
|
||||
|
@ -39,11 +38,11 @@ class NumpyTests(SimpleTestCase):
|
|||
"""
|
||||
Fail silently when the array index is out of range.
|
||||
"""
|
||||
output = render(
|
||||
output = self.engine.render_to_string(
|
||||
'numpy-array-index02',
|
||||
{'var': numpy.array(["first item", "second item"])},
|
||||
)
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, 'INVALID')
|
||||
else:
|
||||
self.assertEqual(output, '')
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
from datetime import date
|
||||
|
||||
from django.template.base import TemplateSyntaxError
|
||||
from django.template.loader import get_template
|
||||
from django.template import TemplateSyntaxError
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class RegroupTagTests(SimpleTestCase):
|
||||
|
@ -18,7 +17,7 @@ class RegroupTagTests(SimpleTestCase):
|
|||
'{% endfor %},'
|
||||
'{% endfor %}'})
|
||||
def test_regroup01(self):
|
||||
output = render('regroup01', {
|
||||
output = self.engine.render_to_string('regroup01', {
|
||||
'data': [{'foo': 'c', 'bar': 1},
|
||||
{'foo': 'd', 'bar': 1},
|
||||
{'foo': 'a', 'bar': 2},
|
||||
|
@ -39,7 +38,7 @@ class RegroupTagTests(SimpleTestCase):
|
|||
"""
|
||||
Test for silent failure when target variable isn't found
|
||||
"""
|
||||
output = render('regroup02', {})
|
||||
output = self.engine.render_to_string('regroup02', {})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'regroup03': ''
|
||||
|
@ -55,7 +54,7 @@ class RegroupTagTests(SimpleTestCase):
|
|||
Regression tests for #17675
|
||||
The date template filter has expects_localtime = True
|
||||
"""
|
||||
output = render('regroup03', {
|
||||
output = self.engine.render_to_string('regroup03', {
|
||||
'data': [{'at': date(2012, 2, 14)},
|
||||
{'at': date(2012, 2, 28)},
|
||||
{'at': date(2012, 7, 4)}],
|
||||
|
@ -74,7 +73,7 @@ class RegroupTagTests(SimpleTestCase):
|
|||
"""
|
||||
The join template filter has needs_autoescape = True
|
||||
"""
|
||||
output = render('regroup04', {
|
||||
output = self.engine.render_to_string('regroup04', {
|
||||
'data': [{'foo': 'x', 'bar': ['ab', 'c']},
|
||||
{'foo': 'y', 'bar': ['a', 'bc']},
|
||||
{'foo': 'z', 'bar': ['a', 'd']}],
|
||||
|
@ -85,19 +84,19 @@ class RegroupTagTests(SimpleTestCase):
|
|||
@setup({'regroup05': '{% regroup data by bar as %}'})
|
||||
def test_regroup05(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('regroup05')
|
||||
self.engine.get_template('regroup05')
|
||||
|
||||
@setup({'regroup06': '{% regroup data by bar thisaintright grouped %}'})
|
||||
def test_regroup06(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('regroup06')
|
||||
self.engine.get_template('regroup06')
|
||||
|
||||
@setup({'regroup07': '{% regroup data thisaintright bar as grouped %}'})
|
||||
def test_regroup07(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('regroup07')
|
||||
self.engine.get_template('regroup07')
|
||||
|
||||
@setup({'regroup08': '{% regroup data by bar as grouped toomanyargs %}'})
|
||||
def test_regroup08(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('regroup08')
|
||||
self.engine.get_template('regroup08')
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from django.conf import settings
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import setup
|
||||
|
@ -15,8 +14,8 @@ class SetupTests(SimpleTestCase):
|
|||
@setup({})
|
||||
def method(self):
|
||||
cases.append([
|
||||
settings.TEMPLATE_STRING_IF_INVALID,
|
||||
settings.TEMPLATE_DEBUG,
|
||||
self.engine.string_if_invalid,
|
||||
self.engine.debug,
|
||||
])
|
||||
|
||||
method(self)
|
||||
|
|
|
@ -1,23 +1,22 @@
|
|||
from django.template.base import TemplateSyntaxError
|
||||
from django.template.loader import get_template
|
||||
from django.template import TemplateSyntaxError
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class SimpleTagTests(SimpleTestCase):
|
||||
|
||||
@setup({'simpletag-renamed01': '{% load custom %}{% minusone 7 %}'})
|
||||
def test_simpletag_renamed01(self):
|
||||
output = render('simpletag-renamed01')
|
||||
output = self.engine.render_to_string('simpletag-renamed01')
|
||||
self.assertEqual(output, '6')
|
||||
|
||||
@setup({'simpletag-renamed02': '{% load custom %}{% minustwo 7 %}'})
|
||||
def test_simpletag_renamed02(self):
|
||||
output = render('simpletag-renamed02')
|
||||
output = self.engine.render_to_string('simpletag-renamed02')
|
||||
self.assertEqual(output, '5')
|
||||
|
||||
@setup({'simpletag-renamed03': '{% load custom %}{% minustwo_overridden_name 7 %}'})
|
||||
def test_simpletag_renamed03(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('simpletag-renamed03')
|
||||
self.engine.get_template('simpletag-renamed03')
|
||||
|
|
|
@ -1,38 +1,38 @@
|
|||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class SpacelessTagTests(SimpleTestCase):
|
||||
|
||||
@setup({'spaceless01': "{% spaceless %} <b> <i> text </i> </b> {% endspaceless %}"})
|
||||
def test_spaceless01(self):
|
||||
output = render('spaceless01')
|
||||
output = self.engine.render_to_string('spaceless01')
|
||||
self.assertEqual(output, "<b><i> text </i></b>")
|
||||
|
||||
@setup({'spaceless02': "{% spaceless %} <b> \n <i> text </i> \n </b> {% endspaceless %}"})
|
||||
def test_spaceless02(self):
|
||||
output = render('spaceless02')
|
||||
output = self.engine.render_to_string('spaceless02')
|
||||
self.assertEqual(output, "<b><i> text </i></b>")
|
||||
|
||||
@setup({'spaceless03': "{% spaceless %}<b><i>text</i></b>{% endspaceless %}"})
|
||||
def test_spaceless03(self):
|
||||
output = render('spaceless03')
|
||||
output = self.engine.render_to_string('spaceless03')
|
||||
self.assertEqual(output, "<b><i>text</i></b>")
|
||||
|
||||
@setup({'spaceless04': "{% spaceless %}<b> <i>{{ text }}</i> </b>{% endspaceless %}"})
|
||||
def test_spaceless04(self):
|
||||
output = render('spaceless04', {'text': 'This & that'})
|
||||
output = self.engine.render_to_string('spaceless04', {'text': 'This & that'})
|
||||
self.assertEqual(output, "<b><i>This & that</i></b>")
|
||||
|
||||
@setup({'spaceless05': "{% autoescape off %}{% spaceless %}"
|
||||
"<b> <i>{{ text }}</i> </b>{% endspaceless %}"
|
||||
"{% endautoescape %}"})
|
||||
def test_spaceless05(self):
|
||||
output = render('spaceless05', {'text': 'This & that'})
|
||||
output = self.engine.render_to_string('spaceless05', {'text': 'This & that'})
|
||||
self.assertEqual(output, "<b><i>This & that</i></b>")
|
||||
|
||||
@setup({'spaceless06': "{% spaceless %}<b> <i>{{ text|safe }}</i> </b>{% endspaceless %}"})
|
||||
def test_spaceless06(self):
|
||||
output = render('spaceless06', {'text': 'This & that'})
|
||||
output = self.engine.render_to_string('spaceless06', {'text': 'This & that'})
|
||||
self.assertEqual(output, "<b><i>This & that</i></b>")
|
||||
|
|
|
@ -1,40 +1,34 @@
|
|||
import os
|
||||
import warnings
|
||||
|
||||
from django.test import override_settings, SimpleTestCase
|
||||
from django.utils._os import upath
|
||||
from django.test import SimpleTestCase
|
||||
from django.utils.deprecation import RemovedInDjango19Warning
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import ROOT, setup
|
||||
|
||||
|
||||
cwd = os.path.dirname(os.path.abspath(upath(__file__)))
|
||||
root = os.path.abspath(os.path.join(cwd, ".."))
|
||||
|
||||
|
||||
@override_settings(ALLOWED_INCLUDE_ROOTS=(root))
|
||||
class SsiTagTests(SimpleTestCase):
|
||||
|
||||
# Test normal behavior
|
||||
@setup({'ssi01': '{%% ssi "%s" %%}' % os.path.join(
|
||||
root, 'templates', 'ssi_include.html',
|
||||
ROOT, 'templates', 'ssi_include.html',
|
||||
)})
|
||||
def test_ssi01(self):
|
||||
output = render('ssi01')
|
||||
output = self.engine.render_to_string('ssi01')
|
||||
self.assertEqual(output, 'This is for testing an ssi include. {{ test }}\n')
|
||||
|
||||
@setup({'ssi02': '{%% ssi "%s" %%}' % os.path.join(
|
||||
root, 'not_here',
|
||||
ROOT, 'not_here',
|
||||
)})
|
||||
def test_ssi02(self):
|
||||
output = render('ssi02')
|
||||
output = self.engine.render_to_string('ssi02')
|
||||
self.assertEqual(output, ''),
|
||||
|
||||
@setup({'ssi03': "{%% ssi '%s' %%}" % os.path.join(
|
||||
root, 'not_here',
|
||||
ROOT, 'not_here',
|
||||
)})
|
||||
def test_ssi03(self):
|
||||
output = render('ssi03')
|
||||
output = self.engine.render_to_string('ssi03')
|
||||
self.assertEqual(output, ''),
|
||||
|
||||
# Test passing as a variable
|
||||
|
@ -42,8 +36,8 @@ class SsiTagTests(SimpleTestCase):
|
|||
def test_ssi04(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango19Warning)
|
||||
output = render('ssi04', {
|
||||
'ssi_file': os.path.join(root, 'templates', 'ssi_include.html')
|
||||
output = self.engine.render_to_string('ssi04', {
|
||||
'ssi_file': os.path.join(ROOT, 'templates', 'ssi_include.html')
|
||||
})
|
||||
self.assertEqual(output, 'This is for testing an ssi include. {{ test }}\n')
|
||||
|
||||
|
@ -51,38 +45,38 @@ class SsiTagTests(SimpleTestCase):
|
|||
def test_ssi05(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango19Warning)
|
||||
output = render('ssi05', {'ssi_file': 'no_file'})
|
||||
output = self.engine.render_to_string('ssi05', {'ssi_file': 'no_file'})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
# Test parsed output
|
||||
@setup({'ssi06': '{%% ssi "%s" parsed %%}' % os.path.join(
|
||||
root, 'templates', 'ssi_include.html',
|
||||
ROOT, 'templates', 'ssi_include.html',
|
||||
)})
|
||||
def test_ssi06(self):
|
||||
output = render('ssi06', {'test': 'Look ma! It parsed!'})
|
||||
output = self.engine.render_to_string('ssi06', {'test': 'Look ma! It parsed!'})
|
||||
self.assertEqual(output, 'This is for testing an ssi include. '
|
||||
'Look ma! It parsed!\n')
|
||||
|
||||
@setup({'ssi07': '{%% ssi "%s" parsed %%}' % os.path.join(
|
||||
root, 'not_here',
|
||||
ROOT, 'not_here',
|
||||
)})
|
||||
def test_ssi07(self):
|
||||
output = render('ssi07', {'test': 'Look ma! It parsed!'})
|
||||
output = self.engine.render_to_string('ssi07', {'test': 'Look ma! It parsed!'})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
# Test space in file name
|
||||
@setup({'ssi08': '{%% ssi "%s" %%}' % os.path.join(
|
||||
root, 'templates', 'ssi include with spaces.html',
|
||||
ROOT, 'templates', 'ssi include with spaces.html',
|
||||
)})
|
||||
def test_ssi08(self):
|
||||
output = render('ssi08')
|
||||
output = self.engine.render_to_string('ssi08')
|
||||
self.assertEqual(output, 'This is for testing an ssi include '
|
||||
'with spaces in its name. {{ test }}\n')
|
||||
|
||||
@setup({'ssi09': '{%% ssi "%s" parsed %%}' % os.path.join(
|
||||
root, 'templates', 'ssi include with spaces.html',
|
||||
ROOT, 'templates', 'ssi include with spaces.html',
|
||||
)})
|
||||
def test_ssi09(self):
|
||||
output = render('ssi09', {'test': 'Look ma! It parsed!'})
|
||||
output = self.engine.render_to_string('ssi09', {'test': 'Look ma! It parsed!'})
|
||||
self.assertEqual(output, 'This is for testing an ssi include '
|
||||
'with spaces in its name. Look ma! It parsed!\n')
|
||||
|
|
|
@ -2,7 +2,7 @@ from django.conf import settings
|
|||
from django.test import override_settings, SimpleTestCase
|
||||
from django.utils.six.moves.urllib.parse import urljoin
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
@override_settings(MEDIA_URL="/media/", STATIC_URL="/static/")
|
||||
|
@ -10,42 +10,42 @@ class StaticTagTests(SimpleTestCase):
|
|||
|
||||
@setup({'static-prefixtag01': '{% load static %}{% get_static_prefix %}'})
|
||||
def test_static_prefixtag01(self):
|
||||
output = render('static-prefixtag01')
|
||||
output = self.engine.render_to_string('static-prefixtag01')
|
||||
self.assertEqual(output, settings.STATIC_URL)
|
||||
|
||||
@setup({'static-prefixtag02': '{% load static %}'
|
||||
'{% get_static_prefix as static_prefix %}{{ static_prefix }}'})
|
||||
def test_static_prefixtag02(self):
|
||||
output = render('static-prefixtag02')
|
||||
output = self.engine.render_to_string('static-prefixtag02')
|
||||
self.assertEqual(output, settings.STATIC_URL)
|
||||
|
||||
@setup({'static-prefixtag03': '{% load static %}{% get_media_prefix %}'})
|
||||
def test_static_prefixtag03(self):
|
||||
output = render('static-prefixtag03')
|
||||
output = self.engine.render_to_string('static-prefixtag03')
|
||||
self.assertEqual(output, settings.MEDIA_URL)
|
||||
|
||||
@setup({'static-prefixtag04': '{% load static %}'
|
||||
'{% get_media_prefix as media_prefix %}{{ media_prefix }}'})
|
||||
def test_static_prefixtag04(self):
|
||||
output = render('static-prefixtag04')
|
||||
output = self.engine.render_to_string('static-prefixtag04')
|
||||
self.assertEqual(output, settings.MEDIA_URL)
|
||||
|
||||
@setup({'static-statictag01': '{% load static %}{% static "admin/base.css" %}'})
|
||||
def test_static_statictag01(self):
|
||||
output = render('static-statictag01')
|
||||
output = self.engine.render_to_string('static-statictag01')
|
||||
self.assertEqual(output, urljoin(settings.STATIC_URL, 'admin/base.css'))
|
||||
|
||||
@setup({'static-statictag02': '{% load static %}{% static base_css %}'})
|
||||
def test_static_statictag02(self):
|
||||
output = render('static-statictag02', {'base_css': 'admin/base.css'})
|
||||
output = self.engine.render_to_string('static-statictag02', {'base_css': 'admin/base.css'})
|
||||
self.assertEqual(output, urljoin(settings.STATIC_URL, 'admin/base.css'))
|
||||
|
||||
@setup({'static-statictag03': '{% load static %}{% static "admin/base.css" as foo %}{{ foo }}'})
|
||||
def test_static_statictag03(self):
|
||||
output = render('static-statictag03')
|
||||
output = self.engine.render_to_string('static-statictag03')
|
||||
self.assertEqual(output, urljoin(settings.STATIC_URL, 'admin/base.css'))
|
||||
|
||||
@setup({'static-statictag04': '{% load static %}{% static base_css as foo %}{{ foo }}'})
|
||||
def test_static_statictag04(self):
|
||||
output = render('static-statictag04', {'base_css': 'admin/base.css'})
|
||||
output = self.engine.render_to_string('static-statictag04', {'base_css': 'admin/base.css'})
|
||||
self.assertEqual(output, urljoin(settings.STATIC_URL, 'admin/base.css'))
|
||||
|
|
|
@ -1,68 +1,67 @@
|
|||
from django.template.base import TemplateSyntaxError
|
||||
from django.template.loader import get_template
|
||||
from django.template import TemplateSyntaxError
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class TemplateTagTests(SimpleTestCase):
|
||||
|
||||
@setup({'templatetag01': '{% templatetag openblock %}'})
|
||||
def test_templatetag01(self):
|
||||
output = render('templatetag01')
|
||||
output = self.engine.render_to_string('templatetag01')
|
||||
self.assertEqual(output, '{%')
|
||||
|
||||
@setup({'templatetag02': '{% templatetag closeblock %}'})
|
||||
def test_templatetag02(self):
|
||||
output = render('templatetag02')
|
||||
output = self.engine.render_to_string('templatetag02')
|
||||
self.assertEqual(output, '%}')
|
||||
|
||||
@setup({'templatetag03': '{% templatetag openvariable %}'})
|
||||
def test_templatetag03(self):
|
||||
output = render('templatetag03')
|
||||
output = self.engine.render_to_string('templatetag03')
|
||||
self.assertEqual(output, '{{')
|
||||
|
||||
@setup({'templatetag04': '{% templatetag closevariable %}'})
|
||||
def test_templatetag04(self):
|
||||
output = render('templatetag04')
|
||||
output = self.engine.render_to_string('templatetag04')
|
||||
self.assertEqual(output, '}}')
|
||||
|
||||
@setup({'templatetag05': '{% templatetag %}'})
|
||||
def test_templatetag05(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('templatetag05')
|
||||
self.engine.get_template('templatetag05')
|
||||
|
||||
@setup({'templatetag06': '{% templatetag foo %}'})
|
||||
def test_templatetag06(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('templatetag06')
|
||||
self.engine.get_template('templatetag06')
|
||||
|
||||
@setup({'templatetag07': '{% templatetag openbrace %}'})
|
||||
def test_templatetag07(self):
|
||||
output = render('templatetag07')
|
||||
output = self.engine.render_to_string('templatetag07')
|
||||
self.assertEqual(output, '{')
|
||||
|
||||
@setup({'templatetag08': '{% templatetag closebrace %}'})
|
||||
def test_templatetag08(self):
|
||||
output = render('templatetag08')
|
||||
output = self.engine.render_to_string('templatetag08')
|
||||
self.assertEqual(output, '}')
|
||||
|
||||
@setup({'templatetag09': '{% templatetag openbrace %}{% templatetag openbrace %}'})
|
||||
def test_templatetag09(self):
|
||||
output = render('templatetag09')
|
||||
output = self.engine.render_to_string('templatetag09')
|
||||
self.assertEqual(output, '{{')
|
||||
|
||||
@setup({'templatetag10': '{% templatetag closebrace %}{% templatetag closebrace %}'})
|
||||
def test_templatetag10(self):
|
||||
output = render('templatetag10')
|
||||
output = self.engine.render_to_string('templatetag10')
|
||||
self.assertEqual(output, '}}')
|
||||
|
||||
@setup({'templatetag11': '{% templatetag opencomment %}'})
|
||||
def test_templatetag11(self):
|
||||
output = render('templatetag11')
|
||||
output = self.engine.render_to_string('templatetag11')
|
||||
self.assertEqual(output, '{#')
|
||||
|
||||
@setup({'templatetag12': '{% templatetag closecomment %}'})
|
||||
def test_templatetag12(self):
|
||||
output = render('templatetag12')
|
||||
output = self.engine.render_to_string('templatetag12')
|
||||
self.assertEqual(output, '#}')
|
||||
|
|
|
@ -2,12 +2,11 @@
|
|||
import warnings
|
||||
|
||||
from django.core.urlresolvers import NoReverseMatch
|
||||
from django.template.base import TemplateSyntaxError
|
||||
from django.template.loader import get_template
|
||||
from django.template import TemplateSyntaxError
|
||||
from django.test import override_settings, SimpleTestCase
|
||||
from django.utils.deprecation import RemovedInDjango20Warning
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
@override_settings(ROOT_URLCONF='template_tests.urls')
|
||||
|
@ -18,88 +17,88 @@ class UrlTagTests(SimpleTestCase):
|
|||
def test_url01(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('url01', {'client': {'id': 1}})
|
||||
output = self.engine.render_to_string('url01', {'client': {'id': 1}})
|
||||
self.assertEqual(output, '/client/1/')
|
||||
|
||||
@setup({'url02': '{% url "template_tests.views.client_action" id=client.id action="update" %}'})
|
||||
def test_url02(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('url02', {'client': {'id': 1}})
|
||||
output = self.engine.render_to_string('url02', {'client': {'id': 1}})
|
||||
self.assertEqual(output, '/client/1/update/')
|
||||
|
||||
@setup({'url02a': '{% url "template_tests.views.client_action" client.id "update" %}'})
|
||||
def test_url02a(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('url02a', {'client': {'id': 1}})
|
||||
output = self.engine.render_to_string('url02a', {'client': {'id': 1}})
|
||||
self.assertEqual(output, '/client/1/update/')
|
||||
|
||||
@setup({'url02b': "{% url 'template_tests.views.client_action' id=client.id action='update' %}"})
|
||||
def test_url02b(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('url02b', {'client': {'id': 1}})
|
||||
output = self.engine.render_to_string('url02b', {'client': {'id': 1}})
|
||||
self.assertEqual(output, '/client/1/update/')
|
||||
|
||||
@setup({'url02c': "{% url 'template_tests.views.client_action' client.id 'update' %}"})
|
||||
def test_url02c(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('url02c', {'client': {'id': 1}})
|
||||
output = self.engine.render_to_string('url02c', {'client': {'id': 1}})
|
||||
self.assertEqual(output, '/client/1/update/')
|
||||
|
||||
@setup({'url03': '{% url "template_tests.views.index" %}'})
|
||||
def test_url03(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('url03')
|
||||
output = self.engine.render_to_string('url03')
|
||||
self.assertEqual(output, '/')
|
||||
|
||||
@setup({'url04': '{% url "named.client" client.id %}'})
|
||||
def test_url04(self):
|
||||
output = render('url04', {'client': {'id': 1}})
|
||||
output = self.engine.render_to_string('url04', {'client': {'id': 1}})
|
||||
self.assertEqual(output, '/named-client/1/')
|
||||
|
||||
@setup({'url05': '{% url "метка_оператора" v %}'})
|
||||
def test_url05(self):
|
||||
output = render('url05', {'v': 'Ω'})
|
||||
output = self.engine.render_to_string('url05', {'v': 'Ω'})
|
||||
self.assertEqual(output, '/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/')
|
||||
|
||||
@setup({'url06': '{% url "метка_оператора_2" tag=v %}'})
|
||||
def test_url06(self):
|
||||
output = render('url06', {'v': 'Ω'})
|
||||
output = self.engine.render_to_string('url06', {'v': 'Ω'})
|
||||
self.assertEqual(output, '/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/')
|
||||
|
||||
@setup({'url07': '{% url "template_tests.views.client2" tag=v %}'})
|
||||
def test_url07(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('url07', {'v': 'Ω'})
|
||||
output = self.engine.render_to_string('url07', {'v': 'Ω'})
|
||||
self.assertEqual(output, '/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/')
|
||||
|
||||
@setup({'url08': '{% url "метка_оператора" v %}'})
|
||||
def test_url08(self):
|
||||
output = render('url08', {'v': 'Ω'})
|
||||
output = self.engine.render_to_string('url08', {'v': 'Ω'})
|
||||
self.assertEqual(output, '/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/')
|
||||
|
||||
@setup({'url09': '{% url "метка_оператора_2" tag=v %}'})
|
||||
def test_url09(self):
|
||||
output = render('url09', {'v': 'Ω'})
|
||||
output = self.engine.render_to_string('url09', {'v': 'Ω'})
|
||||
self.assertEqual(output, '/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/')
|
||||
|
||||
@setup({'url10': '{% url "template_tests.views.client_action" id=client.id action="two words" %}'})
|
||||
def test_url10(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('url10', {'client': {'id': 1}})
|
||||
output = self.engine.render_to_string('url10', {'client': {'id': 1}})
|
||||
self.assertEqual(output, '/client/1/two%20words/')
|
||||
|
||||
@setup({'url11': '{% url "template_tests.views.client_action" id=client.id action="==" %}'})
|
||||
def test_url11(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('url11', {'client': {'id': 1}})
|
||||
output = self.engine.render_to_string('url11', {'client': {'id': 1}})
|
||||
self.assertEqual(output, '/client/1/==/')
|
||||
|
||||
@setup({'url12': '{% url "template_tests.views.client_action" '
|
||||
|
@ -107,7 +106,7 @@ class UrlTagTests(SimpleTestCase):
|
|||
def test_url12(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('url12', {'client': {'id': 1}})
|
||||
output = self.engine.render_to_string('url12', {'client': {'id': 1}})
|
||||
self.assertEqual(output, '/client/1/!$&\'()*+,;=~:@,/')
|
||||
|
||||
@setup({'url13': '{% url "template_tests.views.client_action" '
|
||||
|
@ -115,153 +114,153 @@ class UrlTagTests(SimpleTestCase):
|
|||
def test_url13(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('url13', {'client': {'id': 1}, 'arg': ['a', 'b']})
|
||||
output = self.engine.render_to_string('url13', {'client': {'id': 1}, 'arg': ['a', 'b']})
|
||||
self.assertEqual(output, '/client/1/a-b/')
|
||||
|
||||
@setup({'url14': '{% url "template_tests.views.client_action" client.id arg|join:"-" %}'})
|
||||
def test_url14(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('url14', {'client': {'id': 1}, 'arg': ['a', 'b']})
|
||||
output = self.engine.render_to_string('url14', {'client': {'id': 1}, 'arg': ['a', 'b']})
|
||||
self.assertEqual(output, '/client/1/a-b/')
|
||||
|
||||
@setup({'url15': '{% url "template_tests.views.client_action" 12 "test" %}'})
|
||||
def test_url15(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('url15')
|
||||
output = self.engine.render_to_string('url15')
|
||||
self.assertEqual(output, '/client/12/test/')
|
||||
|
||||
@setup({'url18': '{% url "template_tests.views.client" "1,2" %}'})
|
||||
def test_url18(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('url18')
|
||||
output = self.engine.render_to_string('url18')
|
||||
self.assertEqual(output, '/client/1,2/')
|
||||
|
||||
@setup({'url19': '{% url named_url client.id %}'})
|
||||
def test_url19(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('url19', {'client': {'id': 1}, 'named_url': 'template_tests.views.client'})
|
||||
output = self.engine.render_to_string('url19', {'client': {'id': 1}, 'named_url': 'template_tests.views.client'})
|
||||
self.assertEqual(output, '/client/1/')
|
||||
|
||||
@setup({'url20': '{% url url_name_in_var client.id %}'})
|
||||
def test_url20(self):
|
||||
output = render('url20', {'client': {'id': 1}, 'url_name_in_var': 'named.client'})
|
||||
output = self.engine.render_to_string('url20', {'client': {'id': 1}, 'url_name_in_var': 'named.client'})
|
||||
self.assertEqual(output, '/named-client/1/')
|
||||
|
||||
# Failures
|
||||
@setup({'url-fail01': '{% url %}'})
|
||||
def test_url_fail01(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('url-fail01')
|
||||
self.engine.get_template('url-fail01')
|
||||
|
||||
@setup({'url-fail02': '{% url "no_such_view" %}'})
|
||||
def test_url_fail02(self):
|
||||
with self.assertRaises(NoReverseMatch):
|
||||
render('url-fail02')
|
||||
self.engine.render_to_string('url-fail02')
|
||||
|
||||
@setup({'url-fail03': '{% url "template_tests.views.client" %}'})
|
||||
def test_url_fail03(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
with self.assertRaises(NoReverseMatch):
|
||||
render('url-fail03')
|
||||
self.engine.render_to_string('url-fail03')
|
||||
|
||||
@setup({'url-fail04': '{% url "view" id, %}'})
|
||||
def test_url_fail04(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('url-fail04')
|
||||
self.engine.get_template('url-fail04')
|
||||
|
||||
@setup({'url-fail05': '{% url "view" id= %}'})
|
||||
def test_url_fail05(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('url-fail05')
|
||||
self.engine.get_template('url-fail05')
|
||||
|
||||
@setup({'url-fail06': '{% url "view" a.id=id %}'})
|
||||
def test_url_fail06(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('url-fail06')
|
||||
self.engine.get_template('url-fail06')
|
||||
|
||||
@setup({'url-fail07': '{% url "view" a.id!id %}'})
|
||||
def test_url_fail07(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('url-fail07')
|
||||
self.engine.get_template('url-fail07')
|
||||
|
||||
@setup({'url-fail08': '{% url "view" id="unterminatedstring %}'})
|
||||
def test_url_fail08(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('url-fail08')
|
||||
self.engine.get_template('url-fail08')
|
||||
|
||||
@setup({'url-fail09': '{% url "view" id=", %}'})
|
||||
def test_url_fail09(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('url-fail09')
|
||||
self.engine.get_template('url-fail09')
|
||||
|
||||
@setup({'url-fail11': '{% url named_url %}'})
|
||||
def test_url_fail11(self):
|
||||
with self.assertRaises(NoReverseMatch):
|
||||
render('url-fail11')
|
||||
self.engine.render_to_string('url-fail11')
|
||||
|
||||
@setup({'url-fail12': '{% url named_url %}'})
|
||||
def test_url_fail12(self):
|
||||
with self.assertRaises(NoReverseMatch):
|
||||
render('url-fail12', {'named_url': 'no_such_view'})
|
||||
self.engine.render_to_string('url-fail12', {'named_url': 'no_such_view'})
|
||||
|
||||
@setup({'url-fail13': '{% url named_url %}'})
|
||||
def test_url_fail13(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
with self.assertRaises(NoReverseMatch):
|
||||
render('url-fail13', {'named_url': 'template_tests.views.client'})
|
||||
self.engine.render_to_string('url-fail13', {'named_url': 'template_tests.views.client'})
|
||||
|
||||
@setup({'url-fail14': '{% url named_url id, %}'})
|
||||
def test_url_fail14(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
render('url-fail14', {'named_url': 'view'})
|
||||
self.engine.render_to_string('url-fail14', {'named_url': 'view'})
|
||||
|
||||
@setup({'url-fail15': '{% url named_url id= %}'})
|
||||
def test_url_fail15(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
render('url-fail15', {'named_url': 'view'})
|
||||
self.engine.render_to_string('url-fail15', {'named_url': 'view'})
|
||||
|
||||
@setup({'url-fail16': '{% url named_url a.id=id %}'})
|
||||
def test_url_fail16(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
render('url-fail16', {'named_url': 'view'})
|
||||
self.engine.render_to_string('url-fail16', {'named_url': 'view'})
|
||||
|
||||
@setup({'url-fail17': '{% url named_url a.id!id %}'})
|
||||
def test_url_fail17(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
render('url-fail17', {'named_url': 'view'})
|
||||
self.engine.render_to_string('url-fail17', {'named_url': 'view'})
|
||||
|
||||
@setup({'url-fail18': '{% url named_url id="unterminatedstring %}'})
|
||||
def test_url_fail18(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
render('url-fail18', {'named_url': 'view'})
|
||||
self.engine.render_to_string('url-fail18', {'named_url': 'view'})
|
||||
|
||||
@setup({'url-fail19': '{% url named_url id=", %}'})
|
||||
def test_url_fail19(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
render('url-fail19', {'named_url': 'view'})
|
||||
self.engine.render_to_string('url-fail19', {'named_url': 'view'})
|
||||
|
||||
# {% url ... as var %}
|
||||
@setup({'url-asvar01': '{% url "template_tests.views.index" as url %}'})
|
||||
def test_url_asvar01(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('url-asvar01')
|
||||
output = self.engine.render_to_string('url-asvar01')
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'url-asvar02': '{% url "template_tests.views.index" as url %}{{ url }}'})
|
||||
def test_url_asvar02(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango20Warning)
|
||||
output = render('url-asvar02')
|
||||
output = self.engine.render_to_string('url-asvar02')
|
||||
self.assertEqual(output, '/')
|
||||
|
||||
@setup({'url-asvar03': '{% url "no_such_view" as url %}{{ url }}'})
|
||||
def test_url_asvar03(self):
|
||||
output = render('url-asvar03')
|
||||
output = self.engine.render_to_string('url-asvar03')
|
||||
self.assertEqual(output, '')
|
||||
|
|
|
@ -1,39 +1,38 @@
|
|||
from django.template.base import TemplateSyntaxError
|
||||
from django.template.loader import get_template
|
||||
from django.template import TemplateSyntaxError
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class VerbatimTagTests(SimpleTestCase):
|
||||
|
||||
@setup({'verbatim-tag01': '{% verbatim %}{{bare }}{% endverbatim %}'})
|
||||
def test_verbatim_tag01(self):
|
||||
output = render('verbatim-tag01')
|
||||
output = self.engine.render_to_string('verbatim-tag01')
|
||||
self.assertEqual(output, '{{bare }}')
|
||||
|
||||
@setup({'verbatim-tag02': '{% verbatim %}{% endif %}{% endverbatim %}'})
|
||||
def test_verbatim_tag02(self):
|
||||
output = render('verbatim-tag02')
|
||||
output = self.engine.render_to_string('verbatim-tag02')
|
||||
self.assertEqual(output, '{% endif %}')
|
||||
|
||||
@setup({'verbatim-tag03': '{% verbatim %}It\'s the {% verbatim %} tag{% endverbatim %}'})
|
||||
def test_verbatim_tag03(self):
|
||||
output = render('verbatim-tag03')
|
||||
output = self.engine.render_to_string('verbatim-tag03')
|
||||
self.assertEqual(output, 'It\'s the {% verbatim %} tag')
|
||||
|
||||
@setup({'verbatim-tag04': '{% verbatim %}{% verbatim %}{% endverbatim %}{% endverbatim %}'})
|
||||
def test_verbatim_tag04(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('verbatim-tag04')
|
||||
self.engine.get_template('verbatim-tag04')
|
||||
|
||||
@setup({'verbatim-tag05': '{% verbatim %}{% endverbatim %}{% verbatim %}{% endverbatim %}'})
|
||||
def test_verbatim_tag05(self):
|
||||
output = render('verbatim-tag05')
|
||||
output = self.engine.render_to_string('verbatim-tag05')
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'verbatim-tag06': '{% verbatim special %}'
|
||||
'Don\'t {% endverbatim %} just yet{% endverbatim special %}'})
|
||||
def test_verbatim_tag06(self):
|
||||
output = render('verbatim-tag06')
|
||||
output = self.engine.render_to_string('verbatim-tag06')
|
||||
self.assertEqual(output, 'Don\'t {% endverbatim %} just yet')
|
||||
|
|
|
@ -1,36 +1,35 @@
|
|||
from django.template.base import TemplateSyntaxError
|
||||
from django.template.loader import get_template
|
||||
from django.template import TemplateSyntaxError
|
||||
from django.test import SimpleTestCase
|
||||
from django.utils import six
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class WidthRatioTagTests(SimpleTestCase):
|
||||
|
||||
@setup({'widthratio01': '{% widthratio a b 0 %}'})
|
||||
def test_widthratio01(self):
|
||||
output = render('widthratio01', {'a': 50, 'b': 100})
|
||||
output = self.engine.render_to_string('widthratio01', {'a': 50, 'b': 100})
|
||||
self.assertEqual(output, '0')
|
||||
|
||||
@setup({'widthratio02': '{% widthratio a b 100 %}'})
|
||||
def test_widthratio02(self):
|
||||
output = render('widthratio02', {'a': 0, 'b': 0})
|
||||
output = self.engine.render_to_string('widthratio02', {'a': 0, 'b': 0})
|
||||
self.assertEqual(output, '0')
|
||||
|
||||
@setup({'widthratio03': '{% widthratio a b 100 %}'})
|
||||
def test_widthratio03(self):
|
||||
output = render('widthratio03', {'a': 0, 'b': 100})
|
||||
output = self.engine.render_to_string('widthratio03', {'a': 0, 'b': 100})
|
||||
self.assertEqual(output, '0')
|
||||
|
||||
@setup({'widthratio04': '{% widthratio a b 100 %}'})
|
||||
def test_widthratio04(self):
|
||||
output = render('widthratio04', {'a': 50, 'b': 100})
|
||||
output = self.engine.render_to_string('widthratio04', {'a': 50, 'b': 100})
|
||||
self.assertEqual(output, '50')
|
||||
|
||||
@setup({'widthratio05': '{% widthratio a b 100 %}'})
|
||||
def test_widthratio05(self):
|
||||
output = render('widthratio05', {'a': 100, 'b': 100})
|
||||
output = self.engine.render_to_string('widthratio05', {'a': 100, 'b': 100})
|
||||
self.assertEqual(output, '100')
|
||||
|
||||
@setup({'widthratio06': '{% widthratio a b 100 %}'})
|
||||
|
@ -39,7 +38,7 @@ class WidthRatioTagTests(SimpleTestCase):
|
|||
62.5 should round to 63 on Python 2 and 62 on Python 3
|
||||
See http://docs.python.org/py3k/whatsnew/3.0.html
|
||||
"""
|
||||
output = render('widthratio06', {'a': 50, 'b': 80})
|
||||
output = self.engine.render_to_string('widthratio06', {'a': 50, 'b': 80})
|
||||
self.assertEqual(output, '62' if six.PY3 else '63')
|
||||
|
||||
@setup({'widthratio07': '{% widthratio a b 100 %}'})
|
||||
|
@ -47,23 +46,23 @@ class WidthRatioTagTests(SimpleTestCase):
|
|||
"""
|
||||
71.4 should round to 71
|
||||
"""
|
||||
output = render('widthratio07', {'a': 50, 'b': 70})
|
||||
output = self.engine.render_to_string('widthratio07', {'a': 50, 'b': 70})
|
||||
self.assertEqual(output, '71')
|
||||
|
||||
# Raise exception if we don't have 3 args, last one an integer
|
||||
@setup({'widthratio08': '{% widthratio %}'})
|
||||
def test_widthratio08(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('widthratio08')
|
||||
self.engine.get_template('widthratio08')
|
||||
|
||||
@setup({'widthratio09': '{% widthratio a b %}'})
|
||||
def test_widthratio09(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
render('widthratio09', {'a': 50, 'b': 100})
|
||||
self.engine.render_to_string('widthratio09', {'a': 50, 'b': 100})
|
||||
|
||||
@setup({'widthratio10': '{% widthratio a b 100.0 %}'})
|
||||
def test_widthratio10(self):
|
||||
output = render('widthratio10', {'a': 50, 'b': 100})
|
||||
output = self.engine.render_to_string('widthratio10', {'a': 50, 'b': 100})
|
||||
self.assertEqual(output, '50')
|
||||
|
||||
@setup({'widthratio11': '{% widthratio a b c %}'})
|
||||
|
@ -71,76 +70,76 @@ class WidthRatioTagTests(SimpleTestCase):
|
|||
"""
|
||||
#10043: widthratio should allow max_width to be a variable
|
||||
"""
|
||||
output = render('widthratio11', {'a': 50, 'c': 100, 'b': 100})
|
||||
output = self.engine.render_to_string('widthratio11', {'a': 50, 'c': 100, 'b': 100})
|
||||
self.assertEqual(output, '50')
|
||||
|
||||
# #18739: widthratio should handle None args consistently with
|
||||
# non-numerics
|
||||
@setup({'widthratio12a': '{% widthratio a b c %}'})
|
||||
def test_widthratio12a(self):
|
||||
output = render('widthratio12a', {'a': 'a', 'c': 100, 'b': 100})
|
||||
output = self.engine.render_to_string('widthratio12a', {'a': 'a', 'c': 100, 'b': 100})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'widthratio12b': '{% widthratio a b c %}'})
|
||||
def test_widthratio12b(self):
|
||||
output = render('widthratio12b', {'a': None, 'c': 100, 'b': 100})
|
||||
output = self.engine.render_to_string('widthratio12b', {'a': None, 'c': 100, 'b': 100})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'widthratio13a': '{% widthratio a b c %}'})
|
||||
def test_widthratio13a(self):
|
||||
output = render('widthratio13a', {'a': 0, 'c': 100, 'b': 'b'})
|
||||
output = self.engine.render_to_string('widthratio13a', {'a': 0, 'c': 100, 'b': 'b'})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'widthratio13b': '{% widthratio a b c %}'})
|
||||
def test_widthratio13b(self):
|
||||
output = render('widthratio13b', {'a': 0, 'c': 100, 'b': None})
|
||||
output = self.engine.render_to_string('widthratio13b', {'a': 0, 'c': 100, 'b': None})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'widthratio14a': '{% widthratio a b c %}'})
|
||||
def test_widthratio14a(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
render('widthratio14a', {'a': 0, 'c': 'c', 'b': 100})
|
||||
self.engine.render_to_string('widthratio14a', {'a': 0, 'c': 'c', 'b': 100})
|
||||
|
||||
@setup({'widthratio14b': '{% widthratio a b c %}'})
|
||||
def test_widthratio14b(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
render('widthratio14b', {'a': 0, 'c': None, 'b': 100})
|
||||
self.engine.render_to_string('widthratio14b', {'a': 0, 'c': None, 'b': 100})
|
||||
|
||||
@setup({'widthratio15': '{% load custom %}{% widthratio a|noop:"x y" b 0 %}'})
|
||||
def test_widthratio15(self):
|
||||
"""
|
||||
Test whitespace in filter argument
|
||||
"""
|
||||
output = render('widthratio15', {'a': 50, 'b': 100})
|
||||
output = self.engine.render_to_string('widthratio15', {'a': 50, 'b': 100})
|
||||
self.assertEqual(output, '0')
|
||||
|
||||
# Widthratio with variable assignment
|
||||
@setup({'widthratio16': '{% widthratio a b 100 as variable %}-{{ variable }}-'})
|
||||
def test_widthratio16(self):
|
||||
output = render('widthratio16', {'a': 50, 'b': 100})
|
||||
output = self.engine.render_to_string('widthratio16', {'a': 50, 'b': 100})
|
||||
self.assertEqual(output, '-50-')
|
||||
|
||||
@setup({'widthratio17': '{% widthratio a b 100 as variable %}-{{ variable }}-'})
|
||||
def test_widthratio17(self):
|
||||
output = render('widthratio17', {'a': 100, 'b': 100})
|
||||
output = self.engine.render_to_string('widthratio17', {'a': 100, 'b': 100})
|
||||
self.assertEqual(output, '-100-')
|
||||
|
||||
@setup({'widthratio18': '{% widthratio a b 100 as %}'})
|
||||
def test_widthratio18(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('widthratio18')
|
||||
self.engine.get_template('widthratio18')
|
||||
|
||||
@setup({'widthratio19': '{% widthratio a b 100 not_as variable %}'})
|
||||
def test_widthratio19(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
get_template('widthratio19')
|
||||
self.engine.get_template('widthratio19')
|
||||
|
||||
@setup({'widthratio20': '{% widthratio a b 100 %}'})
|
||||
def test_widthratio20(self):
|
||||
output = render('widthratio20', {'a': float('inf'), 'b': float('inf')})
|
||||
output = self.engine.render_to_string('widthratio20', {'a': float('inf'), 'b': float('inf')})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'widthratio21': '{% widthratio a b 100 %}'})
|
||||
def test_widthratio21(self):
|
||||
output = render('widthratio21', {'a': float('inf'), 'b': 2})
|
||||
output = self.engine.render_to_string('widthratio21', {'a': float('inf'), 'b': 2})
|
||||
self.assertEqual(output, '')
|
||||
|
|
|
@ -1,28 +1,27 @@
|
|||
from django.conf import settings
|
||||
from django.template.base import TemplateSyntaxError
|
||||
from django.template import TemplateSyntaxError
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
class WithTagTests(SimpleTestCase):
|
||||
|
||||
@setup({'with01': '{% with key=dict.key %}{{ key }}{% endwith %}'})
|
||||
def test_with01(self):
|
||||
output = render('with01', {'dict': {'key': 50}})
|
||||
output = self.engine.render_to_string('with01', {'dict': {'key': 50}})
|
||||
self.assertEqual(output, '50')
|
||||
|
||||
@setup({'legacywith01': '{% with dict.key as key %}{{ key }}{% endwith %}'})
|
||||
def test_legacywith01(self):
|
||||
output = render('legacywith01', {'dict': {'key': 50}})
|
||||
output = self.engine.render_to_string('legacywith01', {'dict': {'key': 50}})
|
||||
self.assertEqual(output, '50')
|
||||
|
||||
@setup({'with02': '{{ key }}{% with key=dict.key %}'
|
||||
'{{ key }}-{{ dict.key }}-{{ key }}'
|
||||
'{% endwith %}{{ key }}'})
|
||||
def test_with02(self):
|
||||
output = render('with02', {'dict': {'key': 50}})
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
output = self.engine.render_to_string('with02', {'dict': {'key': 50}})
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, 'INVALID50-50-50INVALID')
|
||||
else:
|
||||
self.assertEqual(output, '50-50-50')
|
||||
|
@ -31,23 +30,23 @@ class WithTagTests(SimpleTestCase):
|
|||
'{{ key }}-{{ dict.key }}-{{ key }}'
|
||||
'{% endwith %}{{ key }}'})
|
||||
def test_legacywith02(self):
|
||||
output = render('legacywith02', {'dict': {'key': 50}})
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
output = self.engine.render_to_string('legacywith02', {'dict': {'key': 50}})
|
||||
if self.engine.string_if_invalid:
|
||||
self.assertEqual(output, 'INVALID50-50-50INVALID')
|
||||
else:
|
||||
self.assertEqual(output, '50-50-50')
|
||||
|
||||
@setup({'with03': '{% with a=alpha b=beta %}{{ a }}{{ b }}{% endwith %}'})
|
||||
def test_with03(self):
|
||||
output = render('with03', {'alpha': 'A', 'beta': 'B'})
|
||||
output = self.engine.render_to_string('with03', {'alpha': 'A', 'beta': 'B'})
|
||||
self.assertEqual(output, 'AB')
|
||||
|
||||
@setup({'with-error01': '{% with dict.key xx key %}{{ key }}{% endwith %}'})
|
||||
def test_with_error01(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
render('with-error01', {'dict': {'key': 50}})
|
||||
self.engine.render_to_string('with-error01', {'dict': {'key': 50}})
|
||||
|
||||
@setup({'with-error02': '{% with dict.key as %}{{ key }}{% endwith %}'})
|
||||
def test_with_error02(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
render('with-error02', {'dict': {'key': 50}})
|
||||
self.engine.render_to_string('with-error02', {'dict': {'key': 50}})
|
||||
|
|
|
@ -2,26 +2,20 @@
|
|||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import functools
|
||||
|
||||
from django import template
|
||||
from django.template import Library
|
||||
from django.template.base import Context, libraries
|
||||
from django.template.base import libraries
|
||||
from django.template.engine import Engine
|
||||
from django.template.loader import get_template
|
||||
from django.test.utils import override_settings
|
||||
from django.utils import translation
|
||||
from django.utils._os import upath
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
|
||||
def render(template_name, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
t = get_template(template_name)
|
||||
with translation.override(context.get('LANGUAGE_CODE', 'en-us')):
|
||||
return t.render(Context(context))
|
||||
ROOT = os.path.dirname(os.path.abspath(upath(__file__)))
|
||||
|
||||
|
||||
def setup(templates, *args):
|
||||
|
@ -45,31 +39,44 @@ def setup(templates, *args):
|
|||
# add this in here for simplicity
|
||||
templates["inclusion.html"] = "{{ result }}"
|
||||
|
||||
def decorator(func):
|
||||
@register_test_tags
|
||||
@override_settings(TEMPLATE_LOADERS=[
|
||||
loaders = [
|
||||
('django.template.loaders.cached.Loader', [
|
||||
('django.template.loaders.locmem.Loader', templates),
|
||||
]),
|
||||
])
|
||||
]
|
||||
|
||||
def decorator(func):
|
||||
@register_test_tags
|
||||
# Make Engine.get_default() raise an exception to ensure that tests
|
||||
# are properly isolated from Django's global settings.
|
||||
@override_settings(TEMPLATES=None)
|
||||
@functools.wraps(func)
|
||||
def inner(self):
|
||||
loader = Engine.get_default().template_loaders[0]
|
||||
self.engine = Engine(
|
||||
allowed_include_roots=[ROOT],
|
||||
loaders=loaders,
|
||||
)
|
||||
func(self)
|
||||
func(self)
|
||||
|
||||
self.engine = Engine(
|
||||
allowed_include_roots=[ROOT],
|
||||
loaders=loaders,
|
||||
string_if_invalid='INVALID',
|
||||
)
|
||||
func(self)
|
||||
func(self)
|
||||
loader.reset()
|
||||
|
||||
with override_settings(TEMPLATE_STRING_IF_INVALID='INVALID'):
|
||||
self.engine = Engine(
|
||||
allowed_include_roots=[ROOT],
|
||||
debug=True,
|
||||
loaders=loaders,
|
||||
)
|
||||
func(self)
|
||||
func(self)
|
||||
loader.reset()
|
||||
|
||||
with override_settings(TEMPLATE_DEBUG=True):
|
||||
func(self)
|
||||
func(self)
|
||||
loader.reset()
|
||||
return inner
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue