From c44f8f6071a0e4bc1d6b41d68fda5c0c51b79e16 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Mon, 30 Nov 2020 20:40:00 +0100 Subject: [PATCH 2/2] rsa13: add remaining endpoints (#48567) * fondsaide & fondsaide details * affectation & affectation details * convo * emploi --- passerelle/contrib/rsa13/models.py | 366 +++++++++++++++++++++++++++++ tests/test_rsa13.py | 128 ++++++++++ 2 files changed, 494 insertions(+) diff --git a/passerelle/contrib/rsa13/models.py b/passerelle/contrib/rsa13/models.py index 48e532c0..33e985df 100644 --- a/passerelle/contrib/rsa13/models.py +++ b/passerelle/contrib/rsa13/models.py @@ -913,3 +913,369 @@ class RSA13Resource(BaseResource, HTTPResource): email=email, ip=ip, ) + + @endpoint( + name='platform', + pattern=r'^(?P[0-9]{1,10})/' + r'beneficiaire/(?P[0-9]{1,10})/' + r'fondsaide/$', + example_pattern='{platform_id}/beneficiaire/{beneficiary_id}/fondsaide/', + description=_('Get beneficiary help funds'), + perm='can_access', + parameters=parameters( + { + 'platform_id': { + 'description': _('Platform numeric identifier'), + 'example_value': '11', + }, + 'beneficiary_id': { + 'description': _('Beneficiary numeric identifier'), + 'example_value': '12', + }, + } + ), + display_category=_('Platform'), + display_order=11, + json_schema_response=response_schema( + { + 'type': 'array', + 'items': { + 'type': 'object', + 'properties': { + 'id': {'type': 'integer'}, + 'cod_tfi': {'type': 'string'}, + 'lib_tfi': {'type': 'string'}, + 'demande': { + 'type': 'object', + 'properties': { + 'montant': {'type': 'number'}, + 'date': DATE_SCHEMA, + } + }, + 'avis_pi': { + 'type': 'object', + 'properties': { + 'montant': {'type': 'number'}, + 'date': DATE_SCHEMA, + 'avis': {'type': 'string'}, + } + }, + 'avis_sai': { + 'type': 'object', + 'properties': { + 'montant': {'type': 'number'}, + 'date': DATE_SCHEMA, + } + }, + 'clos': OUI_NON_ENUM, + }, + }, + } + ), + ) + def platform_beneficiaire_fondsaide( + self, request, platform_id, beneficiary_id, email, ip=None + ): + return self.get( + 'platform/%s/beneficiaire/%s/fondsaide/' % (platform_id, beneficiary_id), + email=email, + ip=ip, + ) + + @endpoint( + name='platform', + pattern=r'^(?P[0-9]{1,10})/' + r'beneficiaire/(?P[0-9]{1,10})/' + r'fondsaide/(?P[0-9]{1,10})/$', + example_pattern='{platform_id}/beneficiaire/{beneficiary_id}/fondsaide/{fondsaide_id}/', + description=_('Get beneficiary help fund details'), + perm='can_access', + parameters=parameters( + { + 'platform_id': { + 'description': _('Platform numeric identifier'), + 'example_value': '11', + }, + 'beneficiary_id': { + 'description': _('Beneficiary numeric identifier'), + 'example_value': '12', + }, + 'fondsaide_id': { + 'description': _('Help fund numeric identifier'), + 'example_value': '7', + }, + } + ), + display_category=_('Platform'), + display_order=12, + json_schema_response=response_schema( + { + 'type': 'object', + } + ), + ) + def platform_beneficiaire_fondsaide_detail( + self, request, platform_id, beneficiary_id, fondsaide_id, email, ip=None + ): + return self.get( + 'platform/%s/beneficiaire/%s/fondsaide/%s/' % (platform_id, beneficiary_id, fondsaide_id), + email=email, + ip=ip, + ) + + @endpoint( + name='platform', + pattern=r'^(?P[0-9]{1,10})/' + r'beneficiaire/(?P[0-9]{1,10})/' + r'affectation/$', + example_pattern='{platform_id}/beneficiaire/{beneficiary_id}/affectation/', + description=_('Get beneficiary affectations'), + perm='can_access', + parameters=parameters( + { + 'platform_id': { + 'description': _('Platform numeric identifier'), + 'example_value': '11', + }, + 'beneficiary_id': { + 'description': _('Beneficiary numeric identifier'), + 'example_value': '12', + }, + } + ), + display_category=_('Platform'), + display_order=13, + json_schema_response=response_schema( + { + 'type': 'array', + 'items': { + 'type': 'object', + 'properties': { + 'id': {'type': 'integer'}, + 'dispositif': {'type': 'string'}, + 'plateforme': {'type': 'string'}, + 'code_pi': {'type': 'string'}, + 'referent': {'type': 'string'}, + 'date_deb': DATE_SCHEMA, + 'origine': {'type': 'string'}, + }, + }, + } + ), + ) + def platform_beneficiaire_affectation( + self, request, platform_id, beneficiary_id, email, ip=None + ): + return self.get( + 'platform/%s/beneficiaire/%s/affectation/' % (platform_id, beneficiary_id), + email=email, + ip=ip, + ) + + @endpoint( + name='platform', + pattern=r'^(?P[0-9]{1,10})/' + r'beneficiaire/(?P[0-9]{1,10})/' + r'affectation/(?P[0-9]{1,10})/$', + example_pattern='{platform_id}/beneficiaire/{beneficiary_id}/affectation/{affectation_id}/', + description=_('Get beneficiary affectation details'), + perm='can_access', + parameters=parameters( + { + 'platform_id': { + 'description': _('Platform numeric identifier'), + 'example_value': '11', + }, + 'beneficiary_id': { + 'description': _('Beneficiary numeric identifier'), + 'example_value': '12', + }, + 'affectation_id': { + 'description': _('Help fund numeric identifier'), + 'example_value': '7', + }, + } + ), + display_category=_('Platform'), + display_order=14, + json_schema_response=response_schema( + { + 'type': 'object', + 'properties': { + 'id': {'type': 'integer'}, + 'dispositif': {'type': 'string'}, + 'plateforme': {'type': 'string'}, + 'referent': { + 'type': 'object', + 'properties': { + 'nom': {'type': 'string'}, + 'prenom': {'type': 'string'}, + } + }, + 'code_pi': {'type': 'string'}, + 'date_deb': DATE_SCHEMA, + 'origine': {'type': 'string'}, + 'erreur': OUI_NON_ENUM, + 'date_deb': DATE_SCHEMA, + 'origin': {'type': 'string'}, + 'prescripteur': { + 'type': 'object', + 'properties': { + 'type': {'type': 'string'}, + 'dispositif': {'type': 'string'}, + 'plateforme': {'type': 'string'}, + }, + }, + 'rendez-vous': { + 'type': 'object', + 'properties': { + 'date_prise': DATE_SCHEMA, + 'relance': { + 'type': 'object', + 'properties': { + 'date': DATE_SCHEMA, + 'motif': {'type': 'string'}, + 'lib_motif': {'type': 'string'}, + }, + }, + 'date_reelle': DATE_SCHEMA, + 'resultat': {'type': 'string'}, + 'lib_resultat': {'type': 'string'}, + } + }, + 'fin': { + 'type': 'object', + 'properties': { + 'date': DATE_SCHEMA, + 'motif': {'type': 'string'}, + 'lib_motif': {'type': 'string'}, + } + }, + 'commentaire_ref': {'type': 'string'}, + }, + } + ), + ) + def platform_beneficiaire_affectation_detail( + self, request, platform_id, beneficiary_id, affectation_id, email, ip=None + ): + return self.get( + 'platform/%s/beneficiaire/%s/affectation/%s/' % (platform_id, beneficiary_id, affectation_id), + email=email, + ip=ip, + ) + + @endpoint( + name='platform', + pattern=r'^(?P[0-9]{1,10})/' + r'beneficiaire/(?P[0-9]{1,10})/' + r'convo/$', + example_pattern='{platform_id}/beneficiaire/{beneficiary_id}/convo/', + description=_('Get beneficiary convocations'), + perm='can_access', + parameters=parameters( + { + 'platform_id': { + 'description': _('Platform numeric identifier'), + 'example_value': '11', + }, + 'beneficiary_id': { + 'description': _('Beneficiary numeric identifier'), + 'example_value': '12', + }, + } + ), + display_category=_('Platform'), + display_order=15, + json_schema_response=response_schema( + { + 'type': 'array', + 'items': { + "type": "object", + "properties": { + "convos_par_motif": { + "type": "array", + "items": { + "type": "object", + "properties": { + "nombre": {"type": "integer"}, + "motif": {"type": "string"}, + } + }, + }, + "derniere_consequence": { + "type": "object", + "properties": { + "date": DATE_SCHEMA, + "consequence": {"type": "string"}, + } + } + } + }, + } + ), + ) + def platform_beneficiaire_convo( + self, request, platform_id, beneficiary_id, email, ip=None + ): + return self.get( + 'platform/%s/beneficiaire/%s/convo/' % (platform_id, beneficiary_id), + email=email, + ip=ip, + ) + + @endpoint( + name='platform', + pattern=r'^(?P[0-9]{1,10})/' + r'beneficiaire/(?P[0-9]{1,10})/' + r'emploi/$', + example_pattern='{platform_id}/beneficiaire/{beneficiary_id}/emploi/', + description=_('Get beneficiary emploiyments'), + perm='can_access', + parameters=parameters( + { + 'platform_id': { + 'description': _('Platform numeric identifier'), + 'example_value': '11', + }, + 'beneficiary_id': { + 'description': _('Beneficiary numeric identifier'), + 'example_value': '12', + }, + } + ), + display_category=_('Platform'), + display_order=16, + json_schema_response=response_schema( + { + 'type': 'array', + 'items': { + "type": "object", + "properties": { + "id": {"type": "string"}, + "code_axe": {"type": "string"}, + "lib_axe": {"type": "string"}, + "code_rome": {"type": "string"}, + "lib_rome": {"type": "string"}, + "code_categorie": {"type": "string"}, + "lib_categorie": {"type": "string"}, + "lib_secteur": {"type": "string"}, + "lib_niveau": {"type": "string"}, + "lib_modalite": {"type": "string"}, + "date_inscription": DATE_SCHEMA, + "date_sortie": DATE_SCHEMA, + "motif_sortie": {"type": "string"}, + "date_dernier_ent": DATE_SCHEMA, + }, + }, + } + ), + ) + def platform_beneficiaire_emploi( + self, request, platform_id, beneficiary_id, email, ip=None + ): + return self.get( + 'platform/%s/beneficiaire/%s/emploi/' % (platform_id, beneficiary_id), + email=email, + ip=ip, + ) diff --git a/tests/test_rsa13.py b/tests/test_rsa13.py index 25a6ad6a..013085a8 100644 --- a/tests/test_rsa13.py +++ b/tests/test_rsa13.py @@ -473,3 +473,131 @@ def test_platform_beneficiaire_action_detail(app, rsa13, url): 'err': 0, 'data': BENEFICIAIRE_ACTION_DETAIL, } + + +BENEFICIAIRE_FONDSAIDE = [] + + +@mock_response(['/api/platform/11/beneficiaire/386981/fondsaide/', {'err': 0, 'data': BENEFICIAIRE_FONDSAIDE}]) +def test_platform_beneficiaire_fondsaide(app, rsa13, url): + response = app.get(url + 'platform/11/beneficiaire/386981/fondsaide/') + assert response.json == { + 'err': 0, + 'data': BENEFICIAIRE_FONDSAIDE, + } + + +BENEFICIAIRE_FONDSAIDE_DETAIL = {} + + +@mock_response(['/api/platform/11/beneficiaire/386981/fondsaide/1/', {'err': 0, 'data': BENEFICIAIRE_FONDSAIDE_DETAIL}]) +def test_platform_beneficiaire_fondsaide_detail(app, rsa13, url): + response = app.get(url + 'platform/11/beneficiaire/386981/fondsaide/1/') + assert response.json == { + 'err': 0, + 'data': BENEFICIAIRE_FONDSAIDE_DETAIL, + } + + +BENEFICIAIRE_AFFECTATION = [ + { + 'id': 1599703, + 'dispoitif': 'LA', + 'plateforme': 'ADPEI', + 'code_pi': 51, + 'referent': ' ', + 'date_deb': '2019-03-11', + 'origine': 'CER', + }, + { + 'id': 28726, + 'dispoitif': 'MDS', + 'plateforme': 'MDS PRESSENSE', + 'code_pi': 51, + 'referent': ' ', + 'date_deb': '2012-03-22', + 'origine': 'CER', + }, +] + + +@mock_response(['/api/platform/11/beneficiaire/386981/affectation/', {'err': 0, 'data': BENEFICIAIRE_AFFECTATION}]) +def test_platform_beneficiaire_affectation(app, rsa13, url): + response = app.get(url + 'platform/11/beneficiaire/386981/affectation/') + assert response.json == { + 'err': 0, + 'data': BENEFICIAIRE_AFFECTATION, + } + + +BENEFICIAIRE_AFFECTATION_DETAIL = { + 'id': 1599703, + 'dispositif': 'LA', + 'plateforme': 'ADPEI', + 'code_pi': 51, + 'referent': {'nom': None, 'prenom': None}, + 'erreur': 'Non', + 'date_deb': '2019-03-11', + 'origine': 'CER', + 'prescripteur': {'type': 'PI', 'dispositif': None, 'plateforme': None}, + 'rendez-vous': { + 'date_prise': None, + 'relance': {'date': None, 'motif': None, 'lib_motif': None}, + 'date_reelle': None, + 'resultat': None, + 'lib_resultat': None, + }, + 'fin': {'motif': None, 'lib_motif': None, 'date': None}, + 'commentaire_ref': None, +} + + +@mock_response(['/api/platform/11/beneficiaire/386981/affectation/1/', {'err': 0, 'data': BENEFICIAIRE_AFFECTATION_DETAIL}]) +def test_platform_beneficiaire_affectation_detail(app, rsa13, url): + response = app.get(url + 'platform/11/beneficiaire/386981/affectation/1/') + assert response.json == { + 'err': 0, + 'data': BENEFICIAIRE_AFFECTATION_DETAIL, + } + + +BENEFICIAIRE_CONVO = { + 'convos_par_motif': [{'motif': "Absence de Contrat d'Engagement Réciproque", 'nombre': 2}], + 'derniere_consequence': {'date': None, 'consequence': None}, +} + + +@mock_response(['/api/platform/11/beneficiaire/386981/convo/', {'err': 0, 'data': BENEFICIAIRE_CONVO}]) +def test_platform_beneficiaire_convo(app, rsa13, url): + response = app.get(url + 'platform/11/beneficiaire/386981/convo/') + assert response.json == { + 'err': 0, + 'data': BENEFICIAIRE_CONVO, + } + + +BENEFICIAIRE_EMPLOI = { + 'id': '6720658N', + 'date_sortie': None, + 'motif_sortie': None, + 'date_inscription': '2018-05-14', + 'date_dernier_ent': '2019-04-11', + 'code_rome': 'F1606', + 'lib_rome': 'Peintre tapissier / tapissière', + 'lib_modalite': 'RENFORCE', + 'lib_niveau': 'CERTIFICATION DE NIVEAU 5 (CAP, BEP)', + 'lib_secteur': None, + 'code_axe': '06', + 'lib_axe': "LEVEE DES FREINS PERIPHERIQUES A L'EMPLOI", + 'code_categorie': '1', + 'lib_categorie': 'PERSONNE SANS EMPLOI DISPONIBLE DUREE INDETERMINEE PLEIN TPS', +} + + +@mock_response(['/api/platform/11/beneficiaire/386981/emploi/', {'err': 0, 'data': BENEFICIAIRE_EMPLOI}]) +def test_platform_beneficiaire_emploi(app, rsa13, url): + response = app.get(url + 'platform/11/beneficiaire/386981/emploi/') + assert response.json == { + 'err': 0, + 'data': BENEFICIAIRE_EMPLOI, + } -- 2.29.2