Skip to content

Commit 92a2d04

Browse files
committed
Isolated template tests from Django settings.
1 parent b34b8a1 commit 92a2d04

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1069
-1080
lines changed

tests/template_tests/filter_tests/test_add.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from django.template.defaultfilters import add
44
from django.test import SimpleTestCase
55

6-
from ..utils import render, setup
6+
from ..utils import setup
77

88

99
class AddTests(SimpleTestCase):
@@ -13,37 +13,37 @@ class AddTests(SimpleTestCase):
1313

1414
@setup({'add01': '{{ i|add:"5" }}'})
1515
def test_add01(self):
16-
output = render('add01', {'i': 2000})
16+
output = self.engine.render_to_string('add01', {'i': 2000})
1717
self.assertEqual(output, '2005')
1818

1919
@setup({'add02': '{{ i|add:"napis" }}'})
2020
def test_add02(self):
21-
output = render('add02', {'i': 2000})
21+
output = self.engine.render_to_string('add02', {'i': 2000})
2222
self.assertEqual(output, '')
2323

2424
@setup({'add03': '{{ i|add:16 }}'})
2525
def test_add03(self):
26-
output = render('add03', {'i': 'not_an_int'})
26+
output = self.engine.render_to_string('add03', {'i': 'not_an_int'})
2727
self.assertEqual(output, '')
2828

2929
@setup({'add04': '{{ i|add:"16" }}'})
3030
def test_add04(self):
31-
output = render('add04', {'i': 'not_an_int'})
31+
output = self.engine.render_to_string('add04', {'i': 'not_an_int'})
3232
self.assertEqual(output, 'not_an_int16')
3333

3434
@setup({'add05': '{{ l1|add:l2 }}'})
3535
def test_add05(self):
36-
output = render('add05', {'l1': [1, 2], 'l2': [3, 4]})
36+
output = self.engine.render_to_string('add05', {'l1': [1, 2], 'l2': [3, 4]})
3737
self.assertEqual(output, '[1, 2, 3, 4]')
3838

3939
@setup({'add06': '{{ t1|add:t2 }}'})
4040
def test_add06(self):
41-
output = render('add06', {'t1': (3, 4), 't2': (1, 2)})
41+
output = self.engine.render_to_string('add06', {'t1': (3, 4), 't2': (1, 2)})
4242
self.assertEqual(output, '(3, 4, 1, 2)')
4343

4444
@setup({'add07': '{{ d|add:t }}'})
4545
def test_add07(self):
46-
output = render('add07', {'d': date(2000, 1, 1), 't': timedelta(10)})
46+
output = self.engine.render_to_string('add07', {'d': date(2000, 1, 1), 't': timedelta(10)})
4747
self.assertEqual(output, 'Jan. 11, 2000')
4848

4949

tests/template_tests/filter_tests/test_addslashes.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
from django.test import SimpleTestCase
33
from django.utils.safestring import mark_safe
44

5-
from ..utils import render, setup
5+
from ..utils import setup
66

77

88
class AddslashesTests(SimpleTestCase):
99

1010
@setup({'addslashes01': '{% autoescape off %}{{ a|addslashes }} {{ b|addslashes }}{% endautoescape %}'})
1111
def test_addslashes01(self):
12-
output = render('addslashes01', {"a": "<a>'", "b": mark_safe("<a>'")})
12+
output = self.engine.render_to_string('addslashes01', {"a": "<a>'", "b": mark_safe("<a>'")})
1313
self.assertEqual(output, r"<a>\' <a>\'")
1414

1515
@setup({'addslashes02': '{{ a|addslashes }} {{ b|addslashes }}'})
1616
def test_addslashes02(self):
17-
output = render('addslashes02', {"a": "<a>'", "b": mark_safe("<a>'")})
17+
output = self.engine.render_to_string('addslashes02', {"a": "<a>'", "b": mark_safe("<a>'")})
1818
self.assertEqual(output, r"&lt;a&gt;\&#39; <a>\'")
1919

2020

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from django.test import SimpleTestCase
22

3-
from ..utils import render, setup, SafeClass, UnsafeClass
3+
from ..utils import setup, SafeClass, UnsafeClass
44

