toulouse-maelis: add conveyance to add_person_basket_subscription endpoint (#74860)
gitea/passerelle/pipeline/head This commit looks good Details

This commit is contained in:
Nicolas Roche 2023-02-23 17:44:44 +01:00
parent 85cee0abe0
commit 4e4a1227c4
3 changed files with 138 additions and 0 deletions

View File

@ -83,6 +83,19 @@ SUBSCRIPTION_SCHEMA = {
{'type': 'null'},
],
},
'conveyanceSubscribe': {
'type': 'object',
'properties': {
'idPlaceMorning': {
'type': 'string',
'pattern': '^[A-Za-z0-9]*$',
},
'idPlaceAfternoon': {
'type': 'string',
'pattern': '^[A-Za-z0-9]*$',
},
},
},
},
'required': [
'person_id',
@ -92,6 +105,7 @@ SUBSCRIPTION_SCHEMA = {
'start_date',
'end_date',
],
'unflatten': True,
}
DELETE_BASKET_LINE_SCHEMA = {

View File

@ -2782,6 +2782,36 @@ class ToulouseMaelis(BaseResource, HTTPResource):
family_id=None,
):
family_id = family_id or self.get_link(NameID).family_id
params = {
'numDossier': family_id,
'numPerson': post_data['person_id'],
'activityUnitPlace': {
'idActivity': post_data['activity_id'],
'idUnit': post_data['unit_id'],
'idPlace': post_data['place_id'],
},
}
subscription_info = self.call('Activity', 'getPersonUnitInfo', getPersonUnitInfoRequestBean=params)
if post_data.get('conveyanceSubscribe') and (
post_data['conveyanceSubscribe'].get('idPlaceMorning')
or post_data['conveyanceSubscribe'].get('idPlaceAfternoon')
):
if not subscription_info.get('conveyance'):
raise APIError('no conveyance defined on this activity')
for payload_key, info_key in [
('idPlaceMorning', 'morningJourney'),
('idPlaceAfternoon', 'afternoonJourney'),
]:
if post_data['conveyanceSubscribe'].get(payload_key):
info_bus_ids = [
x['place']['id']
for x in subscription_info['conveyance'][info_key]['depositPlaceList']
]
payload_bus_id = post_data['conveyanceSubscribe'][payload_key]
if not payload_bus_id in info_bus_ids:
raise APIError(
'no "%s" place defined on "%s" conveyance' % (payload_bus_id, info_key)
)
recurrent_week = []
for item in post_data.get('recurrent_week') or []:
@ -2803,6 +2833,7 @@ class ToulouseMaelis(BaseResource, HTTPResource):
'dateStartSubscribe': post_data['start_date'],
'dateEndSubscribe': post_data['end_date'],
'dayWeekInfoList': recurrent_week,
'conveyanceSubscribe': post_data.get('conveyanceSubscribe'),
}
}
response = self.call('Activity', 'addPersonUnitBasket', **payload)

View File

@ -6091,6 +6091,10 @@ def test_get_person_subscription_info_loisir_date_error(con, app):
def test_add_person_basket_subscription(activity_service, con, app):
activity_service.add_soap_response(
'getPersonUnitInfo',
get_xml_file('R_get_person_unit_info.xml'),
)
activity_service.add_soap_response(
'addPersonUnitBasket',
get_xml_file('R_add_person_unit_basket.xml'),
@ -6167,6 +6171,10 @@ def test_add_person_basket_subscription_with_recurrent_week(activity_service, co
{'dayNum': 2, 'isPresent': True, 'isOpen': None, 'calendarLetter': 'C'},
]
activity_service.add_soap_response(
'getPersonUnitInfo',
get_xml_file('R_get_person_unit_info_with_conveyance.xml'),
)
activity_service.add_soap_response(
'addPersonUnitBasket',
get_xml_file('R_add_person_unit_basket.xml'),
@ -6192,6 +6200,10 @@ def test_add_person_basket_subscription_with_recurrent_week(activity_service, co
def test_add_person_basket_subscription_error(activity_service, con, app):
activity_service.add_soap_response(
'getPersonUnitInfo',
get_xml_file('R_get_person_unit_info.xml'),
)
activity_service.add_soap_response(
'addPersonUnitBasket',
get_xml_file('R_add_person_unit_basket_error.xml'),
@ -6226,6 +6238,87 @@ def test_add_person_basket_subscription_not_linked_error(con, app):
assert resp.json['err_desc'] == 'User not linked to family'
def test_add_person_basket_subscription_with_conveyance(activity_service, con, app):
def request_check(request):
assert serialize_object(request.conveyanceSubscribe) == {
'idPlaceMorning': 'A10053179757',
'idPlaceAfternoon': 'A10053179757',
}
activity_service.add_soap_response(
'getPersonUnitInfo',
get_xml_file('R_get_person_unit_info_with_conveyance.xml'),
)
activity_service.add_soap_response(
'addPersonUnitBasket',
get_xml_file('R_add_person_unit_basket.xml'),
request_check=request_check,
)
url = get_endpoint('add-person-basket-subscription')
params = {
'person_id': '261768',
'activity_id': 'A10053179798',
'unit_id': 'A10053179803',
'place_id': 'A10053179757',
'start_date': '2022-09-01',
'end_date': '2023-08-31',
'conveyanceSubscribe/idPlaceMorning': 'A10053179757',
'conveyanceSubscribe/idPlaceAfternoon': 'A10053179757',
}
resp = app.post_json(url + '?family_id=322423', params=params)
assert resp.json['err'] == 0
def test_add_person_basket_subscription_providing_conveyance_error(activity_service, con, app):
activity_service.add_soap_response(
'getPersonUnitInfo',
get_xml_file('R_get_person_unit_info.xml'),
)
url = get_endpoint('add-person-basket-subscription')
params = {
'person_id': '261768',
'activity_id': 'A10053179798',
'unit_id': 'A10053179803',
'place_id': 'A10053179757',
'start_date': '2022-09-01',
'end_date': '2023-08-31',
'conveyanceSubscribe/idPlaceMorning': 'A10053179757',
}
resp = app.post_json(url + '?family_id=322423', params=params)
assert resp.json['err'] == 1
assert resp.json['err_desc'] == 'no conveyance defined on this activity'
def test_add_person_basket_subscription_with_conveyance_not_found(activity_service, con, app):
activity_service.add_soap_response(
'getPersonUnitInfo',
get_xml_file('R_get_person_unit_info_with_conveyance.xml'),
)
url = get_endpoint('add-person-basket-subscription')
params = {
'person_id': '261768',
'activity_id': 'A10053179798',
'unit_id': 'A10053179803',
'place_id': 'A10053179757',
'start_date': '2022-09-01',
'end_date': '2023-08-31',
'conveyanceSubscribe/idPlaceMorning': 'plop',
'conveyanceSubscribe/idPlaceAfternoon': 'A10053179757',
}
resp = app.post_json(url + '?family_id=322423', params=params)
assert resp.json['err'] == 1
assert resp.json['err_desc'] == 'no "plop" place defined on "morningJourney" conveyance'
params['conveyanceSubscribe/idPlaceMorning'] = ''
params['conveyanceSubscribe/idPlaceAfternoon'] = 'plop'
resp = app.post_json(url + '?family_id=322423', params=params)
assert resp.json['err'] == 1
assert resp.json['err_desc'] == 'no "plop" place defined on "afternoonJourney" conveyance'
def test_get_basket(activity_service, con, app):
activity_service.add_soap_response('getFamilyBasket', get_xml_file('R_get_family_basket.xml'))
url = get_endpoint('get-basket')