Projet

Général

Profil

0002-rsa13-add-remaining-endpoints-48567.patch

Benjamin Dauvergne, 30 novembre 2020 20:41

Télécharger (18,9 ko)

Voir les différences:

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(+)
passerelle/contrib/rsa13/models.py
913 913
            email=email,
914 914
            ip=ip,
915 915
        )
916

  
917
    @endpoint(
918
        name='platform',
919
        pattern=r'^(?P<platform_id>[0-9]{1,10})/'
920
        r'beneficiaire/(?P<beneficiary_id>[0-9]{1,10})/'
921
        r'fondsaide/$',
922
        example_pattern='{platform_id}/beneficiaire/{beneficiary_id}/fondsaide/',
923
        description=_('Get beneficiary help funds'),
924
        perm='can_access',
925
        parameters=parameters(
926
            {
927
                'platform_id': {
928
                    'description': _('Platform numeric identifier'),
929
                    'example_value': '11',
930
                },
931
                'beneficiary_id': {
932
                    'description': _('Beneficiary numeric identifier'),
933
                    'example_value': '12',
934
                },
935
            }
936
        ),
937
        display_category=_('Platform'),
938
        display_order=11,
939
        json_schema_response=response_schema(
940
            {
941
                'type': 'array',
942
                'items': {
943
                    'type': 'object',
944
                    'properties': {
945
                        'id': {'type': 'integer'},
946
                        'cod_tfi': {'type': 'string'},
947
                        'lib_tfi': {'type': 'string'},
948
                        'demande': {
949
                            'type': 'object',
950
                            'properties': {
951
                                'montant': {'type': 'number'},
952
                                'date': DATE_SCHEMA,
953
                            }
954
                        },
955
                        'avis_pi': {
956
                            'type': 'object',
957
                            'properties': {
958
                                'montant': {'type': 'number'},
959
                                'date': DATE_SCHEMA,
960
                                'avis': {'type': 'string'},
961
                            }
962
                        },
963
                        'avis_sai': {
964
                            'type': 'object',
965
                            'properties': {
966
                                'montant': {'type': 'number'},
967
                                'date': DATE_SCHEMA,
968
                            }
969
                        },
970
                        'clos': OUI_NON_ENUM,
971
                    },
972
                },
973
            }
974
        ),
975
    )
976
    def platform_beneficiaire_fondsaide(
977
        self, request, platform_id, beneficiary_id, email, ip=None
978
    ):
979
        return self.get(
980
            'platform/%s/beneficiaire/%s/fondsaide/' % (platform_id, beneficiary_id),
981
            email=email,
982
            ip=ip,
983
        )
984

  
985
    @endpoint(
986
        name='platform',
987
        pattern=r'^(?P<platform_id>[0-9]{1,10})/'
988
        r'beneficiaire/(?P<beneficiary_id>[0-9]{1,10})/'
989
        r'fondsaide/(?P<fondsaide_id>[0-9]{1,10})/$',
990
        example_pattern='{platform_id}/beneficiaire/{beneficiary_id}/fondsaide/{fondsaide_id}/',
991
        description=_('Get beneficiary help fund details'),
992
        perm='can_access',
993
        parameters=parameters(
994
            {
995
                'platform_id': {
996
                    'description': _('Platform numeric identifier'),
997
                    'example_value': '11',
998
                },
999
                'beneficiary_id': {
1000
                    'description': _('Beneficiary numeric identifier'),
1001
                    'example_value': '12',
1002
                },
1003
                'fondsaide_id': {
1004
                    'description': _('Help fund numeric identifier'),
1005
                    'example_value': '7',
1006
                },
1007
            }
1008
        ),
1009
        display_category=_('Platform'),
1010
        display_order=12,
1011
        json_schema_response=response_schema(
1012
            {
1013
                'type': 'object',
1014
            }
1015
        ),
1016
    )
1017
    def platform_beneficiaire_fondsaide_detail(
1018
        self, request, platform_id, beneficiary_id, fondsaide_id, email, ip=None
1019
    ):