55

66
class AutoescapeStringfilterTests(SimpleTestCase):
@@ -10,20 +10,20 @@ class AutoescapeStringfilterTests(SimpleTestCase):
1010

1111
@setup({'autoescape-stringfilter01': '{{ unsafe|capfirst }}'})
1212
def test_autoescape_stringfilter01(self):
13-
output = render('autoescape-stringfilter01', {'unsafe': UnsafeClass()})
13+
output = self.engine.render_to_string('autoescape-stringfilter01', {'unsafe': UnsafeClass()})
1414
self.assertEqual(output, 'You &amp; me')
1515

1616
@setup({'autoescape-stringfilter02': '{% autoescape off %}{{ unsafe|capfirst }}{% endautoescape %}'})
1717
def test_autoescape_stringfilter02(self):
18-
output = render('autoescape-stringfilter02', {'unsafe': UnsafeClass()})
18+
output = self.engine.render_to_string('autoescape-stringfilter02', {'unsafe': UnsafeClass()})
1919
self.assertEqual(output, 'You & me')
2020

2121
@setup({'autoescape-stringfilter03': '{{ safe|capfirst }}'})
2222
def test_autoescape_stringfilter03(self):
23-
output = render('autoescape-stringfilter03', {'safe': SafeClass()})
23+
output = self.engine.render_to_string('autoescape-stringfilter03', {'safe': SafeClass()})
2424
self.assertEqual(output, 'You &gt; me')
2525

2626
@setup({'autoescape-stringfilter04': '{% autoescape off %}{{ safe|capfirst }}{% endautoescape %}'})
2727
def test_autoescape_stringfilter04(self):
28-
output = render('autoescape-stringfilter04', {'safe': SafeClass()})
28+
output = self.engine.render_to_string('autoescape-stringfilter04', {'safe': SafeClass()})
2929
self.assertEqual(output, 'You &gt; me')

tests/template_tests/filter_tests/test_capfirst.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
from django.test import SimpleTestCase
33
from django.utils.safestring import mark_safe
44

5-
from ..utils import render, setup
5+
from ..utils import setup
66

77

88
class CapfirstTests(SimpleTestCase):
99

1010
@setup({'capfirst01': '{% autoescape off %}{{ a|capfirst }} {{ b|capfirst }}{% endautoescape %}'})
1111
def test_capfirst01(self):
12-
output = render('capfirst01', {'a': 'fred>', 'b': mark_safe('fred&gt;')})
12+
output = self.engine.render_to_string('capfirst01', {'a': 'fred>', 'b': mark_safe('fred&gt;')})
1313
self.assertEqual(output, 'Fred> Fred&gt;')
1414

1515
@setup({'capfirst02': '{{ a|capfirst }} {{ b|capfirst }}'})
1616
def test_capfirst02(self):
17-
output = render('capfirst02', {'a': 'fred>', 'b': mark_safe('fred&gt;')})
17+
output = self.engine.render_to_string('capfirst02', {'a': 'fred>', 'b': mark_safe('fred&gt;')})
1818
self.assertEqual(output, 'Fred&gt; Fred&gt;')
1919

2020

tests/template_tests/filter_tests/test_center.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
from django.test import SimpleTestCase
33
from django.utils.safestring import mark_safe
44

5-
from ..utils import render, setup
5+
from ..utils import setup
66

77

88
class CenterTests(SimpleTestCase):
99

1010
@setup({'center01':
1111
'{% autoescape off %}.{{ a|center:"5" }}. .{{ b|center:"5" }}.{% endautoescape %}'})
1212
def test_center01(self):
13-
output = render('center01', {"a": "a&b", "b": mark_safe("a&b")})
13+
output = self.engine.render_to_string('center01', {"a": "a&b", "b": mark_safe("a&b")})
1414
self.assertEqual(output, ". a&b . . a&b .")
1515

1616
@setup({'center02': '.{{ a|center:"5" }}. .{{ b|center:"5" }}.'})
1717
def test_center02(self):
18-
output = render('center02', {"a": "a&b", "b": mark_safe("a&b")})
18+
output = self.engine.render_to_string('center02', {"a": "a&b", "b": mark_safe("a&b")})
1919
self.assertEqual(output, ". a&amp;b . . a&b .")
2020

