templatetags: let mdr be served as geojson (#22050)

This commit is contained in:
Frédéric Péters 2018-03-10 17:21:40 +01:00
parent 7873a12535
commit 0e62a5de05
3 changed files with 2325 additions and 0 deletions

View File

@ -79,6 +79,8 @@ def get_slots_from_mdr_format(data, today):
"""Process data from /ws/grandlyon/ter_territoire.maison_du_rhone/all.json
add to slots all the next opening hours in chronological order & beginning from today()
"""
if 'properties' in data:
data = data['properties']
slots = []
known_format = False
mdr_weekdays_format = ['%s_am' % day for day in FR_WEEKDAYS] + ['%s_pm' % day for day in FR_WEEKDAYS]

2308
tests/data/mdr-geojson.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -12,6 +12,8 @@ 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}
@ -62,3 +64,16 @@ def test_mairie_open_as_opening_hours_templatetag():
assert test_html == mark_safe(u'<div class="badge %s"><span>%s</span></div>'% (klass, label))
test_html = as_opening_hours_badge(GEOJSON[1], base_datetime=test_datetime)
assert test_html == mark_safe(u'<div class="badge %s"><span>%s</span></div>'% (klass, label))
def test_every_mdr_closed_at_midnight():
"""every mdr is closed at mignight"""
midnight = parse("2018-03-05T00:00:00+01:00")
opening_hours = [as_opening_hours_badge(x, base_datetime=midnight) 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