1020
        return self.get(
1021
            'platform/%s/beneficiaire/%s/fondsaide/%s/' % (platform_id, beneficiary_id, fondsaide_id),
1022
            email=email,
1023
            ip=ip,
1024
        )
1025

  
1026
    @endpoint(
1027
        name='platform',
1028
        pattern=r'^(?P<platform_id>[0-9]{1,10})/'
1029
        r'beneficiaire/(?P<beneficiary_id>[0-9]{1,10})/'
1030
        r'affectation/$',
1031
        example_pattern='{platform_id}/beneficiaire/{beneficiary_id}/affectation/',
1032
        description=_('Get beneficiary affectations'),
1033
        perm='can_access',
1034
        parameters=parameters(
1035
            {
1036
                'platform_id': {
1037
                    'description': _('Platform numeric identifier'),
1038
                    'example_value': '11',
1039
                },
1040
                'beneficiary_id': {
1041
                    'description': _('Beneficiary numeric identifier'),
1042
                    'example_value': '12',
1043
                },
1044
            }
1045
        ),
1046
        display_category=_('Platform'),
1047
        display_order=13,
1048
        json_schema_response=response_schema(
1049
            {
1050
                'type': 'array',
1051
                'items': {
1052
                    'type': 'object',
1053
                    'properties': {
1054
                        'id': {'type': 'integer'},
1055
                        'dispositif': {'type': 'string'},
1056
                        'plateforme': {'type': 'string'},
1057
                        'code_pi': {'type': 'string'},
1058
                        'referent': {'type': 'string'},
1059
                        'date_deb': DATE_SCHEMA,
1060
                        'origine': {'type': 'string'},
1061
                    },
1062
                },
1063
            }
1064
        ),
1065
    )
1066
    def platform_beneficiaire_affectation(
1067
        self, request, platform_id, beneficiary_id, email, ip=None
1068
    ):
1069
        return self.get(
1070
            'platform/%s/beneficiaire/%s/affectation/' % (platform_id, beneficiary_id),
1071
            email=email,
1072
            ip=ip,
1073
        )
1074

  
1075
    @endpoint(
1076
        name='platform',
1077
        pattern=r'^(?P<platform_id>[0-9]{1,10})/'
1078
        r'beneficiaire/(?P<beneficiary_id>[0-9]{1,10})/'
1079
        r'affectation/(?P<affectation_id>[0-9]{1,10})/$',
1080
        example_pattern='{platform_id}/beneficiaire/{beneficiary_id}/affectation/{affectation_id}/',
1081
        description=_('Get beneficiary affectation details'),
1082
        perm='can_access',
1083
        parameters=parameters(
1084
            {
1085
                'platform_id': {
1086
                    'description': _('Platform numeric identifier'),
1087
                    'example_value': '11',
1088
                },
1089
                'beneficiary_id': {
1090
                    'description': _('Beneficiary numeric identifier'),
1091
                    'example_value': '12',
1092
                },
1093
                'affectation_id': {
1094
                    'description': _('Help fund numeric identifier'),
1095
                    'example_value': '7',
1096
                },
1097
            }
1098
        ),
1099
        display_category=_('Platform'),
1100
        display_order=14,
1101
        json_schema_response=response_schema(
1102
            {
1103
                'type': 'object',
1104
                'properties': {
1105
                    'id': {'type': 'integer'},
1106
                    'dispositif': {'type': 'string'},
1107
                    'plateforme': {'type': 'string'},
1108
                    'referent': {
1109
                        'type': 'object',
1110
                        'properties': {
1111
                            'nom': {'type': 'string'},
1112
                            'prenom': {'type': 'string'},
1113
                        }
1114
                    },
1115
                    'code_pi': {'type': 'string'},
1116
                    'date_deb': DATE_SCHEMA,
1117
                    'origine': {'type': 'string'},
1118
                    'erreur': OUI_NON_ENUM,
1119
                    'date_deb': DATE_SCHEMA,
1120
                    'origin': {'type': 'string'},
1121
                    'prescripteur': {
1122
                        'type': 'object',
1123
                        'properties': {
1124
                            'type': {'type': 'string'},
1125
                            'dispositif': {'type': 'string'},
1126
                            'plateforme': {'type': 'string'},
1127
                        },
1128
                    },
1129
                    'rendez-vous': {
1130
                        'type': 'object',
1131
                        'properties': {
1132
                            'date_prise': DATE_SCHEMA,
1133
                            'relance': {
1134
                                'type': 'object',
1135
                                'properties': {
1136
                                    'date': DATE_SCHEMA,
1137
                                    'motif': {'type': 'string'},
1138
                                    'lib_motif': {'type': 'string'},
1139
                                },
1140
                            },
1141
                            'date_reelle': DATE_SCHEMA,
1142
                            'resultat': {'type': 'string'},
1143
                            'lib_resultat': {'type': 'string'},
1144
                        }
1145
                    },
1146
                    'fin': {
1147
                        'type': 'object',
1148
                        'properties': {
1149
                            'date': DATE_SCHEMA,
1150
                            'motif': {'type': 'string'},
1151
                            'lib_motif': {'type': 'string'},
1152
                        }
1153
                    },
1154
                    'commentaire_ref': {'type': 'string'},
1155
                },
1156
            }
1157
        ),
1158
    )
