70 lines
4.2 KiB
Python
70 lines
4.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
import pytest
|
|
import json
|
|
import os
|
|
|
|
from combo_plugin_gnm.templatetags.gnm import get_mairie_opening_hours
|
|
|
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
|
GEOJSON = json.load(open(os.path.join(
|
|
BASE_DIR, 'tests/data/mairie-geojson.json')))['features']
|
|
|
|
TZOFFSETS = {"Europe/Paris": 3600}
|
|
|
|
|
|
def test_mairie_hours_parsing():
|
|
"""everything is parsed correctly"""
|
|
opening_hours = [get_mairie_opening_hours(x) for x in GEOJSON]
|
|
assert len(opening_hours) == len(GEOJSON)
|
|
|
|
|
|
def test_mairie_hours_nodata():
|
|
""""no data return nothing"""
|
|
assert get_mairie_opening_hours(GEOJSON[0]['properties']) is None
|
|
|
|
|
|
def test_mairie_hours_special_data():
|
|
"""test results for various data examples"""
|
|
for x in GEOJSON:
|
|
if x['properties']['identifiant'] == 'S1376':
|
|
# La Mulatière
|
|
assert get_mairie_opening_hours(x) == [('lundi', {'am': u'08h30-12h00', 'pm': None}), ('mardi', {'am': u'08h30-12h30', 'pm': u'13h30-17h00'}), ('mercredi', {'am': u'08h30-12h30', 'pm': u'13h30-17h00'}), ('jeudi', {'am': u'08h30-12h30', 'pm': u'13h30-17h00'}), ('vendredi', {'am': u'08h30-12h30', 'pm': u'13h30-17h00'}), ('samedi', {'am': u'09h00-11h45', 'pm': None})]
|
|
|
|
if x['properties']['identifiant'] == 'S1437':
|
|
# special openinghours format with days intervals, comma-separated list and one day definition with a saturday
|
|
assert get_mairie_opening_hours(x) == [('lundi', {'am': u'08h45-12h30', 'pm': u'14h00-16h45'}), ('mardi', {'am': u'08h45-16h45', 'pm': ''}), ('mercredi', {'am': u'08h45-16h45', 'pm': ''}), ('jeudi', {'am': u'08h45-18h00', 'pm': ''}), ('vendredi', {'am': u'08h45-16h45', 'pm': ''}), ('samedi', {'am': u'09h00-12h00', 'pm': None})]
|
|
|
|
if x['properties']['identifiant'] == 'S5564':
|
|
# classic openinghours days interval for am and pm
|
|
assert get_mairie_opening_hours(x) == [('lundi', {'am': u'08h30-12h15', 'pm': u'13h15-17h00'}), ('mardi', {'am': u'08h30-12h15', 'pm': u'13h15-17h00'}), ('mercredi', {'am': u'08h30-12h15', 'pm': u'13h15-17h00'}), ('jeudi', {'am': u'08h30-12h15', 'pm': u'13h15-17h00'}), ('vendredi', {'am': u'08h30-12h15', 'pm': u'13h15-17h00'})]
|
|
|
|
|
|
@pytest.mark.freeze_time("2018-03-05 15:59:00")
|
|
def test_mairie_openinghoursspecification_period_valid():
|
|
"""Test valid periods of openinghoursspecification timetables"""
|
|
for x in GEOJSON:
|
|
if x['properties']['nom'] == 'Mairie de Jonage':
|
|
assert get_mairie_opening_hours(x) == [('lundi', {'am': '08h30-12h30', 'pm': '14h00-17h00'}), ('mardi', {'am': '08h30-12h30', 'pm': '14h00-17h00'}), ('mercredi', {'am': '08h30-12h30', 'pm': '14h00-17h00'}), ('jeudi', {'am': '08h30-12h30', 'pm': '14h00-17h00'}), ('vendredi', {'am': '08h30-12h30', 'pm': '14h00-17h00'}), ('samedi', {'am': '09h00-12h00', 'pm': '14h00-17h00'})]
|
|
return
|
|
|
|
|
|
@pytest.mark.freeze_time("2020-03-05 15:59:00")
|
|
def test_mairie_openinghoursspecification_period_invalid():
|
|
"""Test valid periods of openinghoursspecification timetables"""
|
|
for x in GEOJSON:
|
|
if x['properties']['nom'] == 'Mairie de Jonage':
|
|
assert get_mairie_opening_hours(x) is None
|
|
return
|
|
|
|
def test_mairie_sathonay_timetable():
|
|
"""Sathonay-Village S1415"""
|
|
test_time_table = [get_mairie_opening_hours(x) for x in GEOJSON if x['properties']['identifiant'] == 'S1415'][0]
|
|
assert test_time_table == [('lundi', {'am': u'08h30-12h00', 'pm': u'14h00-17h00'}), ('mardi', {'am': u'08h30-12h00', 'pm': u'13h30-17h00'}), ('mercredi', {'am': u'08h30-12h00', 'pm': u'14h00-17h00'}), ('jeudi', {'am': u'08h30-12h00', 'pm': u'14h00-17h00'}), ('vendredi', {'am': u'08h30-12h00', 'pm': u'14h00-17h00'}), ('samedi', {'am': u'08h30-12h00', 'pm': None})]
|
|
|
|
def test_mairie_saint_priest():
|
|
"S1406"
|
|
test_time_table = [get_mairie_opening_hours(x) for x in GEOJSON if x['properties']['identifiant'] == 'S1406'][0]
|
|
assert test_time_table == [('lundi', {'am': u'08h15-12h15', 'pm': u'13h30-17h30'}), ('mardi', {'am': u'08h15-12h15', 'pm': u'13h30-17h30'}), ('mercredi', {'am': u'08h15-12h15', 'pm': u'13h30-17h30'}), ('jeudi', {'am': u'08h15-11h15', 'pm': u'13h30-17h30'}), ('vendredi', {'am': u'08h15-12h15', 'pm': u'13h30-17h30'}), ('samedi', {'am': u'09h00-11h30', 'pm': None})]
|