| 202 | assert rv == "1" |
| 203 | |
| 204 | def test_call_with_args(self, env): |
| 205 | t = Template( |
| 206 | """{% macro dump_users(users) -%} |
| 207 | <ul> |
| 208 | {%- for user in users -%} |
| 209 | <li><p>{{ user.username|e }}</p>{{ caller(user) }}</li> |
| 210 | {%- endfor -%} |
| 211 | </ul> |
| 212 | {%- endmacro -%} |
| 213 | |
| 214 | {% call(user) dump_users(list_of_user) -%} |
| 215 | <dl> |
| 216 | <dl>Realname</dl> |
| 217 | <dd>{{ user.realname|e }}</dd> |
| 218 | <dl>Description</dl> |
| 219 | <dd>{{ user.description }}</dd> |
| 220 | </dl> |
| 221 | {% endcall %}""" |
| 222 | ) |
| 223 | |
| 224 | assert [ |
| 225 | x.strip() |
| 226 | for x in t.render( |
| 227 | list_of_user=[ |
| 228 | { |
| 229 | "username": "apo", |
| 230 | "realname": "something else", |
| 231 | "description": "test", |
| 232 | } |
| 233 | ] |
| 234 | ).splitlines() |
| 235 | ] == [ |
| 236 | "<ul><li><p>apo</p><dl>", |
| 237 | "<dl>Realname</dl>", |
| 238 | "<dd>something else</dd>", |
| 239 | "<dl>Description</dl>", |
| 240 | "<dd>test</dd>", |
| 241 | "</dl>", |
| 242 | "</li></ul>", |
| 243 | ] |
| 244 | |
| 245 | def test_empty_if_condition_fails(self, env): |
| 246 | pytest.raises(TemplateSyntaxError, Template, "{% if %}....{% endif %}") |