toulouse-maelis: [functests] add tests on activity service (#76089)
gitea/passerelle/pipeline/head This commit looks good Details

Nicolas Roche 2023-03-31 19:02:36 +02:00
parent 71a0822a3e
commit 2ff9fcf643
2 changed files with 390 additions and 0 deletions

View File

@ -437,6 +437,8 @@ def create_data(request, conn):
'lastname': lastname,
'rl1_num': data['RL1']['num'],
'bart_num': data['childList'][0]['num'],
'maggie_num': data['childList'][1]['num'],
'hugo_num': data['childList'][2]['num'],
'data': data,
}
@ -508,3 +510,131 @@ def update_data(request, conn):
'maggie_num': data['childList'][2]['num'],
'data': data,
}
@pytest.fixture(scope='session')
def reference_year():
some_date = datetime.date.today()
if some_date.month <= 8:
# between january and august, reference year is the year just before
return some_date.year - 1
return some_date.year
def get_subscription_info(nature, activity_text, unit_text, place_text, con, name_id, person_id, year):
def select_item(resp, text):
item = None
for item in resp.json()['data']:
if item['text'] == text:
break
else:
raise Exception("do not find '%s'" % text)
return item
# select activity
url = con + '/get-person-activity-list'
params = {
'NameID': name_id,
'person_id': person_id,
'start_date': '%s-09-01' % year,
'end_date': '%s-08-31' % (year + 1),
'nature': nature,
}
resp = requests.get(url, params=params)
resp.raise_for_status()
assert resp.json()['err'] == 0
assert len(resp.json()['data']) > 0
activity = select_item(resp, activity_text)
# select unit
url = con + '/get-person-unit-list'
params = {
'NameID': name_id,
'person_id': person_id,
'start_date': '%s-09-01' % year,
'end_date': '%s-08-31' % (year + 1),
'activity_id': activity['id'],
}
resp = requests.get(url, params=params)
resp.raise_for_status()
assert resp.json()['err'] == 0
assert len(resp.json()['data']) > 0
unit = select_item(resp, unit_text)
# select place
url = con + '/get-person-place-list'
params = {
'NameID': name_id,
'person_id': person_id,
'start_date': '%s-09-01' % year,
'end_date': '%s-08-31' % (year + 1),
'activity_id': activity['id'],
'unit_id': unit['id'],
}
resp = requests.get(url, params=params)
resp.raise_for_status()
assert resp.json()['err'] == 0
assert len(resp.json()['data']) > 0
place = select_item(resp, place_text)
assert place['capacityInfo']['controlOK'] is True
# check subscription info
url = con + '/get-person-subscription-info'
params = {
'NameID': name_id,
'person_id': person_id,
'activity_id': activity['id'],
'unit_id': unit['id'],
'place_id': place['id'],
'ref_date': datetime.date.today().strftime('%Y-%m-%d'),
}
resp = requests.get(url, params=params)
resp.raise_for_status()
assert resp.json()['err'] == 0
info = resp.json()['data']
assert info['controlResult']['controlOK'] is True
return {
'activity': activity,
'unit': unit,
'place': place,
'info': info,
}
@pytest.fixture(scope='session')
def extrasco_subscribe_info(conn, create_data, reference_year):
unlink(conn, create_data['name_id'])
link(conn, create_data)
return get_subscription_info(
'EXTRASCO',
# Sigec made this extra-sco activity available for functests
'ADL ELEMENTAIRE Maourine Avril 2023',
'ADL ELEMENTAIRE Maourine Avril 2023',
'MAOURINE (la) ELEMENTAIRE',
conn,
create_data['name_id'],
create_data['bart_num'],
reference_year,
)
@pytest.fixture(scope='session')
def perisco_subscribe_info(conn, create_data, reference_year):
'''This fixture is a configuration trick from Sigec
as peri-sco should not be available for subscription
and as a consequence, should not be displayed from catalogs'''
unlink(conn, create_data['name_id'])
link(conn, create_data)
return get_subscription_info(
None,
# Sigec made this peri-sco activity available for functests
'TEMPS DU MIDI 22/23',
'TEMPS DU MIDI 22/23',
'DOLTO FRANCOISE MATERNELLE',
conn,
create_data['name_id'],
create_data['bart_num'],
reference_year,
)