2121

Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.test import SimpleTestCase
22
from django.utils.safestring import mark_safe
33

4-
from ..utils import render, setup
4+
from ..utils import setup
55

66

77
class ChainingTests(SimpleTestCase):
@@ -11,76 +11,76 @@ class ChainingTests(SimpleTestCase):
1111

1212
@setup({'chaining01': '{{ a|capfirst|center:"7" }}.{{ b|capfirst|center:"7" }}'})
1313
def test_chaining01(self):
14-
output = render('chaining01', {'a': 'a < b', 'b': mark_safe('a < b')})
14+
output = self.engine.render_to_string('chaining01', {'a': 'a < b', 'b': mark_safe('a < b')})
1515
self.assertEqual(output, ' A &lt; b . A < b ')
1616

1717
@setup({'chaining02':
1818
'{% autoescape off %}{{ a|capfirst|center:"7" }}.{{ b|capfirst|center:"7" }}{% endautoescape %}'})
1919
def test_chaining02(self):
20-
output = render('chaining02', {'a': 'a < b', 'b': mark_safe('a < b')})
20+
output = self.engine.render_to_string('chaining02', {'a': 'a < b', 'b': mark_safe('a < b')})
2121
self.assertEqual(output, ' A < b . A < b ')
2222

2323
# Using a filter that forces a string back to unsafe:
2424
@setup({'chaining03': '{{ a|cut:"b"|capfirst }}.{{ b|cut:"b"|capfirst }}'})
2525
def test_chaining03(self):
26-
output = render('chaining03', {'a': 'a < b', 'b': mark_safe('a < b')})
26+
output = self.engine.render_to_string('chaining03', {'a': 'a < b', 'b': mark_safe('a < b')})
2727
self.assertEqual(output, 'A &lt; .A < ')
2828

2929
@setup({'chaining04':
3030
'{% autoescape off %}{{ a|cut:"b"|capfirst }}.{{ b|cut:"b"|capfirst }}{% endautoescape %}'})
3131
def test_chaining04(self):
32-
output = render('chaining04', {'a': 'a < b', 'b': mark_safe('a < b')})
32+
output = self.engine.render_to_string('chaining04', {'a': 'a < b', 'b': mark_safe('a < b')})
3333
self.assertEqual(output, 'A < .A < ')
3434

3535
# Using a filter that forces safeness does not lead to double-escaping
3636
@setup({'chaining05': '{{ a|escape|capfirst }}'})
3737
def test_chaining05(self):
38-
output = render('chaining05', {'a': 'a < b'})
38+
output = self.engine.render_to_string('chaining05', {'a': 'a < b'})
3939
self.assertEqual(output, 'A &lt; b')
4040

4141
@setup({'chaining06': '{% autoescape off %}{{ a|escape|capfirst }}{% endautoescape %}'})
4242
def test_chaining06(self):
43-
output = render('chaining06', {'a': 'a < b'})
43+
output = self.engine.render_to_string('chaining06', {'a': 'a < b'})
4444
self.assertEqual(output, 'A &lt; b')
4545

4646
# Force to safe, then back (also showing why using force_escape too
4747
# early in a chain can lead to unexpected results).
4848
@setup({'chaining07': '{{ a|force_escape|cut:";" }}'})
4949
def test_chaining07(self):
50-
output = render('chaining07', {'a': 'a < b'})
50+
output = self.engine.render_to_string('chaining07', {'a': 'a < b'})
5151
self.assertEqual(output, 'a &amp;lt b')
5252

5353
@setup({'chaining08': '{% autoescape off %}{{ a|force_escape|cut:";" }}{% endautoescape %}'})
5454
def test_chaining08(self):
55-
output = render('chaining08', {'a': 'a < b'})
55+
output = self.engine.render_to_string('chaining08', {'a': 'a < b'})
5656
self.assertEqual(output, 'a &lt b')
5757

5858
@setup({'chaining09': '{{ a|cut:";"|force_escape }}'})
5959
def test_chaining09(self):
60-
output = render('chaining09', {'a': 'a < b'})
60+
output = self.engine.render_to_string('chaining09', {'a': 'a < b'})
6161
self.assertEqual(output, 'a &lt; b')
6262

