|
|
|
@ -9,11 +9,11 @@ from combo_plugin_gnm.templatetags.gnm import EN_FULL_WEEKDAYS_LIST, FR_WEEKDAYS
|
|
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
|
|
|
|
GEOJSON = json.load(open(os.path.join(BASE_DIR, 'tests/data/mairie-geojson.json')))['features']
|
|
|
|
|
MDR_GEOJSON = json.load(open(os.path.join(BASE_DIR, 'tests/data/mdr-geojson.json')))['features']
|
|
|
|
|
TZOFFSETS = {"Europe/Paris": 3600}
|
|
|
|
|
TZOFFSETS = {'Europe/Paris': 3600}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.freeze_time(
|
|
|
|
|
"2018-03-04 23:00:00",
|
|
|
|
|
'2018-03-04 23:00:00',
|
|
|
|
|
)
|
|
|
|
|
def test_every_mairie_closed():
|
|
|
|
|
"""every mairie is closed at mignight"""
|
|
|
|
@ -21,7 +21,7 @@ def test_every_mairie_closed():
|
|
|
|
|
assert len([x for x in opening_hours if 'open' in x]) == 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-03-04 23:00:00")
|
|
|
|
|
@pytest.mark.freeze_time('2018-03-04 23:00:00')
|
|
|
|
|
def test_all_mairie_data_parsed_correct():
|
|
|
|
|
"""everything got parsed correctly"""
|
|
|
|
|
opening_hours = [
|
|
|
|
@ -32,14 +32,14 @@ def test_all_mairie_data_parsed_correct():
|
|
|
|
|
assert opening_hours.count('') == 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-03-05 14:59:00")
|
|
|
|
|
@pytest.mark.freeze_time('2018-03-05 14:59:00')
|
|
|
|
|
def test_empty_data():
|
|
|
|
|
""" "no data return the empty html"""
|
|
|
|
|
test_html = as_opening_hours_badge(GEOJSON[0]['properties'])
|
|
|
|
|
assert test_html == ''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-08-13 14:59:00")
|
|
|
|
|
@pytest.mark.freeze_time('2018-08-13 14:59:00')
|
|
|
|
|
def test_mairie_bron_monday():
|
|
|
|
|
"""S1326"""
|
|
|
|
|
test_html = [as_opening_hours_badge(x) for x in GEOJSON if x['properties']['identifiant'] == 'S1326'][0]
|
|
|
|
@ -47,15 +47,15 @@ def test_mairie_bron_monday():
|
|
|
|
|
assert test_html == mark_safe('<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-08-12 14:59:00")
|
|
|
|
|
@pytest.mark.freeze_time('2018-08-12 14:59:00')
|
|
|
|
|
def test_mairie_bron_sunday():
|
|
|
|
|
"""S1326"""
|
|
|
|
|
test_html = [as_opening_hours_badge(x) for x in GEOJSON if x['properties']['identifiant'] == 'S1326'][0]
|
|
|
|
|
klass, label = 'closed', "Réouvre demain à 8h00"
|
|
|
|
|
klass, label = 'closed', 'Réouvre demain à 8h00'
|
|
|
|
|
assert test_html == mark_safe('<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-08-09 13:30:01")
|
|
|
|
|
@pytest.mark.freeze_time('2018-08-09 13:30:01')
|
|
|
|
|
def test_mairie_sathonay_thursday_afternoon():
|
|
|
|
|
"""S1326"""
|
|
|
|
|
test_html = [as_opening_hours_badge(x) for x in GEOJSON if x['properties']['identifiant'] == 'S1415'][0]
|
|
|
|
@ -63,15 +63,15 @@ def test_mairie_sathonay_thursday_afternoon():
|
|
|
|
|
assert test_html == mark_safe('<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-08-11 11:30:01")
|
|
|
|
|
@pytest.mark.freeze_time('2018-08-11 11:30:01')
|
|
|
|
|
def test_mairie_saint_priest_closed():
|
|
|
|
|
"""S1326"""
|
|
|
|
|
test_html = [as_opening_hours_badge(x) for x in GEOJSON if x['properties']['identifiant'] == 'S1406'][0]
|
|
|
|
|
klass, label = 'closed', "Réouvre lundi à 8h15"
|
|
|
|
|
klass, label = 'closed', 'Réouvre lundi à 8h15'
|
|
|
|
|
assert test_html == mark_safe('<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-08-22 12:13:01")
|
|
|
|
|
@pytest.mark.freeze_time('2018-08-22 12:13:01')
|
|
|
|
|
def test_mairie_saint_priest_open():
|
|
|
|
|
"""S1326"""
|
|
|
|
|
test_html = [as_opening_hours_badge(x) for x in GEOJSON if x['properties']['identifiant'] == 'S1406'][0]
|
|
|
|
@ -79,17 +79,17 @@ def test_mairie_saint_priest_open():
|
|
|
|
|
assert test_html == mark_safe('<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-08-11 14:59:00")
|
|
|
|
|
@pytest.mark.freeze_time('2018-08-11 14:59:00')
|
|
|
|
|
def test_mairie_bron_saturday():
|
|
|
|
|
"""S1326"""
|
|
|
|
|
test_html = [as_opening_hours_badge(x) for x in GEOJSON if x['properties']['identifiant'] == 'S1326'][0]
|
|
|
|
|
klass, label = 'closed', "Réouvre lundi à 8h00"
|
|
|
|
|
klass, label = 'closed', 'Réouvre lundi à 8h00'
|
|
|
|
|
assert test_html == mark_safe('<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-03-05 09:59:13")
|
|
|
|
|
@pytest.mark.freeze_time('2018-03-05 09:59:13')
|
|
|
|
|
def test_jonage_open():
|
|
|
|
|
"Jonage is defined only by openinghoursspecification data"
|
|
|
|
|
'Jonage is defined only by openinghoursspecification data'
|
|
|
|
|
test_html = [as_opening_hours_badge(x) for x in GEOJSON if x['properties']['nom'] == 'Mairie de Jonage'][
|
|
|
|
|
0
|
|
|
|
|
]
|
|
|
|
@ -97,9 +97,9 @@ def test_jonage_open():
|
|
|
|
|
assert test_html == mark_safe('<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-03-05 11:32:00")
|
|
|
|
|
@pytest.mark.freeze_time('2018-03-05 11:32:00')
|
|
|
|
|
def test_jonage_soon_to_be_closed():
|
|
|
|
|
"Jonage is defined only by openinghoursspecification data"
|
|
|
|
|
'Jonage is defined only by openinghoursspecification data'
|
|
|
|
|
test_html = [as_opening_hours_badge(x) for x in GEOJSON if x['properties']['nom'] == 'Mairie de Jonage'][
|
|
|
|
|
0
|
|
|
|
|
]
|
|
|
|
@ -107,17 +107,17 @@ def test_jonage_soon_to_be_closed():
|
|
|
|
|
assert test_html == mark_safe('<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-03-10 17:30:00")
|
|
|
|
|
@pytest.mark.freeze_time('2018-03-10 17:30:00')
|
|
|
|
|
def test_jonage_closed():
|
|
|
|
|
"Jonage is defined only by openinghoursspecification data"
|
|
|
|
|
'Jonage is defined only by openinghoursspecification data'
|
|
|
|
|
test_html = [as_opening_hours_badge(x) for x in GEOJSON if x['properties']['nom'] == 'Mairie de Jonage'][
|
|
|
|
|
0
|
|
|
|
|
]
|
|
|
|
|
klass, label = 'closed', "Réouvre lundi à 8h30"
|
|
|
|
|
klass, label = 'closed', 'Réouvre lundi à 8h30'
|
|
|
|
|
assert test_html == mark_safe('<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-03-05 15:55:00")
|
|
|
|
|
@pytest.mark.freeze_time('2018-03-05 15:55:00')
|
|
|
|
|
def test_data_input_compatibility():
|
|
|
|
|
"""as_opening_hours with a fixed datetime"""
|
|
|
|
|
klass = 'open'
|
|
|
|
@ -128,7 +128,7 @@ def test_data_input_compatibility():
|
|
|
|
|
assert test_html == mark_safe('<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-03-05 00:00:00")
|
|
|
|
|
@pytest.mark.freeze_time('2018-03-05 00:00:00')
|
|
|
|
|
def test_all_mdr_closed():
|
|
|
|
|
"""every mdr is closed at mignight"""
|
|
|
|
|
opening_hours = [as_opening_hours_badge(x) for x in MDR_GEOJSON]
|
|
|
|
@ -141,41 +141,41 @@ def test_all_mdr_data_parsed_correct():
|
|
|
|
|
assert opening_hours.count('') == 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-03-05 14:59:00")
|
|
|
|
|
@pytest.mark.freeze_time('2018-03-05 14:59:00')
|
|
|
|
|
def test_mdr_open():
|
|
|
|
|
test_html = as_opening_hours_badge(MDR_GEOJSON[0])
|
|
|
|
|
klass, label = 'open', "Ouvert jusqu'à 16h45"
|
|
|
|
|
assert test_html == mark_safe('<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-03-05 15:46:00")
|
|
|
|
|
@pytest.mark.freeze_time('2018-03-05 15:46:00')
|
|
|
|
|
def test_mdr_soon_to_be_closed():
|
|
|
|
|
test_html = as_opening_hours_badge(MDR_GEOJSON[0])
|
|
|
|
|
klass, label = 'soon-to-be-closed', "Ouvert jusqu'à 16h45"
|
|
|
|
|
assert test_html == mark_safe('<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-03-10 17:30:00")
|
|
|
|
|
@pytest.mark.freeze_time('2018-03-10 17:30:00')
|
|
|
|
|
def test_mdr_just_closed():
|
|
|
|
|
test_html = as_opening_hours_badge(MDR_GEOJSON[0])
|
|
|
|
|
klass, label = 'closed', "Réouvre lundi à 8h30"
|
|
|
|
|
klass, label = 'closed', 'Réouvre lundi à 8h30'
|
|
|
|
|
assert test_html == mark_safe('<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-01-01 14:59:00")
|
|
|
|
|
@pytest.mark.freeze_time('2018-01-01 14:59:00')
|
|
|
|
|
def test_mairie_holiday():
|
|
|
|
|
# Ecully, using datetimes
|
|
|
|
|
test_html = [as_opening_hours_badge(x) for x in GEOJSON if x['properties']['identifiant'] == 'S1361'][0]
|
|
|
|
|
klass, label = 'closed', "Réouvre demain à 8h30"
|
|
|
|
|
klass, label = 'closed', 'Réouvre demain à 8h30'
|
|
|
|
|
assert test_html == mark_safe('<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
|
|
|
|
# Feyzin, using dates
|
|
|
|
|
test_html = [as_opening_hours_badge(x) for x in GEOJSON if x['properties']['identifiant'] == 'S1365'][0]
|
|
|
|
|
klass, label = 'closed', "Réouvre demain à 8h30"
|
|
|
|
|
klass, label = 'closed', 'Réouvre demain à 8h30'
|
|
|
|
|
assert test_html == mark_safe('<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-03-05 00:30:00")
|
|
|
|
|
@pytest.mark.freeze_time('2018-03-05 00:30:00')
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
'day, hours, badge, text',
|
|
|
|
|
[
|
|
|
|
@ -188,7 +188,7 @@ def test_mairie_holiday():
|
|
|
|
|
('lundi_am', '00h00-00h45', 'soon-to-be-closed', "Ouvert jusqu'à 0h45"),
|
|
|
|
|
('dimanche_pm', '20h30-00h45', 'soon-to-be-closed', "Ouvert jusqu'à 0h45"),
|
|
|
|
|
('lundi_am', '00h15-24h00', 'open', "Ouvert jusqu'à minuit"),
|
|
|
|
|
('lundi_am', '00h00-24h00', 'open', "Ouvert 24h/24"),
|
|
|
|
|
('lundi_am', '00h00-24h00', 'open', 'Ouvert 24h/24'),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
def test_mdr_format(day, hours, badge, text):
|
|
|
|
@ -206,7 +206,7 @@ def test_mdr_format(day, hours, badge, text):
|
|
|
|
|
assert html == '<div class="badge %s"><span>%s</span></div>' % (badge, text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-03-05 00:30:00")
|
|
|
|
|
@pytest.mark.freeze_time('2018-03-05 00:30:00')
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
'openinghour, badge, text',
|
|
|
|
|
[
|
|
|
|
@ -219,7 +219,7 @@ def test_mdr_format(day, hours, badge, text):
|
|
|
|
|
('Mo 00:00-00:45', 'soon-to-be-closed', "Ouvert jusqu'à 0h45"),
|
|
|
|
|
('Su 20:30-00:45', 'soon-to-be-closed', "Ouvert jusqu'à 0h45"),
|
|
|
|
|
('Mo 00:15-24:00', 'open', "Ouvert jusqu'à minuit"),
|
|
|
|
|
('Mo 00:00-24:00', 'open', "Ouvert 24h/24"),
|
|
|
|
|
('Mo 00:00-24:00', 'open', 'Ouvert 24h/24'),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
def test_mairie_format_openinghours(openinghour, badge, text):
|
|
|
|
@ -237,7 +237,7 @@ def test_mairie_format_openinghours(openinghour, badge, text):
|
|
|
|
|
assert html == '<div class="badge %s"><span>%s</span></div>' % (badge, text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-03-05 00:30:00")
|
|
|
|
|
@pytest.mark.freeze_time('2018-03-05 00:30:00')
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
'day, opens, closes, badge, text',
|
|
|
|
|
[
|
|
|
|
@ -250,7 +250,7 @@ def test_mairie_format_openinghours(openinghour, badge, text):
|
|
|
|
|
('Monday', '00:00', '00:45', 'soon-to-be-closed', "Ouvert jusqu'à 0h45"),
|
|
|
|
|
('Sunday', '20:30', '00:45', 'soon-to-be-closed', "Ouvert jusqu'à 0h45"),
|
|
|
|
|
('Monday', '00:15', '24:00', 'open', "Ouvert jusqu'à minuit"),
|
|
|
|
|
('Monday', '00:00', '24:00', 'open', "Ouvert 24h/24"),
|
|
|
|
|
('Monday', '00:00', '24:00', 'open', 'Ouvert 24h/24'),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
def test_mairie_format_openinghoursspecification(day, opens, closes, badge, text):
|
|
|
|
@ -275,7 +275,7 @@ def test_mairie_format_openinghoursspecification(day, opens, closes, badge, text
|
|
|
|
|
assert html == '<div class="badge %s"><span>%s</span></div>' % (badge, text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-03-09 00:30:00")
|
|
|
|
|
@pytest.mark.freeze_time('2018-03-09 00:30:00')
|
|
|
|
|
def test_mairie_having_both_formats():
|
|
|
|
|
"""openinghoursspecification take preference over openinghours"""
|
|
|
|
|
geojson = r"""
|
|
|
|
@ -298,7 +298,7 @@ def test_mairie_having_both_formats():
|
|
|
|
|
assert html == '<div class="badge %s"><span>%s</span></div>' % ('closed', 'Réouvre lundi à 9h30')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.freeze_time("2021-01-21 15:37:00")
|
|
|
|
|
@pytest.mark.freeze_time('2021-01-21 15:37:00')
|
|
|
|
|
def test_mairie_saint_genis_lavak():
|
|
|
|
|
"""#50337"""
|
|
|
|
|
geojson = json.load(open(os.path.join(BASE_DIR, 'tests/data/mairie-saint-genis-lavak.json')))
|
|
|
|
@ -313,8 +313,8 @@ def test_mairie_saint_genis_lavak():
|
|
|
|
|
[
|
|
|
|
|
('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-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"),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|