tests: add a test on badges having exception (#50419)

This commit is contained in:
Nicolas Roche 2021-01-23 16:43:01 +01:00
parent 7764be274a
commit 1cab06e861
1 changed files with 30 additions and 1 deletions

View File

@ -5,7 +5,8 @@ import os
from django.utils.safestring import mark_safe
from combo_plugin_gnm.templatetags.gnm import as_opening_hours_badge
from combo_plugin_gnm.templatetags.gnm import (
as_opening_hours_badge, EN_FULL_WEEKDAYS_LIST, FR_WEEKDAYS)
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
@ -308,3 +309,31 @@ def test_mairie_saint_genis_lavak():
test_html = as_opening_hours_badge(geojson['features'][0])
klass, label = 'open', u"Ouvert jusqu'à 17h30"
assert test_html == mark_safe(u'<div class="badge %s"><span>%s</span></div>' % (klass, label))
@pytest.mark.freeze_time('2018-01-04 14:59:00')
@pytest.mark.parametrize(
'validFrom, validTrought, badge, message', [
('2017-12-01', '2018-02-01', 'closed', 'Fermé'),
('2018-01-04', '2018-01-04', 'closed', 'Réouvre demain à 8h30'),
('2018-01-04', '2018-01-09', 'closed', "Réouvre mercredi à 8h30"),
('2018-01-04', '2018-01-11', 'closed', "Fermé"),
('2018-01-05', '2018-01-11', 'open', "Ouvert jusqu'à 17h30"),
])
def test_mairie_holiday_period(validFrom, validTrought, badge, message):
ohs = []
for weekday in EN_FULL_WEEKDAYS_LIST:
ohs.append({
'opens': '08:30',
'closes': '17:30',
'dayOfWeek': 'http://schema.org/%s' % weekday,
'validFrom': '2018-01-01T00:00:00+01:00',
'validThrough': '2018-06-30T23:59:59+01:00'
})
ohs.append({
'validFrom': '%sT00:00:00+01:00' % validFrom,
'validThrough': '%sT23:59:59+01:00' % validTrought,
})
data = {'properties': {'openinghoursspecification': ohs}}
html = as_opening_hours_badge(data)
assert html == '<div class="badge %s"><span>%s</span></div>' % (badge, message)