1159
    def platform_beneficiaire_affectation_detail(
1160
        self, request, platform_id, beneficiary_id, affectation_id, email, ip=None
1161
    ):
1162
        return self.get(
1163
            'platform/%s/beneficiaire/%s/affectation/%s/' % (platform_id, beneficiary_id, affectation_id),
1164
            email=email,
1165
            ip=ip,
1166
        )
1167

  
1168
    @endpoint(
1169
        name='platform',
1170
        pattern=r'^(?P<platform_id>[0-9]{1,10})/'
1171
        r'beneficiaire/(?P<beneficiary_id>[0-9]{1,10})/'
1172
        r'convo/$',
1173
        example_pattern='{platform_id}/beneficiaire/{beneficiary_id}/convo/',
1174
        description=_('Get beneficiary convocations'),
1175
        perm='can_access',
1176
        parameters=parameters(
1177
            {
1178
                'platform_id': {
1179
                    'description': _('Platform numeric identifier'),
1180
                    'example_value': '11',
1181
                },
1182
                'beneficiary_id': {
1183
                    'description': _('Beneficiary numeric identifier'),
1184
                    'example_value': '12',
1185
                },
1186
            }
1187
        ),
1188
        display_category=_('Platform'),
1189
        display_order=15,
1190
        json_schema_response=response_schema(
1191
            {
1192
                'type': 'array',
1193
                'items': {
1194
                    "type": "object",
1195
                    "properties": {
1196
                        "convos_par_motif": {
1197
                            "type": "array",
1198
                            "items": {
1199
                                "type": "object",
1200
                                "properties": {
1201
                                    "nombre": {"type": "integer"},
1202
                                    "motif": {"type": "string"},
1203
                                }
1204
                            },
1205
                        },
1206
                        "derniere_consequence": {
1207
                            "type": "object",
1208
                            "properties": {
1209
                                "date": DATE_SCHEMA,
1210
                                "consequence": {"type": "string"},
1211
                            }
1212
                        }
1213
                    }
1214
                },
1215
            }
1216
        ),
1217
    )
1218
    def platform_beneficiaire_convo(
1219
        self, request, platform_id, beneficiary_id, email, ip=None
1220
    ):
1221
        return self.get(
1222
            'platform/%s/beneficiaire/%s/convo/' % (platform_id, beneficiary_id),
1223
            email=email,
1224
            ip=ip,
1225
        )