6363
@setup({'chaining10': '{% autoescape off %}{{ a|cut:";"|force_escape }}{% endautoescape %}'})
6464
def test_chaining10(self):
65-
output = render('chaining10', {'a': 'a < b'})
65+
output = self.engine.render_to_string('chaining10', {'a': 'a < b'})
6666
self.assertEqual(output, 'a &lt; b')
6767

6868
@setup({'chaining11': '{{ a|cut:"b"|safe }}'})
6969
def test_chaining11(self):
70-
output = render('chaining11', {'a': 'a < b'})
70+
output = self.engine.render_to_string('chaining11', {'a': 'a < b'})
7171
self.assertEqual(output, 'a < ')
7272

7373
@setup({'chaining12': '{% autoescape off %}{{ a|cut:"b"|safe }}{% endautoescape %}'})
7474
def test_chaining12(self):
75-
output = render('chaining12', {'a': 'a < b'})
75+
output = self.engine.render_to_string('chaining12', {'a': 'a < b'})
7676
self.assertEqual(output, 'a < ')
7777

7878
@setup({'chaining13': '{{ a|safe|force_escape }}'})
7979
def test_chaining13(self):
80-
output = render('chaining13', {"a": "a < b"})
80+
output = self.engine.render_to_string('chaining13', {"a": "a < b"})
8181
self.assertEqual(output, 'a &lt; b')
8282

8383
@setup({'chaining14': '{% autoescape off %}{{ a|safe|force_escape }}{% endautoescape %}'})
8484
def test_chaining14(self):
85-
output = render('chaining14', {"a": "a < b"})
85+
output = self.engine.render_to_string('chaining14', {"a": "a < b"})
8686
self.assertEqual(output, 'a &lt; b')

tests/template_tests/filter_tests/test_cut.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,41 @@
22
from django.test import SimpleTestCase
33
from django.utils.safestring import mark_safe
44

5-
from ..utils import render, setup
5+
from ..utils import setup
66

77

88
class CutTests(SimpleTestCase):
99

1010
@setup({'cut01': '{% autoescape off %}{{ a|cut:"x" }} {{ b|cut:"x" }}{% endautoescape %}'})
1111
def test_cut01(self):
12-
output = render('cut01', {"a": "x&y", "b": mark_safe("x&amp;y")})
12+
output = self.engine.render_to_string('cut01', {"a": "x&y", "b": mark_safe("x&amp;y")})
1313
self.assertEqual(output, "&y &amp;y")
1414

1515
@setup({'cut02': '{{ a|cut:"x" }} {{ b|cut:"x" }}'})
1616
def test_cut02(self):
17-
output = render('cut02', {"a": "x&y", "b": mark_safe("x&amp;y")})
17+
output = self.engine.render_to_string('cut02', {"a": "x&y", "b": mark_safe("x&amp;y")})
1818
self.assertEqual(output, "&amp;y &amp;y")
1919

2020
@setup({'cut03': '{% autoescape off %}{{ a|cut:"&" }} {{ b|cut:"&" }}{% endautoescape %}'})
2121
def test_cut03(self):
22-
output = render('cut03', {"a": "x&y", "b": mark_safe("x&amp;y")})
22+
output = self.engine.render_to_string('cut03', {"a": "x&y", "b": mark_safe("x&amp;y")})
2323
self.assertEqual(output, "xy xamp;y")
2424

2525
@setup({'cut04': '{{ a|cut:"&" }} {{ b|cut:"&" }}'})
2626
def test_cut04(self):
27-
output = render('cut04', {"a": "x&y", "b": mark_safe("x&amp;y")})
27+
output = self.engine.render_to_string('cut04', {"a": "x&y", "b": mark_safe("x&amp;y")})
2828
self.assertEqual(output, "xy xamp;y")
2929

3030
# Passing ';' to cut can break existing HTML entities, so those strings
3131
# are auto-escaped.
3232
@setup({'cut05': '{% autoescape off %}{{ a|cut:";" }} {{ b|cut:";" }}{% endautoescape %}'})
3333
def test_cut05(self):
34-
output = render('cut05', {"a": "x&y", "b": mark_safe("x&amp;y")})
34+
output = self.engine.render_to_string('cut05', {"a": "x&y", "b": mark_safe("x&amp;y")})
3535
self.assertEqual(output, "x&y x&ampy")
3636

