planitec: expose days restriction parameter as is (#33198)
This commit is contained in:
parent
b06a0d68e9
commit
9396e907da
|
@ -578,9 +578,10 @@ class PlanitechConnector(BaseResource):
|
|||
'example_value': '10',
|
||||
},
|
||||
'weekdays': {
|
||||
'description': _('Week days'),
|
||||
'description': _('Week days, comma separated list of integers beetween'
|
||||
' 0 (sunday) and 6 (saturday)'),
|
||||
'example_value': 'true',
|
||||
'type': 'bool',
|
||||
'type': 'string',
|
||||
},
|
||||
'place_id': {
|
||||
'description': _('Place identifier'),
|
||||
|
@ -594,7 +595,7 @@ class PlanitechConnector(BaseResource):
|
|||
})
|
||||
def getfreegaps(
|
||||
self, request, display, start_time, end_time, min_capacity=0, start_date=None,
|
||||
start_days=None, end_date=None, end_days=None, max_capacity=100000, weekdays=False,
|
||||
start_days=None, end_date=None, end_days=None, max_capacity=100000, weekdays=None,
|
||||
place_id=None, **kwargs):
|
||||
|
||||
# Additional parameters check
|
||||
|
@ -636,8 +637,20 @@ class PlanitechConnector(BaseResource):
|
|||
"requestedStartingTime": float(0),
|
||||
"requestedEndingTime": duration
|
||||
}
|
||||
if not weekdays:
|
||||
params['reservationDays'] = [mste.Uint32(0), mste.Uint32(6)]
|
||||
|
||||
if weekdays is not None:
|
||||
reservation_days = []
|
||||
for day in [d.strip() for d in weekdays.split(',') if d.strip()]:
|
||||
try:
|
||||
day = mste.Uint32(day)
|
||||
if not 0 <= day <= 6:
|
||||
raise ValueError()
|
||||
reservation_days.append(mste.Uint32(day))
|
||||
except (ValueError, TypeError):
|
||||
raise APIError(
|
||||
'weekdays must be a comma separated list of integers beetween 0 and 6')
|
||||
if reservation_days:
|
||||
params['reservationDays'] = reservation_days
|
||||
|
||||
raw_data = self._call_planitech(self.requests.post, 'getFreeGaps', params)
|
||||
|
||||
|
|
|
@ -676,7 +676,7 @@ def test_get_freegaps(app, connector, monkeypatch, settings):
|
|||
assert call_params['placeIdentifiers'] == [1.0, 2.0, 3.0]
|
||||
assert call_params['requestedStartingTime'] == 0.0 # means startingDate
|
||||
assert call_params['requestedEndingTime'] == 60.0 # means startingDate + 60 minutes
|
||||
assert call_params['reservationDays'] == [0, 6] # means every day of the week
|
||||
assert 'reservationDays' not in call_params
|
||||
|
||||
# no end date means only the starting date is interesting
|
||||
# so ending date is the day after at midnight
|
||||
|
@ -708,15 +708,15 @@ def test_get_freegaps(app, connector, monkeypatch, settings):
|
|||
call_params = mock_call_planitech.call_args[0][2]
|
||||
assert call_params['placeIdentifiers'] == [2.0]
|
||||
|
||||
# weekdays means no week days exclusion
|
||||
# weekdays
|
||||
mock_call_planitech.reset_mock()
|
||||
response = app.get(
|
||||
'/planitech/slug-planitech/getfreegaps?start_time=11:00&&end_time=14:00'
|
||||
'&start_date=2018-11-11&max_capacity=15&place_id=2&display=place'
|
||||
'&weekdays=true'
|
||||
'&weekdays=0,1,2'
|
||||
)
|
||||
call_params = mock_call_planitech.call_args[0][2]
|
||||
assert 'reservationDays' not in call_params
|
||||
assert call_params['reservationDays'] == [0, 1, 2]
|
||||
|
||||
# custom field restriction
|
||||
mock_call_planitech.reset_mock()
|
||||
|
|
Loading…
Reference in New Issue