1
1
from django .test import SimpleTestCase
2
2
from django .utils .safestring import mark_safe
3
3
4
- from ..utils import render , setup
4
+ from ..utils import setup
5
5
6
6
7
7
class ChainingTests (SimpleTestCase ):
@@ -11,76 +11,76 @@ class ChainingTests(SimpleTestCase):
11
11
12
12
@setup ({'chaining01' : '{{ a|capfirst|center:"7" }}.{{ b|capfirst|center:"7" }}' })
13
13
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' )})
15
15
self .assertEqual (output , ' A < b . A < b ' )
16
16
17
17
@setup ({'chaining02' :
18
18
'{% autoescape off %}{{ a|capfirst|center:"7" }}.{{ b|capfirst|center:"7" }}{% endautoescape %}' })
19
19
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' )})
21
21
self .assertEqual (output , ' A < b . A < b ' )
22
22
23
23
# Using a filter that forces a string back to unsafe:
24
24
@setup ({'chaining03' : '{{ a|cut:"b"|capfirst }}.{{ b|cut:"b"|capfirst }}' })
25
25
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' )})
27
27
self .assertEqual (output , 'A < .A < ' )
28
28
29
29
@setup ({'chaining04' :
30
30
'{% autoescape off %}{{ a|cut:"b"|capfirst }}.{{ b|cut:"b"|capfirst }}{% endautoescape %}' })
31
31
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' )})
33
33
self .assertEqual (output , 'A < .A < ' )
34
34
35
35
# Using a filter that forces safeness does not lead to double-escaping
36
36
@setup ({'chaining05' : '{{ a|escape|capfirst }}' })
37
37
def test_chaining05 (self ):
38
- output = render ('chaining05' , {'a' : 'a < b' })
38
+ output = self . engine . render_to_string ('chaining05' , {'a' : 'a < b' })
39
39
self .assertEqual (output , 'A < b' )
40
40
41
41
@setup ({'chaining06' : '{% autoescape off %}{{ a|escape|capfirst }}{% endautoescape %}' })
42
42
def test_chaining06 (self ):
43
- output = render ('chaining06' , {'a' : 'a < b' })
43
+ output = self . engine . render_to_string ('chaining06' , {'a' : 'a < b' })
44
44
self .assertEqual (output , 'A < b' )
45
45
46
46
# Force to safe, then back (also showing why using force_escape too
47
47
# early in a chain can lead to unexpected results).
48
48
@setup ({'chaining07' : '{{ a|force_escape|cut:";" }}' })
49
49
def test_chaining07 (self ):
50
- output = render ('chaining07' , {'a' : 'a < b' })
50
+ output = self . engine . render_to_string ('chaining07' , {'a' : 'a < b' })
51
51
self .assertEqual (output , 'a &lt b' )
52
52
53
53
@setup ({'chaining08' : '{% autoescape off %}{{ a|force_escape|cut:";" }}{% endautoescape %}' })
54
54
def test_chaining08 (self ):
55
- output = render ('chaining08' , {'a' : 'a < b' })
55
+ output = self . engine . render_to_string ('chaining08' , {'a' : 'a < b' })
56
56
self .assertEqual (output , 'a < b' )
57
57
58
58
@setup ({'chaining09' : '{{ a|cut:";"|force_escape }}' })
59
59
def test_chaining09 (self ):
60
- output = render ('chaining09' , {'a' : 'a < b' })
60
+ output = self . engine . render_to_string ('chaining09' , {'a' : 'a < b' })
61
61
self .assertEqual (output , 'a < b' )
62
62
63
63
@setup ({'chaining10' : '{% autoescape off %}{{ a|cut:";"|force_escape }}{% endautoescape %}' })
64
64
def test_chaining10 (self ):
65
- output = render ('chaining10' , {'a' : 'a < b' })
65
+ output = self . engine . render_to_string ('chaining10' , {'a' : 'a < b' })
66
66
self .assertEqual (output , 'a < b' )
67
67
68
68
@setup ({'chaining11' : '{{ a|cut:"b"|safe }}' })
69
69
def test_chaining11 (self ):
70
- output = render ('chaining11' , {'a' : 'a < b' })
70
+ output = self . engine . render_to_string ('chaining11' , {'a' : 'a < b' })
71
71
self .assertEqual (output , 'a < ' )
72
72
73
73
@setup ({'chaining12' : '{% autoescape off %}{{ a|cut:"b"|safe }}{% endautoescape %}' })
74
74
def test_chaining12 (self ):
75
- output = render ('chaining12' , {'a' : 'a < b' })
75
+ output = self . engine . render_to_string ('chaining12' , {'a' : 'a < b' })
76
76
self .assertEqual (output , 'a < ' )
77
77
78
78
@setup ({'chaining13' : '{{ a|safe|force_escape }}' })
79
79
def test_chaining13 (self ):
80
- output = render ('chaining13' , {"a" : "a < b" })
80
+ output = self . engine . render_to_string ('chaining13' , {"a" : "a < b" })
81
81
self .assertEqual (output , 'a < b' )
82
82
83
83
@setup ({'chaining14' : '{% autoescape off %}{{ a|safe|force_escape }}{% endautoescape %}' })
84
84
def test_chaining14 (self ):
85
- output = render ('chaining14' , {"a" : "a < b" })
85
+ output = self . engine . render_to_string ('chaining14' , {"a" : "a < b" })
86
86
self .assertEqual (output , 'a < b' )
0 commit comments