463 |
463 |
):
|
464 |
464 |
tmpl = Template('{%% if %s %%}Good{%% endif %%}' % condition_value)
|
465 |
465 |
assert tmpl.render(Context(context)) == 'Good'
|
|
466 |
|
|
467 |
|
|
468 |
def test_decimal_templatetag():
|
|
469 |
tmpl = Template('{{ plop|decimal }}')
|
|
470 |
assert tmpl.render(Context({'plop': 'toto'})) == '0'
|
|
471 |
assert tmpl.render(Context({'plop': '3.14'})) == '3.14'
|
|
472 |
assert tmpl.render(Context({'plop': '3,14'})) == '3.14'
|
|
473 |
assert tmpl.render(Context({'plop': 3.14})) == '3.14'
|
|
474 |
assert tmpl.render(Context({'plop': 12345.678})) == '12345.678'
|
|
475 |
assert tmpl.render(Context({'plop': None})) == '0'
|
|
476 |
assert tmpl.render(Context({'plop': 0})) == '0'
|
|
477 |
|
|
478 |
tmpl = Template('{{ plop|decimal:3 }}')
|
|
479 |
assert tmpl.render(Context({'plop': '3.14'})) == '3.140'
|
|
480 |
assert tmpl.render(Context({'plop': None})) == '0.000'
|
|
481 |
tmpl = Template('{{ plop|decimal:"3" }}')
|
|
482 |
assert tmpl.render(Context({'plop': '3.14'})) == '3.140'
|
|
483 |
assert tmpl.render(Context({'plop': None})) == '0.000'
|
|
484 |
|
|
485 |
tmpl = Template('{% if plop|decimal > 2 %}hello{% endif %}')
|
|
486 |
assert tmpl.render(Context({'plop': 3})) == 'hello'
|
|
487 |
assert tmpl.render(Context({'plop': '3'})) == 'hello'
|
|
488 |
assert tmpl.render(Context({'plop': 2.001})) == 'hello'
|
|
489 |
assert tmpl.render(Context({'plop': '2.001'})) == 'hello'
|
|
490 |
assert tmpl.render(Context({'plop': 1})) == ''
|
|
491 |
assert tmpl.render(Context({'plop': 1.99})) == ''
|
|
492 |
assert tmpl.render(Context({'plop': '1.99'})) == ''
|
|
493 |
assert tmpl.render(Context({'plop': 'x'})) == ''
|
|
494 |
assert tmpl.render(Context({'plop': None})) == ''
|
|
495 |
assert tmpl.render(Context({'plop': 0})) == ''
|
|
496 |
|
|
497 |
tmpl = Template('{% if "3"|decimal == 3 %}hello{% endif %}')
|
|
498 |
assert tmpl.render(Context()) == 'hello'
|
|
499 |
tmpl = Template('{% if "3"|decimal == 3.0 %}hello{% endif %}')
|
|
500 |
assert tmpl.render(Context()) == 'hello'
|
|
501 |
tmpl = Template('{% if 3|decimal == 3 %}hello{% endif %}')
|
|
502 |
assert tmpl.render(Context()) == 'hello'
|
|
503 |
tmpl = Template('{% if 3.0|decimal == 3 %}hello{% endif %}')
|
|
504 |
assert tmpl.render(Context()) == 'hello'
|
|
505 |
tmpl = Template('{% if 3|decimal|decimal == 3 %}hello{% endif %}')
|
|
506 |
assert tmpl.render(Context()) == 'hello'
|
466 |
|
-
|