128 |
128 |
t = Template('{% for x in plop|split %}{{x}}<br>{% endfor %}')
|
129 |
129 |
assert t.render(Context({'plop': 'ab cd ef'})) == 'ab<br>cd<br>ef<br>'
|
130 |
130 |
t = Template('{% for x in plop|split:"|" %}{{x}} {% endfor %}')
|
131 |
131 |
assert t.render(Context({'plop': 'ab|cd|ef'})) == 'ab cd ef '
|
132 |
132 |
|
133 |
133 |
def test_strip_templatetag():
|
134 |
134 |
tmpl = Template('{{ foo|strip }}')
|
135 |
135 |
assert tmpl.render(Context()) == ''
|
136 |
|
assert tmpl.render(Context({'foo': None})) == ''
|
137 |
136 |
assert tmpl.render(Context({'foo': ' foo bar '})) == 'foo bar'
|
138 |
137 |
assert tmpl.render(Context({'foo': ' foo bar\t'})) == 'foo bar'
|
139 |
138 |
assert tmpl.render(Context({'foo': ' félé '})) == 'félé'
|
140 |
139 |
tmpl = Template('{{ foo|strip:"XY" }}')
|
141 |
140 |
assert tmpl.render(Context({'foo': 'XXfoo barXYX'})) == 'foo bar'
|
142 |
141 |
assert tmpl.render(Context({'foo': ' foo barXX'})) == ' foo bar'
|
143 |
142 |
|
|
143 |
|
|
144 |
def test_removeprefix_templatetag():
|
|
145 |
tmpl = Template('{{ foo|removeprefix }}')
|
|
146 |
assert tmpl.render(Context()) == ''
|
|
147 |
assert tmpl.render(Context({'foo': None})) == 'None'
|
|
148 |
assert tmpl.render(Context({'foo': 0})) == '0'
|
|
149 |
assert tmpl.render(Context({'foo': 'None'})) == 'None'
|
|
150 |
assert tmpl.render(Context({'foo': 'foo bar'})) == 'foo bar'
|
|
151 |
tmpl = Template('{{ foo|removeprefix:"" }}')
|
|
152 |
assert tmpl.render(Context({'foo': 'None'})) == 'None'
|
|
153 |
assert tmpl.render(Context({'foo': 'foo bar'})) == 'foo bar'
|
|
154 |
tmpl = Template('{{ foo|removeprefix:"XY" }}')
|
|
155 |
assert tmpl.render(Context({'foo': 'XYfoo barXY'})) == 'foo barXY'
|
|
156 |
assert tmpl.render(Context({'foo': 'foo bar'})) == 'foo bar'
|
|
157 |
assert tmpl.render(Context({'foo': 'xyfoo barXY'})) == 'xyfoo barXY'
|
|
158 |
assert tmpl.render(Context({'foo': ' XYfoo barXY'})) == ' XYfoo barXY'
|
|
159 |
assert tmpl.render(Context({'foo': 'XYXYfoo barXY'})) == 'XYfoo barXY'
|
|
160 |
|
|
161 |
|
|
162 |
def test_removesuffix_templatetag():
|
|
163 |
tmpl = Template('{{ foo|removesuffix }}')
|
|
164 |
assert tmpl.render(Context()) == ''
|
|
165 |
assert tmpl.render(Context({'foo': None})) == 'None'
|
|
166 |
assert tmpl.render(Context({'foo': 0})) == '0'
|
|
167 |
assert tmpl.render(Context({'foo': 'None'})) == 'None'
|
|
168 |
assert tmpl.render(Context({'foo': 'foo bar'})) == 'foo bar'
|
|
169 |
tmpl = Template('{{ foo|removesuffix:"" }}')
|
|
170 |
assert tmpl.render(Context({'foo': 'None'})) == 'None'
|
|
171 |
assert tmpl.render(Context({'foo': 'foo bar'})) == 'foo bar'
|
|
172 |
tmpl = Template('{{ foo|removesuffix:"XY" }}')
|
|
173 |
assert tmpl.render(Context({'foo': 'XYfoo barXY'})) == 'XYfoo bar'
|
|
174 |
assert tmpl.render(Context({'foo': 'foo bar'})) == 'foo bar'
|
|
175 |
assert tmpl.render(Context({'foo': 'XYfoo barxy'})) == 'XYfoo barxy'
|
|
176 |
assert tmpl.render(Context({'foo': 'XYfoo barXY '})) == 'XYfoo barXY '
|
|
177 |
assert tmpl.render(Context({'foo': 'XYfoo barXYXY'})) == 'XYfoo barXY'
|
|
178 |
|
|
179 |
|
144 |
180 |
def test_get_group():
|
145 |
181 |
context = Context({'cities': [
|
146 |
182 |
{'name': 'Mumbai', 'population': '19,000,000', 'country': 'India'},
|
147 |
183 |
{'name': 'New York', 'population': '20,000,000', 'country': 'USA'},
|
148 |
184 |
{'name': 'Calcutta', 'population': '15,000,000', 'country': 'India'},
|
149 |
185 |
{'name': 'Chicago', 'population': '7,000,000', 'country': 'USA'},
|
150 |
186 |
{'name': 'Tokyo', 'population': '33,000,000', 'country': 'Japan'},
|
151 |
187 |
]})
|
152 |
|
-
|