168 lines
7.0 KiB
Python
168 lines
7.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
import pytest
|
|
import json
|
|
import os
|
|
|
|
from django.utils.safestring import mark_safe
|
|
|
|
from combo_plugin_gnm.templatetags.gnm import as_opening_hours_badge
|
|
|
|
|
|
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}
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-03-04 23:00:00",)
|
|
def test_every_mairie_closed():
|
|
"""every mairie is closed at mignight"""
|
|
opening_hours = [as_opening_hours_badge(x) for x in GEOJSON]
|
|
assert len([x for x in opening_hours if 'open' in x]) == 0
|
|
|
|
|
|
def test_all_mairie_data_parsed_correct():
|
|
"""everything got parsed correctly"""
|
|
opening_hours = [as_opening_hours_badge(x) for x in GEOJSON
|
|
if x['properties'].get('openinghours') or x['properties'].get('openinghoursspecification')]
|
|
assert opening_hours.count('') == 0
|
|
|
|
|
|
@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")
|
|
def test_mairie_bron_monday():
|
|
"""S1326"""
|
|
test_html = [as_opening_hours_badge(x) for x in GEOJSON if x['properties']['identifiant'] == 'S1326'][0]
|
|
klass, label = 'open', u"Ouvert jusqu'à 17h15"
|
|
assert test_html == mark_safe(u'<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
@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', u"Réouvre demain à 8h00"
|
|
assert test_html == mark_safe(u'<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
@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]
|
|
klass, label = 'open', u"Ouvert jusqu'à 17h00"
|
|
assert test_html == mark_safe(u'<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
@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', u"Réouvre lundi à 8h15"
|
|
assert test_html == mark_safe(u'<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
@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]
|
|
klass, label = 'soon-to-be-closed', u"Ouvert jusqu'à 12h15"
|
|
assert test_html == mark_safe(u'<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
@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', u"Réouvre lundi à 8h00"
|
|
assert test_html == mark_safe(u'<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-03-05 09:59:13")
|
|
def test_jonage_open():
|
|
"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 = 'open', u"Ouvert jusqu'à 12h30"
|
|
assert test_html == mark_safe(u'<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-03-05 10:32:00")
|
|
def test_jonage_soon_to_be_closed():
|
|
"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 = 'soon-to-be-closed', u"Ouvert jusqu'à 12h30"
|
|
assert test_html == mark_safe(u'<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-03-10 17:30:00")
|
|
def test_jonage_closed():
|
|
"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', u"Réouvre lundi à 8h30"
|
|
assert test_html == mark_safe(u'<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-03-05 15:55:00")
|
|
def test_data_input_compatibility():
|
|
"""as_opening_hours with a fixed datetime"""
|
|
klass = 'open'
|
|
label = u"Ouvert jusqu'à 17h00"
|
|
test_html = as_opening_hours_badge(GEOJSON[1]['properties'])
|
|
assert test_html == mark_safe(u'<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
test_html = as_opening_hours_badge(GEOJSON[1])
|
|
assert test_html == mark_safe(u'<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
@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]
|
|
assert len([x for x in opening_hours if 'open' in x]) == 0
|
|
|
|
|
|
def test_all_mdr_data_parsed_correct():
|
|
"""everything got parsed correctly"""
|
|
opening_hours = [as_opening_hours_badge(x) for x in MDR_GEOJSON]
|
|
assert opening_hours.count('') == 0
|
|
|
|
|
|
@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', u"Ouvert jusqu'à 16h45"
|
|
assert test_html == mark_safe(u'<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
@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', u"Ouvert jusqu'à 16h45"
|
|
assert test_html == mark_safe(u'<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
@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', u"Réouvre lundi à 8h30"
|
|
assert test_html == mark_safe(u'<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
|
|
|
|
|
@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', u"Réouvre demain à 8h30"
|
|
assert test_html == mark_safe(u'<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', u"Réouvre demain à 8h30"
|
|
assert test_html == mark_safe(u'<div class="badge %s"><span>%s</span></div>' % (klass, label))
|