49 lines
1.9 KiB
Python
49 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
from dateutil.parser import parse
|
|
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']
|
|
TZOFFSETS = {"Europe/Paris": 3600}
|
|
|
|
|
|
def test_every_mairie_closed_at_midnight():
|
|
"""every mairie 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 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')]
|
|
# actually not everything, Jonage and Solaize are not handled correctly as
|
|
# they only use openinghoursspecification → 2
|
|
assert opening_hours.count('') == 2 # FIXME
|
|
|
|
|
|
def test_mairie_nodata_as_opening_hours_templatetag():
|
|
""""no data return the right empty html"""
|
|
test_datetime = parse("2018-03-05T15:59:00+01:00")
|
|
test_html = as_opening_hours_badge(GEOJSON[0]['properties'], base_datetime=test_datetime)
|
|
assert test_html == ''
|
|
|
|
|
|
def test_mairie_open_as_opening_hours_templatetag():
|
|
"""mairie as_opening_hours with a fixed datetime"""
|
|
klass = 'open'
|
|
label = u"Ouvert jusqu'à 17h00"
|
|
test_datetime = parse("2018-03-05T15:55:00+01:00")
|
|
test_html = as_opening_hours_badge(GEOJSON[1]['properties'], base_datetime=test_datetime)
|
|
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))
|