199 lines
8.2 KiB
Python
199 lines
8.2 KiB
Python
import requests
|
|
|
|
|
|
def test_catalog_personnalise_extrasco(extrasco_subscribe_info):
|
|
assert extrasco_subscribe_info['info']['activity']['libelle1'] == 'ADL ELEMENTAIRE Maourine Avril 2023'
|
|
assert extrasco_subscribe_info['info']['calendarGeneration']['code'] == 'REQUIRED'
|
|
assert extrasco_subscribe_info['info']['billingInformation'] == {
|
|
'modeFact': 'PRESENCE',
|
|
'quantity': None,
|
|
'unitPrice': 43.0,
|
|
}
|
|
|
|
|
|
def test_direct_subscribe(conn, create_data, extrasco_subscribe_info, reference_year):
|
|
assert extrasco_subscribe_info['info']['controlResult']['controlOK'] is True
|
|
|
|
url = conn + '/add-person-subscription?NameID=%s' % create_data['name_id']
|
|
payload = {
|
|
'person_id': create_data['hugo_num'],
|
|
'activity_id': extrasco_subscribe_info['activity']['id'],
|
|
'unit_id': extrasco_subscribe_info['unit']['id'],
|
|
'place_id': extrasco_subscribe_info['place']['id'],
|
|
'start_date': extrasco_subscribe_info['unit']['dateStart'][:10],
|
|
'end_date': extrasco_subscribe_info['unit']['dateEnd'][:10],
|
|
}
|
|
resp = requests.post(url, json=payload)
|
|
resp.raise_for_status()
|
|
assert resp.json()['err'] == 0
|
|
|
|
# no idIns provided to remove subscription later
|
|
assert resp.json()['data'] == {'controlOK': True, 'message': None}
|
|
|
|
|
|
def test_subscribe_with_conveyance(conn, create_data, extrasco_subscribe_info):
|
|
assert extrasco_subscribe_info['info']['controlResult']['controlOK'] is True
|
|
|
|
assert extrasco_subscribe_info['info']['conveyance'] is not None
|
|
morning = [
|
|
x['id'] for x in extrasco_subscribe_info['info']['conveyance']['morningJourney']['depositPlaceList']
|
|
]
|
|
afternoon = [
|
|
x['id'] for x in extrasco_subscribe_info['info']['conveyance']['afternoonJourney']['depositPlaceList']
|
|
]
|
|
assert len(morning) > 0
|
|
assert len(afternoon) > 0
|
|
|
|
url = conn + '/add-person-basket-subscription?NameID=%s' % create_data['name_id']
|
|
payload = {
|
|
'person_id': create_data['bart_num'],
|
|
'activity_id': extrasco_subscribe_info['activity']['id'],
|
|
'unit_id': extrasco_subscribe_info['unit']['id'],
|
|
'place_id': extrasco_subscribe_info['place']['id'],
|
|
'start_date': extrasco_subscribe_info['unit']['dateStart'][:10],
|
|
'end_date': extrasco_subscribe_info['unit']['dateEnd'][:10],
|
|
'conveyanceSubscribe/idPlaceMorning': morning[0],
|
|
'conveyanceSubscribe/idPlaceAfternoon': afternoon[0],
|
|
}
|
|
resp = requests.post(url, json=payload)
|
|
resp.raise_for_status()
|
|
assert resp.json()['err'] == 0
|
|
basket_id = resp.json()['data']['basket']['id']
|
|
|
|
# remove subscription
|
|
url = conn + '/delete-basket?NameID=%s' % create_data['name_id']
|
|
payload = {'basket_id': basket_id}
|
|
resp = requests.post(url, json=payload)
|
|
resp.raise_for_status()
|
|
assert resp.json()['err'] == 0
|
|
|
|
|
|
def test_subscribe_with_recurrent_week(conn, create_data, extrasco_subscribe_info):
|
|
assert extrasco_subscribe_info['info']['controlResult']['controlOK'] is True
|
|
assert [(x['id'], x['day']) for x in extrasco_subscribe_info['info']['recurrent_week']] == [
|
|
('1-C', 'Lundi'),
|
|
('1-B', 'Lundi'),
|
|
('2-C', 'Mardi'),
|
|
('2-B', 'Mardi'),
|
|
('3-C', 'Mercredi'),
|
|
('3-B', 'Mercredi'),
|
|
('4-C', 'Jeudi'),
|
|
('4-B', 'Jeudi'),
|
|
('5-C', 'Vendredi'),
|
|
('5-B', 'Vendredi'),
|
|
]
|
|
|
|
url = conn + '/add-person-basket-subscription?NameID=%s' % create_data['name_id']
|
|
payload = {
|
|
'person_id': create_data['bart_num'],
|
|
'activity_id': extrasco_subscribe_info['activity']['id'],
|
|
'unit_id': extrasco_subscribe_info['unit']['id'],
|
|
'place_id': extrasco_subscribe_info['place']['id'],
|
|
'start_date': extrasco_subscribe_info['unit']['dateStart'][:10],
|
|
'end_date': extrasco_subscribe_info['unit']['dateEnd'][:10],
|
|
'recurrent_week': ['1-B', '2-C'],
|
|
}
|
|
resp = requests.post(url, json=payload)
|
|
resp.raise_for_status()
|
|
assert resp.json()['err'] == 0
|
|
basket_id = resp.json()['data']['basket']['id']
|
|
|
|
# there is now some bookings
|
|
url = conn + '/read-activity-agenda?NameID=%s' % create_data['name_id']
|
|
params = {
|
|
'person_id': create_data['bart_num'],
|
|
'activity_id': extrasco_subscribe_info['activity']['id'],
|
|
'start_date': extrasco_subscribe_info['unit']['dateStart'][:10],
|
|
'end_date': extrasco_subscribe_info['unit']['dateEnd'][:10],
|
|
}
|
|
resp = requests.get(url, params=params)
|
|
resp.raise_for_status()
|
|
assert resp.json()['err'] == 0
|
|
assert any(x['prefill'] for x in resp.json()['data'])
|
|
|
|
# remove subscription
|
|
url = conn + '/delete-basket?NameID=%s' % create_data['name_id']
|
|
payload = {'basket_id': basket_id}
|
|
resp = requests.post(url, json=payload)
|
|
resp.raise_for_status()
|
|
assert resp.json()['err'] == 0
|
|
|
|
|
|
def test_subscribe_with_agenda(conn, create_data, extrasco_subscribe_info):
|
|
assert extrasco_subscribe_info['info']['controlResult']['controlOK'] is True
|
|
|
|
def get_bookings():
|
|
url = conn + '/read-activity-agenda?NameID=%s' % create_data['name_id']
|
|
params = {
|
|
'person_id': create_data['bart_num'],
|
|
'activity_id': extrasco_subscribe_info['activity']['id'],
|
|
'start_date': extrasco_subscribe_info['unit']['dateStart'][:10],
|
|
'end_date': extrasco_subscribe_info['unit']['dateEnd'][:10],
|
|
}
|
|
resp = requests.get(url, params=params)
|
|
resp.raise_for_status()
|
|
assert resp.json()['err'] == 0
|
|
return resp.json()['data']
|
|
|
|
# subscribe witout providing calandar
|
|
url = conn + '/add-person-basket-subscription?NameID=%s' % create_data['name_id']
|
|
payload = {
|
|
'person_id': create_data['bart_num'],
|
|
'activity_id': extrasco_subscribe_info['activity']['id'],
|
|
'unit_id': extrasco_subscribe_info['unit']['id'],
|
|
'place_id': extrasco_subscribe_info['place']['id'],
|
|
'start_date': extrasco_subscribe_info['unit']['dateStart'][:10],
|
|
'end_date': extrasco_subscribe_info['unit']['dateEnd'][:10],
|
|
}
|
|
resp = requests.post(url, json=payload)
|
|
resp.raise_for_status()
|
|
assert resp.json()['err'] == 0
|
|
basket_id = resp.json()['data']['basket']['id']
|
|
|
|
# no booking
|
|
assert not any(x['prefill'] for x in get_bookings())
|
|
|
|
# book using info calendar gabarit (booking registered from w.c.s. form)
|
|
assert len(extrasco_subscribe_info['info']['agenda']) > 0
|
|
assert not any(x['prefill'] for x in extrasco_subscribe_info['info']['agenda'])
|
|
slots = [x['id'] for x in extrasco_subscribe_info['info']['agenda'] if x['disabled'] is False]
|
|
url = conn + '/update-activity-agenda/?NameID=%s' % create_data['name_id']
|
|
payload = {
|
|
'person_id': create_data['bart_num'],
|
|
'activity_id': extrasco_subscribe_info['activity']['id'],
|
|
'start_date': extrasco_subscribe_info['unit']['dateStart'][:10],
|
|
'end_date': extrasco_subscribe_info['unit']['dateEnd'][:10],
|
|
'booking_list': [slots[0], slots[-1]],
|
|
}
|
|
resp = requests.post(url, json=payload)
|
|
resp.raise_for_status()
|
|
assert resp.json()['err'] == 0
|
|
assert resp.json()['updated'] is True
|
|
assert [x['booked'] for x in resp.json()['changes']] == [True, True]
|
|
|
|
# there is now 2 bookings
|
|
assert len([x['prefill'] for x in get_bookings() if x['prefill'] is True]) == 2
|
|
|
|
# unbook slots
|
|
url = conn + '/update-activity-agenda/?NameID=%s' % create_data['name_id']
|
|
payload = {
|
|
'person_id': create_data['bart_num'],
|
|
'activity_id': extrasco_subscribe_info['activity']['id'],
|
|
'start_date': extrasco_subscribe_info['unit']['dateStart'][:10],
|
|
'end_date': extrasco_subscribe_info['unit']['dateEnd'][:10],
|
|
'booking_list': [],
|
|
}
|
|
resp = requests.post(url, json=payload)
|
|
resp.raise_for_status()
|
|
assert resp.json()['err'] == 0
|
|
assert resp.json()['updated'] is True
|
|
assert [x['booked'] for x in resp.json()['changes']] == [False, False]
|
|
assert not any(x['prefill'] for x in get_bookings())
|
|
|
|
# remove subscription
|
|
url = conn + '/delete-basket?NameID=%s' % create_data['name_id']
|
|
payload = {'basket_id': basket_id}
|
|
resp = requests.post(url, json=payload)
|
|
resp.raise_for_status()
|
|
assert resp.json()['err'] == 0
|