From 7f3354c4680a3fefa9bf78c9cece446aa08f0211 Mon Sep 17 00:00:00 2001 From: Emmanuel Cazenave Date: Fri, 23 Nov 2018 18:46:32 +0100 Subject: [PATCH] planitech: filter dates by place id (#28298) --- functests/planitech/test_planitech.py | 15 ++++++++++++++- passerelle/contrib/planitech/models.py | 12 ++++++++++-- tests/test_planitech.py | 9 +++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/functests/planitech/test_planitech.py b/functests/planitech/test_planitech.py index 893124b..d4214bd 100644 --- a/functests/planitech/test_planitech.py +++ b/functests/planitech/test_planitech.py @@ -7,7 +7,7 @@ import requests def test_main(conn): - # get a free gap + # get days today = datetime.datetime.now().date().isoformat() query_string = urllib.urlencode({ 'start_date': today, 'start_time': '10:00', 'end_time': '11:00' @@ -34,6 +34,19 @@ def test_main(conn): assert data place = data[random.randint(0, len(data) - 1)]['id'] + # get days on one place + today = datetime.datetime.now().date().isoformat() + query_string = urllib.urlencode({ + 'start_date': today, 'start_time': '10:00', 'end_time': '11:00', 'place_id': place + }) + url = conn + '/getdays?%s' % query_string + resp = requests.get(url) + resp.raise_for_status() + res = resp.json() + assert res['err'] == 0 + data = res['data'] + assert data + # create reservation params = { 'date': date, 'start_time': '10:00', 'end_time': '11:00', diff --git a/passerelle/contrib/planitech/models.py b/passerelle/contrib/planitech/models.py index 8ea20a2..50a214d 100644 --- a/passerelle/contrib/planitech/models.py +++ b/passerelle/contrib/planitech/models.py @@ -319,11 +319,19 @@ class PlanitechConnector(BaseResource): 'example_value': 'true', 'type': 'bool', }, + 'place_id': { + 'description': _('Place identifer'), + 'example_value': '2', + 'type': 'int', + } }) def getdays( self, request, start_date, start_time, end_time, min_capacity=0, - end_date=None, max_capacity=100000, weekdays=False): - places_id = self._get_places_by_capacity(int(min_capacity), int(max_capacity)) + end_date=None, max_capacity=100000, weekdays=False, place_id=None): + if place_id is not None: + places_id = [float(place_id)] + else: + places_id = self._get_places_by_capacity(int(min_capacity), int(max_capacity)) utc_start_datetime = get_utc_datetime(start_date, start_time) if end_date is None: diff --git a/tests/test_planitech.py b/tests/test_planitech.py index ea5bc3d..bc0711a 100644 --- a/tests/test_planitech.py +++ b/tests/test_planitech.py @@ -364,6 +364,15 @@ def test_get_days(app, connector, monkeypatch, settings): call_params = mock_call_planitech.call_args[0][2] assert call_params['requestedEndingTime'] == 180.0 + # place_id filter + mock_call_planitech.reset_mock() + response = app.get( + '/planitech/slug-planitech/getdays?start_time=11:00&&end_time=14:00' + '&start_date=2018-11-11&place_id=2' + ) + call_params = mock_call_planitech.call_args[0][2] + assert call_params['placeIdentifiers'] == [2.0] + # date bad format response = app.get( '/planitech/slug-planitech/getdays?start_time=11:00&&end_time=14:00' -- 2.19.2