View File

@ -0,0 +1,260 @@
import datetime
import requests
from .conftest import link, unlink
def test_perisco(perisco_subscribe_info):
assert perisco_subscribe_info['info']['activity']['libelle1'] == 'TEMPS DU MIDI 22/23'
def test_perisco_calendar(conn, create_data, perisco_subscribe_info, reference_year):
# subscription
url = conn + '/add-person-subscription?NameID=%s' % create_data['name_id']
payload = {
'person_id': create_data['bart_num'],
'activity_id': perisco_subscribe_info['activity']['id'],
'unit_id': perisco_subscribe_info['unit']['id'],
'place_id': perisco_subscribe_info['place']['id'],
'start_date': perisco_subscribe_info['unit']['dateStart'][:10],
'end_date': perisco_subscribe_info['unit']['dateEnd'][:10],
}
resp = requests.post(url, json=payload)
resp.raise_for_status()
assert resp.json()['err'] == 0
# find first available booking
url = conn + '/read-child-agenda?NameID=%s' % create_data['name_id']
params = {
'child_id': create_data['bart_num'],
'start_date': perisco_subscribe_info['unit']['dateStart'][:10],
'end_date': perisco_subscribe_info['unit']['dateEnd'][:10],
}
resp = requests.get(url, params=params)
resp.raise_for_status()
assert resp.json()['err'] == 0
assert len(resp.json()['data']) > 0
booking = None
for booking in resp.json()['data']:
if booking['disabled'] is False:
break
else:
raise Exception("no booking available")
assert booking['details']['activity_id'] == perisco_subscribe_info['activity']['id']
assert booking['prefill'] is False
# book activity
url = conn + '/update-child-agenda?NameID=%s' % create_data['name_id']
payload = {
'child_id': create_data['bart_num'],
'start_date': perisco_subscribe_info['unit']['dateStart'][:10],
'end_date': perisco_subscribe_info['unit']['dateEnd'][:10],
'booking_list': [booking['id']],
}
resp = requests.post(url, json=payload)
resp.raise_for_status()
assert resp.json() == {
'updated': True,
'count': 1,
'changes': [
{
'booked': True,
'activity_id': booking['details']['activity_id'],
'activity_label': 'Restauration scolaire',
'day': booking['details']['day_str'],
}
],
'err': 0,
}
# check booking
url = conn + '/read-child-agenda?NameID=%s' % create_data['name_id']
params = {
'child_id': create_data['bart_num'],
'start_date': perisco_subscribe_info['unit']['dateStart'][:10],
'end_date': perisco_subscribe_info['unit']['dateEnd'][:10],
}
resp = requests.get(url, params=params)
resp.raise_for_status()
assert resp.json()['err'] == 0
assert [x['prefill'] for x in resp.json()['data'] if x['id'] == booking['id']][0] is True
def test_catalog_general_loisirs(conn, update_data):
unlink(conn, update_data['name_id'])
link(conn, update_data)
url = conn + '/read-activity-list'
params = {'ref_date': datetime.date.today().strftime('%Y-%m-%d')}
resp = requests.get(url, params=params)
resp.raise_for_status()
assert resp.json()['err'] == 0
# still not nature code defined on LOISIR activities
assert len(resp.json()['data']) == 0
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
# check subscription info
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': '%s-09-01' % reference_year,
'end_date': '%s-08-31' % (reference_year + 1),
}
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_basket_subscribe(conn, create_data, extrasco_subscribe_info, reference_year):
assert extrasco_subscribe_info['info']['controlResult']['controlOK'] is True
def get_baskets():
url = conn + '/get-baskets?NameID=%s' % create_data['name_id']
resp = requests.get(url)
resp.raise_for_status()
assert resp.json()['err'] == 0
return resp.json()['data']
def subscribe(person_id):
url = conn + '/add-person-basket-subscription?NameID=%s' % create_data['name_id']
payload = {
'person_id': person_id,
'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()
return resp
# empty basket
assert get_baskets() == []
# subscribe Bart
resp = subscribe(create_data['bart_num'])
assert resp.json()['err'] == 0
data = resp.json()['data']
assert data['controlResult'] == {'controlOK': True, 'message': None}
assert data['basket']['codeRegie'] is None # No codeRegie #2174
assert len({x['personneInfo']['numPerson'] for x in data['basket']['lignes']}) == 1
assert len({x['idIns'] for x in data['basket']['lignes']}) == 3
# basket
data = get_baskets()
assert len(data) == 1
assert data[0]['codeRegie'] == 105
assert data[0]['text'] == 'ENFANCE LOISIRS ET PE'
assert len(data[0]['lignes']) == 3
assert len({x['personneInfo']['numPerson'] for x in data[0]['lignes']}) == 1
# get 3 idIns because we subscribe a generic unit
assert len({x['idIns'] for x in data[0]['lignes']}) == 3
basket_id = data[0]['id']
# cannot subscribe Bart twice
resp = subscribe(create_data['bart_num'])
assert resp.json()['err'] == 1
assert 'E1019' in resp.json()['err_desc']
assert len(get_baskets()) == 1
# delete basket
# should be call by user or by cron job
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
assert resp.json()['data'] == 'ok'
assert get_baskets() == []
# subscribe Bart
resp = subscribe(create_data['bart_num'])
assert resp.json()['err'] == 0
data = resp.json()['data']
assert data['controlResult'] == {'controlOK': True, 'message': None}
assert len({x['personneInfo']['numPerson'] for x in data['basket']['lignes']}) == 1
# subscribe Maggie
resp = subscribe(create_data['maggie_num'])
assert resp.json()['err'] == 0
data = resp.json()['data']
assert data['controlResult'] == {'controlOK': True, 'message': None}
assert len({x['personneInfo']['numPerson'] for x in data['basket']['lignes']}) == 2
# delete (generic) basket line for Bart
data = get_baskets()
assert len(data) == 1
assert len(data[0]['lignes']) == 6
basket_id = data[0]['id']
# idIns for the generic unit
line_id = [
y['id']
for x in data
for y in x['lignes']
if y['personneInfo']['numPerson'] == int(create_data['bart_num'])
if y['inscription']['idUnit'] == extrasco_subscribe_info['unit']['id']
][0]
url = conn + '/delete-basket-line?NameID=%s' % create_data['name_id']
payload = {
'basket_id': basket_id,
'line_id': line_id,
}
resp = requests.post(url, json=payload)
resp.raise_for_status()
assert resp.json()['err'] == 0
data = resp.json()['data']
assert data['codeRegie'] is None # No codeRegie #2174
assert len({x['personneInfo']['numPerson'] for x in data['lignes']}) == 1
assert len({x['idIns'] for x in data['lignes']}) == 3
data = get_baskets()
assert len(data) == 1
assert len(get_baskets()) == 1
assert len(data[0]['lignes']) == 3
# re-subscribe Bart
resp = subscribe(create_data['bart_num'])
assert resp.json()['err'] == 0
data = resp.json()['data']
assert data['controlResult'] == {'controlOK': True, 'message': None}
assert len({x['personneInfo']['numPerson'] for x in data['basket']['lignes']}) == 2
# validate basket
url = conn + '/validate-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
data = resp.json()['data']
assert len(data['idInsLst']) == 6
assert len(data['factureLst']) == 0
assert get_baskets() == []
# TODO
# read_subscribe_activity_list
# cancelInvoiceAndDeleteSubscribeList
# read_subscribe_activity_list
# ...
# payInvoice