planitec: return unavailable places (#35941)

This commit is contained in:
Emmanuel Cazenave 2019-09-09 13:03:59 +02:00
parent 8db639426f
commit ca492db2b7
2 changed files with 35 additions and 19 deletions

View File

@ -571,7 +571,7 @@ class PlanitechConnector(BaseResource):
res.append({"id": place, "text": places_ref[place]['label']})
return res
def _full_display(self, raw_data):
def _full_display(self, raw_data, places_id):
places_ref = self._raw_get_places_referential()
res = {
'date': self._date_display(raw_data),
@ -579,16 +579,18 @@ class PlanitechConnector(BaseResource):
}
all_dates = [d['id'] for d in res['date']]
full = []
for place in raw_data.get('availablePlaces', []):
place_id = int(place['placeIdentifier'])
for place_id in places_id:
place_data = {
'id': place_id,
'text': places_ref[place_id]['label'],
'dates': []
}
place_dates = []
for freegap in place.get('freeGaps', []):
place_dates.append(freegap[0].date().isoformat())
for place in raw_data.get('availablePlaces', []):
if place_id == int(place['placeIdentifier']):
for freegap in place.get('freeGaps', []):
place_dates.append(freegap[0].date().isoformat())
break
for d in all_dates:
available = d in place_dates
place_data['dates'].append({'id': d, 'available': available})
@ -718,7 +720,7 @@ class PlanitechConnector(BaseResource):
return {'data': self._place_display(raw_data)}
if display == 'full':
return {'data': self._full_display(raw_data)}
return {'data': self._full_display(raw_data, places_id)}
def generic_call(self, endpoint, data_key):
raw_data = self._call_planitech(self.requests.post, endpoint)

View File

@ -1,3 +1,4 @@
import collections
from datetime import datetime
from django.contrib.contenttypes.models import ContentType
@ -633,19 +634,21 @@ def test_get_reservations_infos(app, connector, monkeypatch):
def freegaps_data():
referential = {
3.0: {
u'capacity': 30.0, u'label': u'salle 2', u'identifier': 2.0,
u'some_custom_field': u'Yes'
},
2.0: {
u'capacity': 20.0, u'label': u'salle 2', u'identifier': 2.0,
u'some_custom_field': u'Yes'
},
1.0: {
u'capacity': 10.0, u'label': u'salle 1', u'identifier': 1.0
}
}
referential = collections.OrderedDict(
[
(1.0, {
u'capacity': 10.0, u'label': u'salle 1', u'identifier': 1.0
}),
(2.0, {
u'capacity': 20.0, u'label': u'salle 2', u'identifier': 2.0,
u'some_custom_field': u'Yes'
}),
(3.0, {
u'capacity': 30.0, u'label': u'salle 3', u'identifier': 3.0,
u'some_custom_field': u'Yes'
}),
]
)
place1_gaps = [
[datetime(year=2018, month=11, day=11, hour=10, minute=0),
datetime(year=2018, month=11, day=11, hour=11, minute=0)],
@ -720,6 +723,8 @@ def test_get_freegaps(app, connector, monkeypatch, settings):
assert 'place' in res
assert 'date' in res
full = res['full']
assert len(full) == 3
place_1 = full[0]
assert place_1['id'] == 1.0
assert place_1['text'] == u'salle 1'
@ -738,6 +743,15 @@ def test_get_freegaps(app, connector, monkeypatch, settings):
{u'available': True, u'id': u'2018-11-13'}
]
place_3 = full[2]
assert place_3['id'] == 3.0
assert place_3['text'] == u'salle 3'
assert place_3['dates'] == [
{u'available': False, u'id': u'2018-11-11'},
{u'available': False, u'id': u'2018-11-12'},
{u'available': False, u'id': u'2018-11-13'}
]
# general params interpretation
mock_call_planitech.reset_mock()
response = app.get(