add tests for now and today variables in templates (#29887)
This commit is contained in:
parent
e9d144d2c4
commit
f02f0d8df9
|
@ -1,5 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import datetime
|
||||
import pytest
|
||||
|
||||
from quixote import cleanup
|
||||
|
@ -13,6 +14,7 @@ def setup_module(module):
|
|||
cleanup()
|
||||
global pub
|
||||
pub = create_temporary_pub()
|
||||
pub.substitutions.feed(pub)
|
||||
|
||||
|
||||
def teardown_module(module):
|
||||
|
@ -59,6 +61,36 @@ def test_template():
|
|||
tmpl = Template('[if-any foo][foo][endif]')
|
||||
assert tmpl.render({'foo': 'bar'}) == '[if-any foo][foo][endif]'
|
||||
|
||||
def test_now_and_today_variables():
|
||||
# create a today string, verify it contains the year, at least
|
||||
today = Template('{{d}}').render({'d': datetime.date.today()})
|
||||
assert datetime.date.today().strftime('%Y') in today
|
||||
|
||||
tmpl = Template('{{ today }}')
|
||||
for mode in (None, 'lazy'):
|
||||
context = pub.substitutions.get_context_variables(mode=mode)
|
||||
assert tmpl.render(context) == today
|
||||
tmpl = Template('{{ now }}')
|
||||
for mode in (None, 'lazy'):
|
||||
context = pub.substitutions.get_context_variables(mode=mode)
|
||||
assert today in tmpl.render(context) # contains the date,
|
||||
assert tmpl.render(context) != today # but not only
|
||||
|
||||
# ezt templates (legacy)
|
||||
today = Template('[t]').render({'t': datetime.date.today()})
|
||||
assert today == datetime.date.today().strftime('%Y-%m-%d')
|
||||
now = Template('[n]').render({'n': datetime.datetime.now()})
|
||||
assert now == datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
|
||||
|
||||
tmpl = Template('[today]')
|
||||
for mode in (None, 'lazy'):
|
||||
context = pub.substitutions.get_context_variables(mode=mode)
|
||||
assert tmpl.render(context) == today
|
||||
tmpl = Template('[now]')
|
||||
for mode in (None, 'lazy'):
|
||||
context = pub.substitutions.get_context_variables(mode=mode)
|
||||
assert tmpl.render(context) == now
|
||||
|
||||
def test_template_templatetag():
|
||||
# check qommon templatetags are always loaded
|
||||
tmpl = Template('{{ date|parse_datetime|date:"Y" }}')
|
||||
|
|
Loading…
Reference in New Issue