Projet

Général

Profil

0001-add-tests-for-now-and-today-variables-in-templates-2.patch

Thomas Noël, 18 janvier 2019 14:02

Télécharger (2,38 ko)

Voir les différences:

Subject: [PATCH 1/5] add tests for now and today variables in templates
 (#29887)

 tests/test_templates.py | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
tests/test_templates.py
1 1
# -*- coding: utf-8 -*-
2 2

  
3
import datetime
3 4
import pytest
4 5

  
5 6
from quixote import cleanup
......
13 14
    cleanup()
14 15
    global pub
15 16
    pub = create_temporary_pub()
17
    pub.substitutions.feed(pub)
16 18

  
17 19

  
18 20
def teardown_module(module):
......
59 61
    tmpl = Template('[if-any foo][foo][endif]')
60 62
    assert tmpl.render({'foo': 'bar'}) == '[if-any foo][foo][endif]'
61 63

  
64
def test_now_and_today_variables():
65
    # create a today string, verify it contains the year, at least
66
    today = Template('{{d}}').render({'d': datetime.date.today()})
67
    assert datetime.date.today().strftime('%Y') in today
68

  
69
    tmpl = Template('{{ today }}')
70
    for mode in (None, 'lazy'):
71
        context = pub.substitutions.get_context_variables(mode=mode)
72
        assert tmpl.render(context) == today
73
    tmpl = Template('{{ now }}')
74
    for mode in (None, 'lazy'):
75
        context = pub.substitutions.get_context_variables(mode=mode)
76
        assert today in tmpl.render(context)  # contains the date,
77
        assert tmpl.render(context) != today  # but not only
78

  
79
    # ezt templates (legacy)
80
    today = Template('[t]').render({'t': datetime.date.today()})
81
    assert today == datetime.date.today().strftime('%Y-%m-%d')
82
    now = Template('[n]').render({'n': datetime.datetime.now()})
83
    assert now == datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
84

  
85
    tmpl = Template('[today]')
86
    for mode in (None, 'lazy'):
87
        context = pub.substitutions.get_context_variables(mode=mode)
88
        assert tmpl.render(context) == today
89
    tmpl = Template('[now]')
90
    for mode in (None, 'lazy'):
91
        context = pub.substitutions.get_context_variables(mode=mode)
92
        assert tmpl.render(context) == now
93

  
62 94
def test_template_templatetag():
63 95
    # check qommon templatetags are always loaded
64 96
    tmpl = Template('{{ date|parse_datetime|date:"Y" }}')
65
-