0002-toulouse-maelis-add-endpoint-for-invoice-debit-order.patch
passerelle/contrib/toulouse_maelis/invoice_schemas.py | ||
---|---|---|
1 |
# Copyright (C) 2022 Entr'ouvert |
|
2 |
# |
|
3 |
# This program is free software: you can redistribute it and/or modify it |
|
4 |
# under the terms of the GNU Affero General Public License as published |
|
5 |
# by the Free Software Foundation, either version 3 of the License, or |
|
6 |
# (at your option) any later version. |
|
7 |
# |
|
8 |
# This program is distributed in the hope that it will be useful, |
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 |
# GNU Affero General Public License for more details. |
|
12 |
# |
|
13 |
# You should have received a copy of the GNU Affero General Public License |
|
14 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 | ||
16 | ||
17 |
PERSON_BANK_SCHEMA = { |
|
18 |
'$schema': 'http://json-schema.org/draft-04/schema#', |
|
19 |
'title': 'Person bank', |
|
20 |
'description': "Coordonnées du compte à débiter (coordonnées bancaires)", |
|
21 |
'type': 'object', |
|
22 |
'required': ['bankBIC', 'bankIBAN', 'bankRUM', 'dateStart', 'bankAddress', 'lastName', 'firstName'], |
|
23 |
'properties': { |
|
24 |
'bankBIC': { |
|
25 |
'description': 'BIC', |
|
26 |
'type': 'string', |
|
27 |
}, |
|
28 |
'bankIBAN': { |
|
29 |
'description': 'IBAN', |
|
30 |
'type': 'string', |
|
31 |
}, |
|
32 |
'bankRUM': { |
|
33 |
'description': 'RUM', |
|
34 |
'type': 'string', |
|
35 |
}, |
|
36 |
'dateStart': { |
|
37 |
'description': 'date de début', |
|
38 |
'type': 'string', |
|
39 |
'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$', |
|
40 |
}, |
|
41 |
'bankAddress': { |
|
42 |
'description': 'Adresse de la banque', |
|
43 |
'type': 'string', |
|
44 |
}, |
|
45 |
'civility': { |
|
46 |
'description': 'civility', |
|
47 |
'oneOf': [{'type': 'string'}, {'type': 'null'}], |
|
48 |
}, |
|
49 |
'lastName': { |
|
50 |
'description': 'Nom', |
|
51 |
'type': 'string', |
|
52 |
}, |
|
53 |
'firstName': { |
|
54 |
'description': 'Prénom', |
|
55 |
'type': 'string', |
|
56 |
}, |
|
57 |
}, |
|
58 |
} |
|
59 | ||
60 | ||
61 |
ADD_DIRECT_DEBIT_ORDER_SCHEMA = { |
|
62 |
'$schema': 'http://json-schema.org/draft-04/schema#', |
|
63 |
'title': 'Add direct debit order', |
|
64 |
'description': "Ajout d'autorisation de prélèvement", |
|
65 |
'type': 'object', |
|
66 |
'required': ['numPerson', 'bank', 'codeRegie'], |
|
67 |
'properties': { |
|
68 |
'numPerson': { |
|
69 |
'description': 'Numéro MAELIS de la personne', |
|
70 |
'type': 'string', |
|
71 |
}, |
|
72 |
'bank': PERSON_BANK_SCHEMA, |
|
73 |
'codeRegie': { |
|
74 |
'description': 'Code de la régie', |
|
75 |
'type': 'string', |
|
76 |
}, |
|
77 |
}, |
|
78 |
'additionalProperties': False, |
|
79 |
'unflatten': True, |
|
80 |
} |
|
81 | ||
82 | ||
83 |
GET_DIRECT_DEBIT_ORDER_SCHEMA = { |
|
84 |
'$schema': 'http://json-schema.org/draft-04/schema#', |
|
85 |
'title': 'Get direct debit order', |
|
86 |
'description': "Lecture des informations relatives à l'autorisation de prélèvement en cours à la date de référence", |
|
87 |
'type': 'object', |
|
88 |
'required': ['numPerson', 'codeRegie', 'dateRef'], |
|
89 |
'properties': { |
|
90 |
'numPerson': { |
|
91 |
'description': 'Numéro MAELIS de la personne', |
|
92 |
'type': 'string', |
|
93 |
}, |
|
94 |
'codeRegie': { |
|
95 |
'description': 'Code de la régie', |
|
96 |
'type': 'string', |
|
97 |
}, |
|
98 |
'dateRef': { |
|
99 |
'description': 'Date de référence ', |
|
100 |
'type': 'string', |
|
101 |
'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$', |
|
102 |
}, |
|
103 |
}, |
|
104 |
'additionalProperties': False, |
|
105 |
'unflatten': True, |
|
106 |
} |
passerelle/contrib/toulouse_maelis/models.py | ||
---|---|---|
22 | 22 |
from zeep.helpers import serialize_object |
23 | 23 |
from zeep.wsse.username import UsernameToken |
24 | 24 | |
25 | 25 |
from passerelle.base.models import BaseResource, HTTPResource |
26 | 26 |
from passerelle.utils.api import endpoint |
27 | 27 |
from passerelle.utils.conversion import simplify |
28 | 28 |
from passerelle.utils.jsonresponse import APIError |
29 | 29 | |
30 |
from . import family_schemas, schemas |
|
30 |
from . import family_schemas, invoice_schemas, schemas
|
|
31 | 31 | |
32 | 32 | |
33 | 33 |
class UpdateError(Exception): |
34 | 34 |
pass |
35 | 35 | |
36 | 36 | |
37 | 37 |
class ToulouseMaelis(BaseResource, HTTPResource): |
38 | 38 |
# noqa pylint: disable=too-many-public-methods |
... | ... | |
1399 | 1399 |
) |
1400 | 1400 |
def update_child_indicator(self, request, NameID, child_id, post_data): |
1401 | 1401 |
self.get_link(NameID) |
1402 | 1402 |
self.assert_update_indicator_payload_in_referential('ChildIndicator', post_data) |
1403 | 1403 | |
1404 | 1404 |
self.call('Family', 'updatePersonIndicatorList', numPerson=child_id, **post_data) |
1405 | 1405 |
return {'data': 'ok'} |
1406 | 1406 | |
1407 |
@endpoint( |
|
1408 |
display_category='Facture', |
|
1409 |
description="Ajout d'autorisation de prélèvement", |
|
1410 |
name='add-direct-debit-order', |
|
1411 |
perm='can_access', |
|
1412 |
parameters={'NameID': {'description': 'Publik NameID'}}, |
|
1413 |
post={ |
|
1414 |
'request_body': {'schema': {'application/json': invoice_schemas.ADD_DIRECT_DEBIT_ORDER_SCHEMA}} |
|
1415 |
}, |
|
1416 |
) |
|
1417 |
def add_direct_debit_order(self, request, NameID, post_data): |
|
1418 |
family_id = self.get_link(NameID).family_id |
|
1419 |
self.call('Invoice', 'addDirectDebitOrder', dossierNumber=family_id, **post_data) |
|
1420 |
return {'data': 'ok'} |
|
1421 | ||
1422 |
@endpoint( |
|
1423 |
display_category='Facture', |
|
1424 |
description="Lecture des informations relatives à l'autorisation de prélèvement en cours à la date de référence", |
|
1425 |
name='get-direct-debit-order', |
|
1426 |
perm='can_access', |
|
1427 |
parameters={'NameID': {'description': 'Publik NameID'}}, |
|
1428 |
post={ |
|
1429 |
'request_body': {'schema': {'application/json': invoice_schemas.GET_DIRECT_DEBIT_ORDER_SCHEMA}} |
|
1430 |
}, |
|
1431 |
) |
|
1432 |
def get_direct_debit_order(self, request, NameID, post_data): |
|
1433 |
family_id = self.get_link(NameID).family_id |
|
1434 | ||
1435 |
response = self.call('Invoice', 'getDirectDebitOrder', dossierNumber=family_id, **post_data) |
|
1436 |
data = serialize_object(response) |
|
1437 |
return {'data': data} |
|
1438 | ||
1407 | 1439 | |
1408 | 1440 |
class Link(models.Model): |
1409 | 1441 |
resource = models.ForeignKey(ToulouseMaelis, on_delete=models.CASCADE) |
1410 | 1442 |
name_id = models.CharField(blank=False, max_length=256) |
1411 | 1443 |
family_id = models.CharField(blank=False, max_length=128) |
1412 | 1444 |
created = models.DateTimeField(auto_now_add=True) |
1413 | 1445 |
updated = models.DateTimeField(auto_now=True) |
1414 | 1446 |
tests/data/toulouse_maelis/R_add_direct_debit_order.xml | ||
---|---|---|
1 |
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> |
|
2 |
<soap:Body> |
|
3 |
<ns2:addDirectDebitOrderResponse xmlns:ns2="ws.maelis.sigec.com"/> |
|
4 |
</soap:Body> |
|
5 |
</soap:Envelope> |
tests/data/toulouse_maelis/R_direct_debit_order_soap_error.xml | ||
---|---|---|
1 |
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> |
|
2 |
<soap:Body> |
|
3 |
<soap:Fault> |
|
4 |
<faultcode>soap:Server</faultcode> |
|
5 |
<faultstring>E520 : La REGIE CS [{0}] n''existe pas dans la base Maelis</faultstring> |
|
6 |
<detail> |
|
7 |
<ns1:MaelisAccountException xmlns:ns1="ws.maelis.sigec.com"> |
|
8 |
<message xmlns:ns2="ws.maelis.sigec.com">E520 : La REGIE CS [{0}] n''existe pas dans la base Maelis</message> |
|
9 |
</ns1:MaelisAccountException> |
|
10 |
</detail> |
|
11 |
</soap:Fault> |
|
12 |
</soap:Body> |
|
13 |
</soap:Envelope> |
tests/data/toulouse_maelis/R_get_direct_debit_order.xml | ||
---|---|---|
1 |
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> |
|
2 |
<soap:Body> |
|
3 |
<ns2:getDirectDebitOrderResponse xmlns:ns2="ws.maelis.sigec.com"> |
|
4 |
<return> |
|
5 |
<bankBIC>BDFEFR2T</bankBIC> |
|
6 |
<bankIBAN>FR7630001007941234567890185</bankIBAN> |
|
7 |
<bankRUM>xxx</bankRUM> |
|
8 |
<dateStart>2023-01-01T00:00:00+01:00</dateStart> |
|
9 |
<bankAddress>75049 PARIS cedex 01</bankAddress> |
|
10 |
<civility>x</civility> |
|
11 |
<lastName>Ewing</lastName> |
|
12 |
<firstName>John Ross</firstName> |
|
13 |
</return> |
|
14 |
</ns2:getDirectDebitOrderResponse> |
|
15 |
</soap:Body> |
|
16 |
</soap:Envelope> |
tests/test_toulouse_maelis.py | ||
---|---|---|
3026 | 3026 | |
3027 | 3027 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
3028 | 3028 |
resp = app.post_json(url + '?NameID=local&child_id=613880', params=params) |
3029 | 3029 |
assert resp.json['err'] == 'wrong-key' |
3030 | 3030 |
assert ( |
3031 | 3031 |
resp.json['err_desc'] |
3032 | 3032 |
== "indicatorList/0/code key value 'plop' do not belong to 'ChildIndicator' required referential" |
3033 | 3033 |
) |
3034 | ||
3035 | ||
3036 |
def test_add_direct_debit_order(invoice_service, con, app): |
|
3037 |
def request_check(request): |
|
3038 |
assert request.dossierNumber == 1312 |
|
3039 | ||
3040 |
invoice_service.add_soap_response( |
|
3041 |
'addDirectDebitOrder', get_xml_file('R_add_direct_debit_order.xml'), request_check=request_check |
|
3042 |
) |
|
3043 |
url = get_endpoint('add-direct-debit-order') |
|
3044 |
params = { |
|
3045 |
'numPerson': '613878', |
|
3046 |
'codeRegie': '22', |
|
3047 |
'bank/bankBIC': 'BDFEFR2T', |
|
3048 |
'bank/bankIBAN': 'FR7630001007941234567890185', |
|
3049 |
'bank/bankRUM': 'xxx', |
|
3050 |
'bank/dateStart': '2023-01-01', |
|
3051 |
'bank/bankAddress': '75049 PARIS cedex 01', |
|
3052 |
'bank/civility': 'x', |
|
3053 |
'bank/lastName': 'Ewing', |
|
3054 |
'bank/firstName': 'John Ross', |
|
3055 |
} |
|
3056 | ||
3057 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
3058 |
resp = app.post_json(url + '?NameID=local', params=params) |
|
3059 |
assert resp.json['err'] == 0 |
|
3060 |
assert resp.json['data'] == 'ok' |
|
3061 | ||
3062 | ||
3063 |
def test_add_direct_debit_order_not_linked_error(con, app): |
|
3064 |
url = get_endpoint('add-direct-debit-order') |
|
3065 |
params = { |
|
3066 |
'numPerson': '613878', |
|
3067 |
'codeRegie': '22', |
|
3068 |
'bank/bankBIC': 'BDFEFR2T', |
|
3069 |
'bank/bankIBAN': 'FR7630001007941234567890185', |
|
3070 |
'bank/bankRUM': 'xxx', |
|
3071 |
'bank/dateStart': '2023-01-01', |
|
3072 |
'bank/bankAddress': '75049 PARIS cedex 01', |
|
3073 |
'bank/civility': 'x', |
|
3074 |
'bank/lastName': 'Ewing', |
|
3075 |
'bank/firstName': 'John Ross', |
|
3076 |
} |
|
3077 | ||
3078 |
resp = app.post_json(url + '?NameID=local', params=params) |
|
3079 |
assert resp.json['err'] == 'not-linked' |
|
3080 |
assert resp.json['err_desc'] == 'User not linked to family' |
|
3081 | ||
3082 | ||
3083 |
def test_add_direct_debit_order_soap_error(invoice_service, con, app): |
|
3084 |
invoice_service.add_soap_response( |
|
3085 |
'addDirectDebitOrder', get_xml_file('R_direct_debit_order_soap_error.xml'), status=500 |
|
3086 |
) |
|
3087 | ||
3088 |
url = get_endpoint('add-direct-debit-order') |
|
3089 |
params = { |
|
3090 |
'numPerson': '613878', |
|
3091 |
'codeRegie': '12345', |
|
3092 |
'bank/bankBIC': 'BDFEFR2T', |
|
3093 |
'bank/bankIBAN': 'FR7630001007941234567890185', |
|
3094 |
'bank/bankRUM': 'xxx', |
|
3095 |
'bank/dateStart': '2023-01-01', |
|
3096 |
'bank/bankAddress': '75049 PARIS cedex 01', |
|
3097 |
'bank/civility': 'x', |
|
3098 |
'bank/lastName': 'Ewing', |
|
3099 |
'bank/firstName': 'John Ross', |
|
3100 |
} |
|
3101 | ||
3102 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
3103 |
resp = app.post_json(url + '?NameID=local', params=params) |
|
3104 |
assert resp.json['err'] == 'Invoice-addDirectDebitOrder-soap:Server' |
|
3105 |
assert resp.json['err_desc'] == "E520 : La REGIE CS [{0}] n''existe pas dans la base Maelis" |
|
3106 | ||
3107 | ||
3108 |
def test_get_direct_debit_order(invoice_service, con, app): |
|
3109 |
def request_check(request): |
|
3110 |
assert request.dossierNumber == 1312 |
|
3111 | ||
3112 |
invoice_service.add_soap_response( |
|
3113 |
'getDirectDebitOrder', get_xml_file('R_get_direct_debit_order.xml'), request_check=request_check |
|
3114 |
) |
|
3115 |
url = get_endpoint('get-direct-debit-order') |
|
3116 |
params = { |
|
3117 |
'numPerson': '613878', |
|
3118 |
'codeRegie': '22', |
|
3119 |
'dateRef': '2023-01-01', |
|
3120 |
} |
|
3121 | ||
3122 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
3123 |
resp = app.post_json(url + '?NameID=local', params=params) |
|
3124 |
assert resp.json['err'] == 0 |
|
3125 |
assert resp.json['data'] == { |
|
3126 |
'bankBIC': 'BDFEFR2T', |
|
3127 |
'bankIBAN': 'FR7630001007941234567890185', |
|
3128 |
'bankRUM': 'xxx', |
|
3129 |
'dateStart': '2023-01-01T00:00:00+01:00', |
|
3130 |
'bankAddress': '75049 PARIS cedex 01', |
|
3131 |
'civility': 'x', |
|
3132 |
'lastName': 'Ewing', |
|
3133 |
'firstName': 'John Ross', |
|
3134 |
} |
|
3135 | ||
3136 | ||
3137 |
def test_get_direct_debit_order_not_linked_error(con, app): |
|
3138 |
url = get_endpoint('get-direct-debit-order') |
|
3139 |
params = { |
|
3140 |
'numPerson': '613878', |
|
3141 |
'codeRegie': '22', |
|
3142 |
'dateRef': '2023-01-01', |
|
3143 |
} |
|
3144 | ||
3145 |
resp = app.post_json(url + '?NameID=local', params=params) |
|
3146 |
assert resp.json['err'] == 'not-linked' |
|
3147 |
assert resp.json['err_desc'] == 'User not linked to family' |
|
3148 | ||
3149 | ||
3150 |
def test_get_direct_debit_order_soap_error(invoice_service, con, app): |
|
3151 |
invoice_service.add_soap_response( |
|
3152 |
'getDirectDebitOrder', get_xml_file('R_direct_debit_order_soap_error.xml'), status=500 |
|
3153 |
) |
|
3154 |
url = get_endpoint('get-direct-debit-order') |
|
3155 |
params = { |
|
3156 |
'numPerson': '613878', |
|
3157 |
'codeRegie': '12345', |
|
3158 |
'dateRef': '2023-01-01', |
|
3159 |
} |
|
3160 | ||
3161 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
3162 |
resp = app.post_json(url + '?NameID=local', params=params) |
|
3163 |
assert resp.json['err'] == 'Invoice-getDirectDebitOrder-soap:Server' |
|
3164 |
assert resp.json['err_desc'] == "E520 : La REGIE CS [{0}] n''existe pas dans la base Maelis" |
|
3034 |
- |