1226

  
1227
    @endpoint(
1228
        name='platform',
1229
        pattern=r'^(?P<platform_id>[0-9]{1,10})/'
1230
        r'beneficiaire/(?P<beneficiary_id>[0-9]{1,10})/'
1231
        r'emploi/$',
1232
        example_pattern='{platform_id}/beneficiaire/{beneficiary_id}/emploi/',
1233
        description=_('Get beneficiary emploiyments'),
1234
        perm='can_access',
1235
        parameters=parameters(
1236
            {
1237
                'platform_id': {
1238
                    'description': _('Platform numeric identifier'),
1239
                    'example_value': '11',
1240
                },
1241
                'beneficiary_id': {
1242
                    'description': _('Beneficiary numeric identifier'),
1243
                    'example_value': '12',
1244
                },
1245
            }
1246
        ),
1247
        display_category=_('Platform'),
1248
        display_order=16,
1249
        json_schema_response=response_schema(
1250
            {
1251
                'type': 'array',
1252
                'items': {
1253
                    "type": "object",
1254
                    "properties": {
1255
                        "id": {"type": "string"},
1256
                        "code_axe": {"type": "string"},
1257
                        "lib_axe": {"type": "string"},
1258
                        "code_rome": {"type": "string"},
1259
                        "lib_rome": {"type": "string"},
1260
                        "code_categorie": {"type": "string"},
1261
                        "lib_categorie": {"type": "string"},
1262
                        "lib_secteur": {"type": "string"},
1263
                        "lib_niveau": {"type": "string"},
1264
                        "lib_modalite": {"type": "string"},
1265
                        "date_inscription": DATE_SCHEMA,
1266
                        "date_sortie": DATE_SCHEMA,
1267
                        "motif_sortie": {"type": "string"},
1268
                        "date_dernier_ent": DATE_SCHEMA,
1269
                    },
1270
                },
1271
            }
1272
        ),
1273
    )
1274
    def platform_beneficiaire_emploi(
1275
        self, request, platform_id, beneficiary_id, email, ip=None
1276
    ):
1277
        return self.get(
1278
            'platform/%s/beneficiaire/%s/emploi/' % (platform_id, beneficiary_id),
1279
            email=email,
1280
            ip=ip,
1281
        )
tests/test_rsa13.py
473 473
        'err': 0,
474 474
        'data': BENEFICIAIRE_ACTION_DETAIL,
475 475
    }
476

  
477

  
478
BENEFICIAIRE_FONDSAIDE = []
479

  
480

  
481
@mock_response(['/api/platform/11/beneficiaire/386981/fondsaide/', {'err': 0, 'data': BENEFICIAIRE_FONDSAIDE}])
482
def test_platform_beneficiaire_fondsaide(app, rsa13, url):
483
    response = app.get(url + 'platform/11/beneficiaire/386981/fondsaide/')
484
    assert response.json == {
485
        'err': 0,
486
        'data': BENEFICIAIRE_FONDSAIDE,
487
    }
488

  
489

  
490
BENEFICIAIRE_FONDSAIDE_DETAIL = {}
491

  
492

  
493
@mock_response(['/api/platform/11/beneficiaire/386981/fondsaide/1/', {'err': 0, 'data': BENEFICIAIRE_FONDSAIDE_DETAIL}])
494
def test_platform_beneficiaire_fondsaide_detail(app, rsa13, url):
495
    response = app.get(url + 'platform/11/beneficiaire/386981/fondsaide/1/')
496
    assert response.json == {
497
        'err': 0,
498
        'data': BENEFICIAIRE_FONDSAIDE_DETAIL,
499
    }
500

  
501

  
502
BENEFICIAIRE_AFFECTATION = [
503
    {
504
        'id': 1599703,
505
        'dispoitif': 'LA',
506
        'plateforme': 'ADPEI',
507
        'code_pi': 51,
508
        'referent': ' ',
509
        'date_deb': '2019-03-11',
510
        'origine': 'CER',
511
    },
512
    {
513
        'id': 28726,
514
        'dispoitif': 'MDS',
515
        'plateforme': 'MDS PRESSENSE',
516
        'code_pi': 51,
517
        'referent': ' ',
518
        'date_deb': '2012-03-22',
519
        'origine': 'CER',
520
    },
521
]
522

  
523

  
524
@mock_response(['/api/platform/11/beneficiaire/386981/affectation/', {'err': 0, 'data': BENEFICIAIRE_AFFECTATION}])
525
def test_platform_beneficiaire_affectation(app, rsa13, url):
526
    response = app.get(url + 'platform/11/beneficiaire/386981/affectation/')