3737
@setup({'cut06': '{{ a|cut:";" }} {{ b|cut:";" }}'})
3838
def test_cut06(self):
39-
output = render('cut06', {"a": "x&y", "b": mark_safe("x&amp;y")})
39+
output = self.engine.render_to_string('cut06', {"a": "x&y", "b": mark_safe("x&amp;y")})
4040
self.assertEqual(output, "x&amp;y x&amp;ampy")
4141

4242

tests/template_tests/filter_tests/test_date.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,60 @@
55
from django.utils import timezone
66

77
from .timezone_utils import TimezoneTestCase
8-
from ..utils import render, setup
8+
from ..utils import setup
99

1010

1111
class DateTests(TimezoneTestCase):
1212

1313
@setup({'date01': '{{ d|date:"m" }}'})
1414
def test_date01(self):
15-
output = render('date01', {'d': datetime(2008, 1, 1)})
15+
output = self.engine.render_to_string('date01', {'d': datetime(2008, 1, 1)})
1616
self.assertEqual(output, '01')
1717

1818
@setup({'date02': '{{ d|date }}'})
1919
def test_date02(self):
20-
output = render('date02', {'d': datetime(2008, 1, 1)})
20+
output = self.engine.render_to_string('date02', {'d': datetime(2008, 1, 1)})
2121
self.assertEqual(output, 'Jan. 1, 2008')
2222

2323
@setup({'date03': '{{ d|date:"m" }}'})
2424
def test_date03(self):
2525
"""
2626
#9520: Make sure |date doesn't blow up on non-dates
2727
"""
28-
output = render('date03', {'d': 'fail_string'})
28+
output = self.engine.render_to_string('date03', {'d': 'fail_string'})
2929
self.assertEqual(output, '')
3030

3131
# ISO date formats
3232
@setup({'date04': '{{ d|date:"o" }}'})
3333
def test_date04(self):
34-
output = render('date04', {'d': datetime(2008, 12, 29)})
34+
output = self.engine.render_to_string('date04', {'d': datetime(2008, 12, 29)})
3535
self.assertEqual(output, '2009')
3636

3737
@setup({'date05': '{{ d|date:"o" }}'})
3838
def test_date05(self):
39-
output = render('date05', {'d': datetime(2010, 1, 3)})
39+
output = self.engine.render_to_string('date05', {'d': datetime(2010, 1, 3)})
4040
self.assertEqual(output, '2009')
4141

4242
# Timezone name
4343
@setup({'date06': '{{ d|date:"e" }}'})
4444
def test_date06(self):
45-
output = render('date06', {'d': datetime(2009, 3, 12, tzinfo=timezone.get_fixed_timezone(30))})
45+
output = self.engine.render_to_string('date06', {'d': datetime(2009, 3, 12, tzinfo=timezone.get_fixed_timezone(30))})
4646
self.assertEqual(output, '+0030')
4747

4848
@setup({'date07': '{{ d|date:"e" }}'})
4949
def test_date07(self):
50-
output = render('date07', {'d': datetime(2009, 3, 12)})
50+
output = self.engine.render_to_string('date07', {'d': datetime(2009, 3, 12)})
5151
self.assertEqual(output, '')
5252

5353
# #19370: Make sure |date doesn't blow up on a midnight time object
5454
@setup({'date08': '{{ t|date:"H:i" }}'})
5555
def test_date08(self):
56-
output = render('date08', {'t': time(0, 1)})
56+
output = self.engine.render_to_string('date08', {'t': time(0, 1)})
5757
self.assertEqual(output, '00:01')
5858

5959
@setup({'date09': '{{ t|date:"H:i" }}'})
6060
def test_date09(self):
61-
output = render('date09', {'t': time(0, 0)})
61+
output = self.engine.render_to_string('date09', {'t': time(0, 0)})
6262
self.assertEqual(output, '00:00')
6363

6464

0 commit comments

Comments
 (0)