toulouse-maelis: explicit RL can use perisco booking endpoints (#78890)
gitea/passerelle/pipeline/head This commit looks good Details

This commit is contained in:
Nicolas Roche 2023-06-22 12:17:43 +02:00 committed by Nicolas Roche
parent ab2f8a847b
commit 06f22a03f8
3 changed files with 52 additions and 52 deletions

View File

@ -17,7 +17,7 @@
BOOKING_SCHEMA = {
'type': 'object',
'properties': {
'child_id': {
'person_id': {
'type': 'string',
'minLength': 1,
'maxLength': 8,
@ -39,7 +39,7 @@ BOOKING_SCHEMA = {
},
},
'required': [
'child_id',
'person_id',
'booking_list',
'start_date',
'end_date',

View File

@ -2220,20 +2220,20 @@ class ToulouseMaelis(BaseResource, HTTPResource):
@endpoint(
display_category='Réservation',
description="Obtenir l'agenda d'un enfant",
name='read-child-agenda',
description="Obtenir l'agenda d'un responsable légal ou d'un enfant",
name='read-person-agenda',
parameters={
'child_id': {'description': "Numéro de l'enfant"},
'person_id': {'description': "Numéro du responsable légal ou de l'enfant"},
'start_date': {'description': 'Début de la période'},
'end_date': {'description': 'Fin de la période'},
'NameID': {'description': 'Publik NameID'},
'family_id': {'description': 'Numéro de DUI'},
},
)
def read_child_agenda(self, request, child_id, start_date, end_date, NameID=None, family_id=None):
def read_person_agenda(self, request, person_id, start_date, end_date, NameID=None, family_id=None):
family_id = family_id or self.get_link(NameID).family_id
start_date, end_date, reference_year = self.get_start_and_end_dates(start_date, end_date)
bookings = self.get_bookings(family_id, child_id, start_date, end_date)
bookings = self.get_bookings(family_id, person_id, start_date, end_date)
return {
'data': bookings,
'extra_data': {
@ -2245,8 +2245,8 @@ class ToulouseMaelis(BaseResource, HTTPResource):
@endpoint(
display_category='Réservation',
description="Modifier l'agenda d'un enfant",
name='update-child-agenda',
description="Modifier l'agenda d'un responsable légal ou d'un enfant",
name='update-person-agenda',
parameters={
'NameID': {'description': 'Publik NameID'},
'family_id': {'description': 'Numéro de DUI'},
@ -2259,16 +2259,16 @@ class ToulouseMaelis(BaseResource, HTTPResource):
}
},
)
def update_child_agenda(self, request, post_data, NameID=None, family_id=None):
def update_person_agenda(self, request, post_data, NameID=None, family_id=None):
family_id = family_id or self.get_link(NameID).family_id
child_id = post_data['child_id']
person_id = post_data['person_id']
start_date, end_date, dummy = self.get_start_and_end_dates(
post_data['start_date'], post_data['end_date']
)
requested_bookings = post_data['booking_list']
# build list of existing booked days
bookings = self.get_bookings(family_id, child_id, start_date, end_date)
bookings = self.get_bookings(family_id, person_id, start_date, end_date)
legacy_bookings = [b['id'] for b in bookings if b['prefill'] is True]
available_bookings = [b['id'] for b in bookings if b['disabled'] is False]
@ -2297,7 +2297,7 @@ class ToulouseMaelis(BaseResource, HTTPResource):
# no changes, don't send the day
bookings_to_update.append(
{
'numPerson': child_id,
'numPerson': person_id,
'idAct': booking_info['details']['activity_id'],
'idUni': booking_info['details']['unit_id'],
'date': booking_info['details']['day_str'],

View File

@ -4948,17 +4948,17 @@ def test_read_exemption_reasons_list(con, app):
assert 'text' in item
def test_read_child_agenda(activity_service, con, app):
def test_read_person_agenda(activity_service, con, app):
activity_service.add_soap_response(
'getPersonScheduleList', get_xml_file('R_get_person_schedule_list.xml')
)
url = get_endpoint('read-child-agenda')
url = get_endpoint('read-person-agenda')
resp = app.get(url + '?family_id=1312&child_id=613880&start_date=2023-01-01&end_date=2023-01-15')
resp = app.get(url + '?family_id=1312&person_id=613880&start_date=2023-01-01&end_date=2023-01-15')
assert resp.json['err'] == 0
Link.objects.create(resource=con, family_id='1312', name_id='local')
resp = app.get(url + '?NameID=local&child_id=613880&start_date=2023-01-01&end_date=2023-01-15')
resp = app.get(url + '?NameID=local&person_id=613880&start_date=2023-01-01&end_date=2023-01-15')
assert resp.json['err'] == 0
assert resp.json['extra_data'] == {
@ -5323,17 +5323,17 @@ def test_read_child_agenda(activity_service, con, app):
]
def test_read_child_agenda_multi_units(activity_service, con, app):
def test_read_person_agenda_multi_units(activity_service, con, app):
activity_service.add_soap_response(
'getPersonScheduleList', get_xml_file('R_get_person_schedule_list_with_multi_units.xml')
)
url = get_endpoint('read-child-agenda')
url = get_endpoint('read-person-agenda')
resp = app.get(url + '?family_id=1312&child_id=613880&start_date=2023-01-01&end_date=2023-01-15')
resp = app.get(url + '?family_id=1312&person_id=613880&start_date=2023-01-01&end_date=2023-01-15')
assert resp.json['err'] == 0
Link.objects.create(resource=con, family_id='1312', name_id='local')
resp = app.get(url + '?NameID=local&child_id=613880&start_date=2023-01-01&end_date=2023-01-15')
resp = app.get(url + '?NameID=local&person_id=613880&start_date=2023-01-01&end_date=2023-01-15')
assert resp.json['err'] == 0
assert resp.json['extra_data'] == {
@ -5456,17 +5456,17 @@ def test_read_child_agenda_multi_units(activity_service, con, app):
]
def test_read_child_agenda_with_activity(activity_service, con, app):
def test_read_person_agenda_with_activity(activity_service, con, app):
activity_service.add_soap_response(
'getPersonScheduleList', get_xml_file('R_get_person_schedule_list_with_activity.xml')
)
url = get_endpoint('read-child-agenda')
url = get_endpoint('read-person-agenda')
resp = app.get(url + '?family_id=1312&child_id=322423&start_date=2023-05-01&end_date=2023-05-31')
resp = app.get(url + '?family_id=1312&person_id=322423&start_date=2023-05-01&end_date=2023-05-31')
assert resp.json['err'] == 0
Link.objects.create(resource=con, family_id='1312', name_id='local')
resp = app.get(url + '?NameID=local&child_id=322423&start_date=2023-05-01&end_date=2023-05-31')
resp = app.get(url + '?NameID=local&person_id=322423&start_date=2023-05-01&end_date=2023-05-31')
assert resp.json['err'] == 0
assert resp.json['extra_data'] == {
@ -5529,44 +5529,44 @@ def test_read_child_agenda_with_activity(activity_service, con, app):
]
def test_read_child_agenda_not_linked_error(con, app):
url = get_endpoint('read-child-agenda')
def test_read_person_agenda_not_linked_error(con, app):
url = get_endpoint('read-person-agenda')
resp = app.get(url + '?NameID=local&child_id=613880&start_date=2022-09-01&end_date=2023-08-31')
resp = app.get(url + '?NameID=local&person_id=613880&start_date=2022-09-01&end_date=2023-08-31')
assert resp.json['err'] == 1
assert resp.json['err_desc'] == 'User not linked to family'
def test_read_child_agenda_date_error(con, app):
url = get_endpoint('read-child-agenda')
def test_read_person_agenda_date_error(con, app):
url = get_endpoint('read-person-agenda')
Link.objects.create(resource=con, family_id='1312', name_id='local')
resp = app.get(url + '?NameID=local&child_id=613880&start_date=bad&end_date=2023-08-31', status=400)
resp = app.get(url + '?NameID=local&person_id=613880&start_date=bad&end_date=2023-08-31', status=400)
assert resp.json['err'] == 1
assert resp.json['err_desc'] == 'bad date format, should be YYYY-MM-DD'
resp = app.get(url + '?NameID=local&child_id=613880&start_date=2022-09-01&end_date=bad', status=400)
resp = app.get(url + '?NameID=local&person_id=613880&start_date=2022-09-01&end_date=bad', status=400)
assert resp.json['err'] == 1
assert resp.json['err_desc'] == 'bad date format, should be YYYY-MM-DD'
resp = app.get(
url + '?NameID=local&child_id=613880&start_date=2023-09-01&end_date=2023-08-31', status=400
url + '?NameID=local&person_id=613880&start_date=2023-09-01&end_date=2023-08-31', status=400
)
assert resp.json['err'] == 1
assert resp.json['err_desc'] == 'start_date should be before end_date'
resp = app.get(
url + '?NameID=local&child_id=613880&start_date=2022-09-01&end_date=2024-08-31', status=400
url + '?NameID=local&person_id=613880&start_date=2022-09-01&end_date=2024-08-31', status=400
)
assert resp.json['err'] == 1
assert resp.json['err_desc'] == 'start_date and end_date are in different reference year (2022 != 2023)'
def test_update_child_agenda(activity_service, con, app):
def test_update_person_agenda(activity_service, con, app):
activity_service.add_soap_response(
'getPersonScheduleList', get_xml_file('R_get_person_schedule_list.xml')
)
url = get_endpoint('update-child-agenda')
url = get_endpoint('update-person-agenda')
def request_check(request):
assert request.numDossier == 1312
@ -5597,7 +5597,7 @@ def test_update_child_agenda(activity_service, con, app):
)
params = {
'child_id': '613880',
'person_id': '613880',
'start_date': '2023-01-01',
'end_date': '2023-01-15',
'booking_list': [
@ -5652,15 +5652,15 @@ def test_update_child_agenda(activity_service, con, app):
}
def test_update_child_agenda_no_changes(activity_service, con, app):
def test_update_person_agenda_no_changes(activity_service, con, app):
activity_service.add_soap_response(
'getPersonScheduleList', get_xml_file('R_get_person_schedule_list.xml')
)
url = get_endpoint('update-child-agenda')
url = get_endpoint('update-person-agenda')
Link.objects.create(resource=con, family_id='1312', name_id='local')
params = {
'child_id': '613880',
'person_id': '613880',
'start_date': '2023-01-01',
'end_date': '2023-01-15',
'booking_list': [
@ -5677,11 +5677,11 @@ def test_update_child_agenda_no_changes(activity_service, con, app):
assert resp.json == []
def test_update_child_agenda_maelis_error(activity_service, con, app):
def test_update_person_agenda_maelis_error(activity_service, con, app):
activity_service.add_soap_response(
'getPersonScheduleList', get_xml_file('R_get_person_schedule_list.xml')
)
url = get_endpoint('update-child-agenda')
url = get_endpoint('update-person-agenda')
Link.objects.create(resource=con, family_id='1312', name_id='local')
activity_service.add_soap_response(
@ -5689,7 +5689,7 @@ def test_update_child_agenda_maelis_error(activity_service, con, app):
)
params = {
'child_id': '613880',
'person_id': '613880',
'start_date': '2023-01-01',
'end_date': '2023-01-15',
'booking_list': [
@ -5701,11 +5701,11 @@ def test_update_child_agenda_maelis_error(activity_service, con, app):
assert resp.json['err_desc'] == 'Foo ; Bar'
def test_update_child_agenda_not_linked_error(con, app):
url = get_endpoint('update-child-agenda')
def test_update_person_agenda_not_linked_error(con, app):
url = get_endpoint('update-person-agenda')
params = {
'child_id': '613880',
'person_id': '613880',
'start_date': '2022-09-01',
'end_date': '2023-08-31',
'booking_list': [],
@ -5715,12 +5715,12 @@ def test_update_child_agenda_not_linked_error(con, app):
assert resp.json['err_desc'] == 'User not linked to family'
def test_update_child_agenda_date_error(con, app):
url = get_endpoint('update-child-agenda')
def test_update_person_agenda_date_error(con, app):
url = get_endpoint('update-person-agenda')
Link.objects.create(resource=con, family_id='1312', name_id='local')
params = {
'child_id': '613880',
'person_id': '613880',
'start_date': 'bad',
'end_date': '2023-08-31',
'booking_list': [],
@ -5730,7 +5730,7 @@ def test_update_child_agenda_date_error(con, app):
assert resp.json['err_desc'] == "start_date: 'bad' does not match '^[0-9]{4}-[0-9]{2}-[0-9]{2}$'"
params = {
'child_id': '613880',
'person_id': '613880',
'start_date': '2022-09-01',
'end_date': 'bad',
'booking_list': [],
@ -5740,7 +5740,7 @@ def test_update_child_agenda_date_error(con, app):
assert resp.json['err_desc'] == "end_date: 'bad' does not match '^[0-9]{4}-[0-9]{2}-[0-9]{2}$'"
params = {
'child_id': '613880',
'person_id': '613880',
'start_date': '2023-09-01',
'end_date': '2023-08-31',
'booking_list': [],
@ -5750,7 +5750,7 @@ def test_update_child_agenda_date_error(con, app):
assert resp.json['err_desc'] == 'start_date should be before end_date'
params = {
'child_id': '613880',
'person_id': '613880',
'start_date': '2022-09-01',
'end_date': '2024-08-31',
'booking_list': [],