527
    assert response.json == {
528
        'err': 0,
529
        'data': BENEFICIAIRE_AFFECTATION,
530
    }
531

  
532

  
533
BENEFICIAIRE_AFFECTATION_DETAIL = {
534
    'id': 1599703,
535
    'dispositif': 'LA',
536
    'plateforme': 'ADPEI',
537
    'code_pi': 51,
538
    'referent': {'nom': None, 'prenom': None},
539
    'erreur': 'Non',
540
    'date_deb': '2019-03-11',
541
    'origine': 'CER',
542
    'prescripteur': {'type': 'PI', 'dispositif': None, 'plateforme': None},
543
    'rendez-vous': {
544
        'date_prise': None,
545
        'relance': {'date': None, 'motif': None, 'lib_motif': None},
546
        'date_reelle': None,
547
        'resultat': None,
548
        'lib_resultat': None,
549
    },
550
    'fin': {'motif': None, 'lib_motif': None, 'date': None},
551
    'commentaire_ref': None,
552
}
553

  
554

  
555
@mock_response(['/api/platform/11/beneficiaire/386981/affectation/1/', {'err': 0, 'data': BENEFICIAIRE_AFFECTATION_DETAIL}])
556
def test_platform_beneficiaire_affectation_detail(app, rsa13, url):
557
    response = app.get(url + 'platform/11/beneficiaire/386981/affectation/1/')
558
    assert response.json == {
559
        'err': 0,
560
        'data': BENEFICIAIRE_AFFECTATION_DETAIL,
561
    }
562

  
563

  
564
BENEFICIAIRE_CONVO = {
565
    'convos_par_motif': [{'motif': "Absence de Contrat d'Engagement Réciproque", 'nombre': 2}],
566
    'derniere_consequence': {'date': None, 'consequence': None},
567
}
568

  
569

  
570
@mock_response(['/api/platform/11/beneficiaire/386981/convo/', {'err': 0, 'data': BENEFICIAIRE_CONVO}])
571
def test_platform_beneficiaire_convo(app, rsa13, url):
572
    response = app.get(url + 'platform/11/beneficiaire/386981/convo/')
573
    assert response.json == {
574
        'err': 0,
575
        'data': BENEFICIAIRE_CONVO,
576
    }
577

  
578

  
579
BENEFICIAIRE_EMPLOI = {
580
    'id': '6720658N',
581
    'date_sortie': None,
582
    'motif_sortie': None,
583
    'date_inscription': '2018-05-14',
584
    'date_dernier_ent': '2019-04-11',
585
    'code_rome': 'F1606',
586
    'lib_rome': 'Peintre tapissier / tapissière',
587
    'lib_modalite': 'RENFORCE',
588
    'lib_niveau': 'CERTIFICATION DE NIVEAU 5 (CAP, BEP)',
589
    'lib_secteur': None,
590
    'code_axe': '06',
591
    'lib_axe': "LEVEE DES FREINS PERIPHERIQUES A L'EMPLOI",
592
    'code_categorie': '1',
593
    'lib_categorie': 'PERSONNE SANS EMPLOI DISPONIBLE DUREE INDETERMINEE PLEIN TPS',
594
}
595

  
596

  
597
@mock_response(['/api/platform/11/beneficiaire/386981/emploi/', {'err': 0, 'data': BENEFICIAIRE_EMPLOI}])
598
def test_platform_beneficiaire_emploi(app, rsa13, url):
599
    response = app.get(url + 'platform/11/beneficiaire/386981/emploi/')
600
    assert response.json == {
601
        'err': 0,
602
        'data': BENEFICIAIRE_EMPLOI,
603
    }
476
-