rsa13: add beneficiaire evenement endpoints (#84252)
This commit is contained in:
parent
4465d64903
commit
5b2f2d5b97
|
@ -33,6 +33,25 @@ from passerelle.utils.jsonresponse import APIError
|
|||
|
||||
OUI_NON_ENUM = {'enum': ['Oui', 'Non']}
|
||||
DATE_SCHEMA = {'type': 'string', 'format': 'date'}
|
||||
DATETIME_SCHEMA = {'type': 'string', 'format': 'datetime'}
|
||||
SOFT_INTEGER_SCHEMA = {
|
||||
'oneOf': [
|
||||
{'type': 'integer'},
|
||||
{'type': 'string', 'regex': '^[0-9]+$'},
|
||||
]
|
||||
}
|
||||
STRING_ID_TEXT_SCHEMA = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'id': {'type': 'string'},
|
||||
'text': {'type': 'string'},
|
||||
},
|
||||
}
|
||||
STRING_SCHEMA = {'type': 'string'}
|
||||
|
||||
|
||||
def nullable(schema):
|
||||
return {'oneOf': [{'type': 'null'}, schema]}
|
||||
|
||||
|
||||
def parameters(update=None):
|
||||
|
@ -2001,6 +2020,185 @@ class RSA13Resource(BaseResource, HTTPResource):
|
|||
def type_evenement(self, request, email, ip=None):
|
||||
return self.get('type-evenement/', email=email, ip=ip)
|
||||
|
||||
@endpoint(
|
||||
name='platform',
|
||||
methods=['get', 'post'],
|
||||
pattern=r'^(?P<platform_id>[0-9]{1,10})/'
|
||||
r'beneficiaire/(?P<beneficiary_id>[0-9]{1,10})/'
|
||||
r'evenement/$',
|
||||
example_pattern='{platform_id}/beneficiaire/{beneficiary_id}/evenement/',
|
||||
description=_('Get beneficiary events'),
|
||||
parameters=parameters(
|
||||
{
|
||||
'platform_id': {
|
||||
'description': _('Platform numeric identifier'),
|
||||
'example_value': '11',
|
||||
},
|
||||
'beneficiary_id': {
|
||||
'description': _('Beneficiary numeric identifier'),
|
||||
'example_value': '12',
|
||||
},
|
||||
}
|
||||
),
|
||||
post_json_schema={
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'code_tev': {'type': 'string'},
|
||||
'nom_evt': {'type': 'string'},
|
||||
'lieu_evt': {'type': 'string'},
|
||||
'dt_evt': DATETIME_SCHEMA,
|
||||
'duree_evt': SOFT_INTEGER_SCHEMA,
|
||||
'code_upl': SOFT_INTEGER_SCHEMA,
|
||||
'type_inter': {'type': 'string'},
|
||||
'com_evt': {'type': 'string'},
|
||||
},
|
||||
'unflatten': True,
|
||||
},
|
||||
display_category=_('Platform'),
|
||||
display_order=16,
|
||||
json_schema_response=response_schema(
|
||||
{
|
||||
'type': 'array',
|
||||
'items': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'id': {'type': 'integer'},
|
||||
'text': {'type': 'string'},
|
||||
'datetime': DATETIME_SCHEMA,
|
||||
'duree': {'type': 'integer'},
|
||||
'type': {'type': 'string'},
|
||||
'intervenant': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'id': {'type': 'integer'},
|
||||
'text': {'type': 'string'},
|
||||
'type': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'id': {'type': 'string'},
|
||||
'text': {'type': 'string'},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
'resultat': {
|
||||
'anyOf': [{'type': 'null'}, {'type': 'string'}],
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
),
|
||||
)
|
||||
def platform_beneficiaire_evenement(
|
||||
self, request, platform_id, beneficiary_id, email, post_data=None, ip=None
|
||||
):
|
||||
if request.method == 'POST':
|
||||
return self.post(
|
||||
'platform/%s/beneficiaire/%s/evenement/' % (platform_id, beneficiary_id),
|
||||
email=email,
|
||||
ip=ip,
|
||||
json=post_data,
|
||||
)
|
||||
else:
|
||||
return self.get(
|
||||
'platform/%s/beneficiaire/%s/evenement/' % (platform_id, beneficiary_id),
|
||||
email=email,
|
||||
ip=ip,
|
||||
)
|
||||
|
||||
platform_beneficiaire_evenement.endpoint_info.methods.insert(0, 'get')
|
||||
|
||||
@endpoint(
|
||||
name='platform',
|
||||
methods=['get', 'post', 'delete'],
|
||||
pattern=r'^(?P<platform_id>[0-9]{1,10})/'
|
||||
r'beneficiaire/(?P<beneficiary_id>[0-9]{1,10})/'
|
||||
r'evenement/(?P<event_id>[0-9]{1,10})/$',
|
||||
example_pattern='{platform_id}/beneficiaire/{beneficiary_id}/evenement/{event_id}/',
|
||||
description=_('Get beneficiary event\'s detail'),
|
||||
parameters=parameters(
|
||||
{
|
||||
'platform_id': {
|
||||
'description': _('Platform numeric identifier'),
|
||||
'example_value': '11',
|
||||
},
|
||||
'beneficiary_id': {
|
||||
'description': _('Beneficiary numeric identifier'),
|
||||
'example_value': '12',
|
||||
},
|
||||
'event_id': {
|
||||
'description': _('Beneficiary numeric identifier'),
|
||||
'example_value': '12',
|
||||
},
|
||||
}
|
||||
),
|
||||
post_json_schema={
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'code_tev': {'type': 'string'},
|
||||
'nom_evt': {'type': 'string'},
|
||||
'lieu_evt': {'type': 'string'},
|
||||
'dt_evt': DATETIME_SCHEMA,
|
||||
'duree_evt': SOFT_INTEGER_SCHEMA,
|
||||
'code_upl': SOFT_INTEGER_SCHEMA,
|
||||
'type_inter': {'type': 'string'},
|
||||
'com_evt': {'type': 'string'},
|
||||
},
|
||||
'unflatten': True,
|
||||
},
|
||||
display_category=_('Platform'),
|
||||
display_order=16,
|
||||
json_schema_response=response_schema(
|
||||
{
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'id': {'type': 'integer'},
|
||||
'text': {'type': 'string'},
|
||||
'datetime': DATETIME_SCHEMA,
|
||||
'duree': {'type': 'integer'},
|
||||
'lieu': {'type': 'string'},
|
||||
'type': STRING_ID_TEXT_SCHEMA,
|
||||
'nom': STRING_SCHEMA,
|
||||
'intervenant': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'id': {'type': 'integer'},
|
||||
'text': {'type': 'string'},
|
||||
'type': STRING_ID_TEXT_SCHEMA,
|
||||
},
|
||||
},
|
||||
'resultat': nullable(STRING_ID_TEXT_SCHEMA),
|
||||
'commentaire': STRING_SCHEMA,
|
||||
},
|
||||
}
|
||||
),
|
||||
)
|
||||
def platform_beneficiaire_evenement_detail(
|
||||
self, request, platform_id, beneficiary_id, event_id, email, post_data=None, ip=None
|
||||
):
|
||||
if request.method == 'POST':
|
||||
return self.put(
|
||||
'platform/%s/beneficiaire/%s/evenement/%s/' % (platform_id, beneficiary_id, event_id),
|
||||
email=email,
|
||||
ip=ip,
|
||||
json=post_data,
|
||||
)
|
||||
elif request.method == 'DELETE':
|
||||
return self.delete(
|
||||
'platform/%s/beneficiaire/%s/evenement/%s/' % (platform_id, beneficiary_id, event_id),
|
||||
email=email,
|
||||
ip=ip,
|
||||
)
|
||||
else:
|
||||
return self.get(
|
||||
'platform/%s/beneficiaire/%s/evenement/%s/' % (platform_id, beneficiary_id, event_id),
|
||||
email=email,
|
||||
ip=ip,
|
||||
)
|
||||
|
||||
platform_beneficiaire_evenement_detail.endpoint_info.methods.insert(0, 'get')
|
||||
platform_beneficiaire_evenement_detail.endpoint_info.methods.insert(0, 'delete')
|
||||
|
||||
|
||||
DEFAULTS = {
|
||||
'beneficiaire_csv_columns': [
|
||||
|
|
|
@ -22,9 +22,11 @@ from urllib.parse import parse_qs
|
|||
|
||||
import httmock
|
||||
import pytest
|
||||
import responses
|
||||
|
||||
import tests.utils
|
||||
from passerelle.contrib.rsa13.models import DEFAULTS, RSA13Resource, dump_csv_columns
|
||||
from passerelle.utils.json import validate_schema
|
||||
|
||||
from .test_manager import login
|
||||
|
||||
|
@ -1396,6 +1398,198 @@ def test_type_evenement(app, rsa13, url):
|
|||
assert response.json == TYPE_EVENEMENT
|
||||
|
||||
|
||||
ENDPOINT_CASES = [
|
||||
{
|
||||
'endpoint': 'platform_beneficiaire_evenement',
|
||||
'path': 'platform/11/beneficiaire/386981/evenement/',
|
||||
'mock_path': '/api/platform/11/beneficiaire/386981/evenement/',
|
||||
'mock_data': [
|
||||
{
|
||||
'id': 2,
|
||||
'text': 'Atelier CV - 26/08/2023',
|
||||
'datetime': '2023-08-26T14:30:00.000+02:00',
|
||||
'duree': 120,
|
||||
'type': 'Atelier',
|
||||
'intervenant': {
|
||||
'id': 1234,
|
||||
'text': 'TARTEMPION Roger',
|
||||
'type': {'id': 'TS', 'text': 'Travailleur social'},
|
||||
},
|
||||
'resultat': None,
|
||||
},
|
||||
{
|
||||
'id': 1,
|
||||
'text': 'Renouvellement de CER - 23/08/2023',
|
||||
'datetime': '2023-08-23T08:30:10.000+02:00',
|
||||
'duree': 95,
|
||||
'type': 'Entretien Diagnostic',
|
||||
'intervenant': {
|
||||
'id': 22662,
|
||||
'text': 'GELLF Bonnie',
|
||||
'type': {'id': 'TS', 'text': 'Travailleur social'},
|
||||
},
|
||||
'resultat': 'Présent',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
'endpoint': 'platform_beneficiaire_evenement',
|
||||
'method': 'post_json',
|
||||
'params': {
|
||||
'code_tev': '1',
|
||||
'nom_evt': 'TEST 20231109',
|
||||
'lieu_evt': 'Aix',
|
||||
'dt_evt': '2023-11-09T11:00:00',
|
||||
'duree_evt': 60,
|
||||
'code_upl': 37261,
|
||||
'type_inter': 'TS',
|
||||
'com_evt': 'Blabla',
|
||||
},
|
||||
'path': 'platform/11/beneficiaire/386981/evenement/',
|
||||
'mock_path': '/api/platform/11/beneficiaire/386981/evenement/',
|
||||
'mock_method': 'post',
|
||||
'mock_data': {'err': 0},
|
||||
},
|
||||
{
|
||||
'endpoint': 'platform_beneficiaire_evenement',
|
||||
'id': 'id-as-string',
|
||||
'method': 'post_json',
|
||||
'params': {
|
||||
'code_tev': '1',
|
||||
'nom_evt': 'TEST 20231109',
|
||||
'lieu_evt': 'Aix',
|
||||
'dt_evt': '2023-11-09T11:00:00',
|
||||
'duree_evt': '60',
|
||||
'code_upl': '37261',
|
||||
'type_inter': 'TS',
|
||||
'com_evt': 'Blabla',
|
||||
},
|
||||
'path': 'platform/11/beneficiaire/386981/evenement/',
|
||||
'mock_path': '/api/platform/11/beneficiaire/386981/evenement/',
|
||||
'mock_method': 'post',
|
||||
'mock_data': {'err': 0},
|
||||
},
|
||||
{
|
||||
'endpoint': 'platform_beneficiaire_evenement_detail',
|
||||
'path': 'platform/11/beneficiaire/386981/evenement/1/',
|
||||
'mock_path': '/api/platform/11/beneficiaire/386981/evenement/1/',
|
||||
'mock_data': {
|
||||
'id': 1,
|
||||
'text': 'Diagnostic 01/01/2023',
|
||||
'datetime': '2023-01-01T14:30:00.000+02:00',
|
||||
'duree': 60,
|
||||
'lieu': '14 Rue de la République, 13001 Marseille',
|
||||
'type': {'id': '3', 'text': 'Entretien Diagnostic'},
|
||||
'nom': 'Diagnostic',
|
||||
'intervenant': {'id': 1, 'text': 'NOM Prénom', 'type': {'id': 'PSY', 'text': 'Psychologue'}},
|
||||
'resultat': {'id': 'PRS', 'text': 'Présent'},
|
||||
'commentaire': 'Blabla',
|
||||
},
|
||||
},
|
||||
{
|
||||
'endpoint': 'platform_beneficiaire_evenement_detail',
|
||||
'path': 'platform/11/beneficiaire/386981/evenement/1/',
|
||||
'method': 'post_json',
|
||||
'params': {
|
||||
'code_tev': '1',
|
||||
'nom_evt': 'TEST 20231109',
|
||||
'lieu_evt': 'Aix',
|
||||
'dt_evt': '2023-11-09T11:00:00',
|
||||
'duree_evt': 60,
|
||||
'code_upl': 37261,
|
||||
'type_inter': 'TS',
|
||||
'com_evt': 'Blabla',
|
||||
},
|
||||
'mock_path': '/api/platform/11/beneficiaire/386981/evenement/1/',
|
||||
'mock_method': 'put',
|
||||
'mock_data': {
|
||||
'id': 1,
|
||||
'text': 'Diagnostic 01/01/2023',
|
||||
'datetime': '2023-01-01T14:30:00.000+02:00',
|
||||
'duree': 60,
|
||||
'lieu': '14 Rue de la République, 13001 Marseille',
|
||||
'type': {'id': '3', 'text': 'Entretien Diagnostic'},
|
||||
'nom': 'Diagnostic',
|
||||
'intervenant': {'id': 1, 'text': 'NOM Prénom', 'type': {'id': 'PSY', 'text': 'Psychologue'}},
|
||||
'resultat': {'id': 'PRS', 'text': 'Présent'},
|
||||
'commentaire': 'Blabla',
|
||||
},
|
||||
},
|
||||
{
|
||||
'endpoint': 'platform_beneficiaire_evenement_detail',
|
||||
'path': 'platform/11/beneficiaire/386981/evenement/1/',
|
||||
'method': 'delete',
|
||||
'mock_path': '/api/platform/11/beneficiaire/386981/evenement/1/',
|
||||
'mock_method': 'delete',
|
||||
'mock_data': {'err': 0},
|
||||
},
|
||||
{
|
||||
'id': 'gone',
|
||||
'endpoint': 'platform_beneficiaire_evenement_detail',
|
||||
'path': 'platform/11/beneficiaire/386981/evenement/1/',
|
||||
'method': 'delete',
|
||||
'response_data': {
|
||||
'err': 1,
|
||||
'err_class': 'passerelle.utils.jsonresponse.APIError',
|
||||
'err_desc': 'gone',
|
||||
'data': {
|
||||
'err': 410,
|
||||
'err_code': 'gone',
|
||||
'metier': "L'évènement n'existe pas",
|
||||
},
|
||||
},
|
||||
'mock_path': '/api/platform/11/beneficiaire/386981/evenement/1/',
|
||||
'mock_method': 'delete',
|
||||
'mock_data': {'err': 410, 'err_code': 'gone', 'metier': "L'évènement n'existe pas"},
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def endpoint_case_ids():
|
||||
for case in ENDPOINT_CASES:
|
||||
case_id = case['endpoint']
|
||||
if method := case.get('method'):
|
||||
case_id += '-' + method
|
||||
if extra_id := case.get('id'):
|
||||
case_id += '-' + extra_id
|
||||
yield case_id
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'case',
|
||||
ENDPOINT_CASES,
|
||||
ids=list(endpoint_case_ids()),
|
||||
)
|
||||
def test_endpoints(app, rsa13, url, case):
|
||||
endpoint = getattr(rsa13, case['endpoint'])
|
||||
method = case.get('method', 'get')
|
||||
api_response_method = case.get('mock_method', method)
|
||||
api_response_data = case['mock_data']
|
||||
if 'err' not in api_response_data:
|
||||
api_response_data = {
|
||||
'err': 0,
|
||||
'data': api_response_data,
|
||||
}
|
||||
params = case.get('params', ())
|
||||
|
||||
with responses.RequestsMock() as rsp:
|
||||
rsp.add(
|
||||
getattr(responses, api_response_method.upper()),
|
||||
'https://rsa-cd13.com' + case['mock_path'],
|
||||
json=api_response_data,
|
||||
)
|
||||
|
||||
response = getattr(app, method)(url + case['path'], params=params)
|
||||
response_data = case.get('response_data', api_response_data)
|
||||
if 'err' not in response_data:
|
||||
response_data = {
|
||||
'err': 0,
|
||||
'data': response_data,
|
||||
}
|
||||
assert response.json == response_data
|
||||
validate_schema(response.json, endpoint.endpoint_info.response_schemas['application/json'])
|
||||
|
||||
|
||||
def test_csv_columns_migration(migration, settings):
|
||||
old_apps = migration.before([('rsa13', '0001_initial')])
|
||||
|
||||
|
|
Loading…
Reference in New Issue