0002-toulouse-maelis-add-RL2-webservices-68788.patch
passerelle/contrib/toulouse_maelis/models.py | ||
---|---|---|
503 | 503 |
'dossierNumber': family_id, |
504 | 504 |
'categorie': family['category'], |
505 | 505 |
'situation': family['situation'], |
506 | 506 |
'rl1': rl1, |
507 | 507 |
} |
508 | 508 |
self.call('Family', 'updateFamily', **payload) |
509 | 509 |
return {'data': 'ok'} |
510 | 510 | |
511 |
@endpoint( |
|
512 |
display_category='Famille', |
|
513 |
description='Création du RL2', |
|
514 |
name='create-rl2', |
|
515 |
perm='can_access', |
|
516 |
parameters={'NameID': {'description': 'Publik NameID'}}, |
|
517 |
post={'request_body': {'schema': {'application/json': schemas.CREATE_RL2_SCHEMA}}}, |
|
518 |
) |
|
519 |
def create_rl2(self, request, NameID, post_data): |
|
520 |
family_id = self.get_link(NameID).family_id |
|
521 |
family = self.get_family_raw(family_id) |
|
522 |
if family['RL2']: |
|
523 |
raise APIError('RL2 already defined on family', err_code='already-rl2') |
|
524 | ||
525 |
payload = { |
|
526 |
'dossierNumber': family_id, |
|
527 |
'categorie': family['category'], |
|
528 |
'situation': family['situation'], |
|
529 |
'rl2': post_data, |
|
530 |
} |
|
531 |
self.call('Family', 'updateFamily', **payload) |
|
532 |
return {'data': 'ok'} |
|
533 | ||
534 |
@endpoint( |
|
535 |
display_category='Famille', |
|
536 |
description='Modification du RL2', |
|
537 |
name='update-rl2', |
|
538 |
perm='can_access', |
|
539 |
parameters={'NameID': {'description': 'Publik NameID'}}, |
|
540 |
post={'request_body': {'schema': {'application/json': schemas.UPDATE_RL2_SCHEMA}}}, |
|
541 |
) |
|
542 |
def update_rl2(self, request, NameID, post_data): |
|
543 |
family_id = self.get_link(NameID).family_id |
|
544 |
family = self.get_family_raw(family_id) |
|
545 |
if not family['RL2']: |
|
546 |
raise APIError('No RL2 to update on family', err_code='no-rl2') |
|
547 |
self.replace_null_values(post_data) |
|
548 | ||
549 |
rl2 = post_data |
|
550 |
rl2['num'] = family['RL2']['num'] |
|
551 |
rl2['adresse'] = family['RL2']['adresse'] |
|
552 |
payload = { |
|
553 |
'dossierNumber': family_id, |
|
554 |
'categorie': family['category'], |
|
555 |
'situation': family['situation'], |
|
556 |
'rl2': rl2, |
|
557 |
} |
|
558 |
self.call('Family', 'updateFamily', **payload) |
|
559 |
return {'data': 'ok'} |
|
560 | ||
511 | 561 |
@endpoint( |
512 | 562 |
display_category='Famille', |
513 | 563 |
description="Mise à jour des coordonnées d'une personne", |
514 | 564 |
name='update-coordinate', |
515 | 565 |
perm='can_access', |
516 | 566 |
parameters={ |
517 | 567 |
'NameID': {'description': 'Publik NameID'}, |
518 | 568 |
'rl_id': {'description': 'Numéro du représentant légal'}, |
passerelle/contrib/toulouse_maelis/schemas.py | ||
---|---|---|
674 | 674 | |
675 | 675 |
UPDATE_RL1_SCHEMA = copy.deepcopy(RLINFO_SCHEMA) |
676 | 676 |
UPDATE_RL1_SCHEMA['required'] = ['firstname', 'lastname', 'civility', 'quality', 'dateBirth'] |
677 | 677 |
del UPDATE_RL1_SCHEMA['properties']['adresse'] |
678 | 678 |
del UPDATE_RL1_SCHEMA['properties']['contact'] |
679 | 679 |
del UPDATE_RL1_SCHEMA['properties']['profession'] |
680 | 680 |
del UPDATE_RL1_SCHEMA['properties']['CAFInfo'] |
681 | 681 | |
682 |
CREATE_RL2_SCHEMA = copy.deepcopy(RLINFO_SCHEMA) |
|
683 |
CREATE_RL2_SCHEMA['unflatten'] = True |
|
684 |
del CREATE_RL2_SCHEMA['properties']['contact'] |
|
685 |
del CREATE_RL2_SCHEMA['properties']['profession'] |
|
686 |
del CREATE_RL2_SCHEMA['properties']['CAFInfo'] |
|
687 | ||
688 |
UPDATE_RL2_SCHEMA = copy.deepcopy(UPDATE_RL1_SCHEMA) |
|
682 | 689 | |
683 | 690 |
UPDATE_COORDINATE_SCHEMA = { |
684 | 691 |
'$schema': 'http://json-schema.org/draft-04/schema#', |
685 | 692 |
'title': 'Update coordinate', |
686 | 693 |
'description': "Mise à jour des coordonnées d'un responsable légal", |
687 | 694 |
'type': 'object', |
688 | 695 |
'properties': { |
689 | 696 |
'adresse': ADDRESS_SCHEMA, |
tests/data/toulouse_maelis/Q_create_rl2.xml | ||
---|---|---|
1 |
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"> |
|
2 |
<soap-env:Header> |
|
3 |
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> |
|
4 |
<wsse:UsernameToken> |
|
5 |
<wsse:Username>maelis-webservice</wsse:Username> |
|
6 |
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">maelis-password</wsse:Password> |
|
7 |
</wsse:UsernameToken> |
|
8 |
</wsse:Security> |
|
9 |
</soap-env:Header> |
|
10 |
<soap-env:Body> |
|
11 |
<ns0:updateFamily xmlns:ns0="family.ws.maelis.sigec.com"> |
|
12 |
<dossierNumber>1312</dossierNumber> |
|
13 |
<categorie>BI</categorie> |
|
14 |
<situation>M</situation> |
|
15 |
<rl2> |
|
16 |
<lastname>DOE</lastname> |
|
17 |
<firstname>JANE</firstname> |
|
18 |
<quality>MERE</quality> |
|
19 |
<civility>MME</civility> |
|
20 |
<dateBirth>1940-06-22</dateBirth> |
|
21 |
<adresse> |
|
22 |
<num>170</num> |
|
23 |
<street1>Chateau d'eau</street1> |
|
24 |
<town>Paris</town> |
|
25 |
<zipcode>75014</zipcode> |
|
26 |
</adresse> |
|
27 |
</rl2> |
|
28 |
</ns0:updateFamily> |
|
29 |
</soap-env:Body> |
|
30 |
</soap-env:Envelope> |
tests/data/toulouse_maelis/Q_update_rl2.xml | ||
---|---|---|
1 |
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"> |
|
2 |
<soap-env:Header> |
|
3 |
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> |
|
4 |
<wsse:UsernameToken> |
|
5 |
<wsse:Username>maelis-webservice</wsse:Username> |
|
6 |
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">maelis-password</wsse:Password> |
|
7 |
</wsse:UsernameToken> |
|
8 |
</wsse:Security> |
|
9 |
</soap-env:Header> |
|
10 |
<soap-env:Body> |
|
11 |
<ns0:updateFamily xmlns:ns0="family.ws.maelis.sigec.com"> |
|
12 |
<dossierNumber>1312</dossierNumber> |
|
13 |
<categorie>BI</categorie> |
|
14 |
<situation>M</situation> |
|
15 |
<rl2> |
|
16 |
<num>613879</num> |
|
17 |
<lastname>DOE</lastname> |
|
18 |
<firstname>JANE</firstname> |
|
19 |
<quality>MERE</quality> |
|
20 |
<civility>MME</civility> |
|
21 |
<dateBirth>1940-06-22</dateBirth> |
|
22 |
<adresse> |
|
23 |
<num>170</num> |
|
24 |
<street1>Chateau d'eau</street1> |
|
25 |
<town>Paris</town> |
|
26 |
<zipcode>75014</zipcode> |
|
27 |
</adresse> |
|
28 |
</rl2> |
|
29 |
</ns0:updateFamily> |
|
30 |
</soap-env:Body> |
|
31 |
</soap-env:Envelope> |
tests/test_toulouse_maelis.py | ||
---|---|---|
1232 | 1232 |
} |
1233 | 1233 | |
1234 | 1234 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
1235 | 1235 |
resp = app.post_json(url + '?NameID=local', params=params, status=500) |
1236 | 1236 |
assert resp.json['err'] |
1237 | 1237 |
assert resp.json['err_desc'] == 'No address associated with hostname' |
1238 | 1238 | |
1239 | 1239 | |
1240 |
@mock.patch('passerelle.utils.Request.get') |
|
1241 |
@mock.patch('passerelle.utils.Request.post') |
|
1242 |
def test_create_rl2(mocked_post, mocked_get, con, app): |
|
1243 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
|
1244 |
mocked_post.side_effect = [READ_RL1_FAMILY, UPDATE_FAMILY] |
|
1245 |
url = get_endpoint('create-rl2') |
|
1246 |
params = { |
|
1247 |
'civility': 'MME', |
|
1248 |
'firstname': 'JANE', |
|
1249 |
'lastname': 'DOE', |
|
1250 |
'quality': 'MERE', |
|
1251 |
'dateBirth': '1940-06-22', |
|
1252 |
'adresse/num': '170', |
|
1253 |
'adresse/street1': "Chateau d'eau", |
|
1254 |
'adresse/town': 'Paris', |
|
1255 |
'adresse/zipcode': '75014', |
|
1256 |
} |
|
1257 | ||
1258 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
1259 |
resp = app.post_json(url + '?NameID=local', params=params) |
|
1260 |
assert_sent_payload(mocked_post, 'Q_create_rl2.xml') |
|
1261 |
assert resp.json['err'] == 0 |
|
1262 |
assert resp.json['data'] == 'ok' |
|
1263 | ||
1264 | ||
1265 |
def test_create_rl2_not_linked_error(con, app): |
|
1266 |
url = get_endpoint('create-rl2') |
|
1267 |
params = { |
|
1268 |
'civility': 'MME', |
|
1269 |
'firstname': 'JANE', |
|
1270 |
'lastname': 'DOE', |
|
1271 |
'quality': 'MERE', |
|
1272 |
'dateBirth': '1940-06-22', |
|
1273 |
'adresse/num': '170', |
|
1274 |
'adresse/street1': "Chateau d'eau", |
|
1275 |
'adresse/town': 'Paris', |
|
1276 |
'adresse/zipcode': '75014', |
|
1277 |
} |
|
1278 | ||
1279 |
resp = app.post_json(url + '?NameID=local', params=params) |
|
1280 |
assert resp.json['err'] == 'not-linked' |
|
1281 |
assert resp.json['err_desc'] == 'User not linked to family' |
|
1282 | ||
1283 | ||
1284 |
@mock.patch('passerelle.utils.Request.get') |
|
1285 |
@mock.patch('passerelle.utils.Request.post') |
|
1286 |
def test_create_rl2_connection_error(mocked_post, mocked_get, con, app): |
|
1287 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
|
1288 |
mocked_post.side_effect = CONNECTION_ERROR |
|
1289 |
url = get_endpoint('create-rl2') |
|
1290 |
params = { |
|
1291 |
'civility': 'MME', |
|
1292 |
'firstname': 'JANE', |
|
1293 |
'lastname': 'DOE', |
|
1294 |
'quality': 'MERE', |
|
1295 |
'dateBirth': '1940-06-22', |
|
1296 |
'adresse/num': '170', |
|
1297 |
'adresse/street1': "Chateau d'eau", |
|
1298 |
'adresse/town': 'Paris', |
|
1299 |
'adresse/zipcode': '75014', |
|
1300 |
} |
|
1301 | ||
1302 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
1303 |
resp = app.post_json(url + '?NameID=local', params=params, status=500) |
|
1304 |
assert resp.json['err'] |
|
1305 |
assert resp.json['err_desc'] == 'No address associated with hostname' |
|
1306 | ||
1307 | ||
1308 |
@mock.patch('passerelle.utils.Request.get') |
|
1309 |
@mock.patch('passerelle.utils.Request.post') |
|
1310 |
def test_create_rl2_already_exists_error(mocked_post, mocked_get, con, app): |
|
1311 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
|
1312 |
mocked_post.return_value = READ_FAMILY |
|
1313 |
url = get_endpoint('create-rl2') |
|
1314 |
params = { |
|
1315 |
'civility': 'MME', |
|
1316 |
'firstname': 'JANE', |
|
1317 |
'lastname': 'DOE', |
|
1318 |
'quality': 'MERE', |
|
1319 |
'dateBirth': '1940-06-22', |
|
1320 |
'adresse/num': '170', |
|
1321 |
'adresse/street1': "Chateau d'eau", |
|
1322 |
'adresse/town': 'Paris', |
|
1323 |
'adresse/zipcode': '75014', |
|
1324 |
} |
|
1325 | ||
1326 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
1327 |
resp = app.post_json(url + '?NameID=local', params=params) |
|
1328 |
assert resp.json['err'] == 'already-rl2' |
|
1329 |
assert resp.json['err_desc'] == 'RL2 already defined on family' |
|
1330 | ||
1331 | ||
1332 |
@mock.patch('passerelle.utils.Request.get') |
|
1333 |
@mock.patch('passerelle.utils.Request.post') |
|
1334 |
def test_update_rl2(mocked_post, mocked_get, con, app): |
|
1335 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
|
1336 |
mocked_post.side_effect = [READ_FAMILY, UPDATE_FAMILY] |
|
1337 |
url = get_endpoint('update-rl2') |
|
1338 |
params = { |
|
1339 |
'civility': 'MME', |
|
1340 |
'firstname': 'JANE', |
|
1341 |
'lastname': 'DOE', |
|
1342 |
'quality': 'MERE', |
|
1343 |
'dateBirth': '1940-06-22', |
|
1344 |
} |
|
1345 | ||
1346 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
1347 |
resp = app.post_json(url + '?NameID=local', params=params) |
|
1348 |
assert_sent_payload(mocked_post, 'Q_update_rl2.xml') |
|
1349 |
assert resp.json['err'] == 0 |
|
1350 | ||
1351 | ||
1352 |
def test_update_rl2_not_linked_error(con, app): |
|
1353 |
url = get_endpoint('update-rl2') |
|
1354 |
params = { |
|
1355 |
'civility': 'MME', |
|
1356 |
'firstname': 'JANE', |
|
1357 |
'lastname': 'DOE', |
|
1358 |
'quality': 'MERE', |
|
1359 |
'dateBirth': '1940-06-22', |
|
1360 |
} |
|
1361 | ||
1362 |
resp = app.post_json(url + '?NameID=local', params=params) |
|
1363 |
assert resp.json['err'] == 'not-linked' |
|
1364 |
assert resp.json['err_desc'] == 'User not linked to family' |
|
1365 | ||
1366 | ||
1367 |
@mock.patch('passerelle.utils.Request.get') |
|
1368 |
@mock.patch('passerelle.utils.Request.post') |
|
1369 |
def test_update_rl2_connection_error(mocked_post, mocked_get, con, app): |
|
1370 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
|
1371 |
mocked_post.side_effect = CONNECTION_ERROR |
|
1372 |
url = get_endpoint('update-rl2') |
|
1373 |
params = { |
|
1374 |
'civility': 'MME', |
|
1375 |
'firstname': 'JANE', |
|
1376 |
'lastname': 'DOE', |
|
1377 |
'quality': 'MERE', |
|
1378 |
'dateBirth': '1940-06-22', |
|
1379 |
} |
|
1380 | ||
1381 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
1382 |
resp = app.post_json(url + '?NameID=local', params=params, status=500) |
|
1383 |
assert resp.json['err'] |
|
1384 |
assert resp.json['err_desc'] == 'No address associated with hostname' |
|
1385 | ||
1386 | ||
1387 |
@mock.patch('passerelle.utils.Request.get') |
|
1388 |
@mock.patch('passerelle.utils.Request.post') |
|
1389 |
def test_update_rl2_not_exists_error(mocked_post, mocked_get, con, app): |
|
1390 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
|
1391 |
mocked_post.return_value = READ_RL1_FAMILY |
|
1392 |
url = get_endpoint('update-rl2') |
|
1393 |
params = { |
|
1394 |
'civility': 'MME', |
|
1395 |
'firstname': 'JANE', |
|
1396 |
'lastname': 'DOE', |
|
1397 |
'quality': 'MERE', |
|
1398 |
'dateBirth': '1940-06-22', |
|
1399 |
} |
|
1400 | ||
1401 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
1402 |
resp = app.post_json(url + '?NameID=local', params=params) |
|
1403 |
assert resp.json['err'] == 'no-rl2' |
|
1404 |
assert resp.json['err_desc'] == 'No RL2 to update on family' |
|
1405 | ||
1406 | ||
1240 | 1407 |
@mock.patch('passerelle.utils.Request.get') |
1241 | 1408 |
@mock.patch('passerelle.utils.Request.post') |
1242 | 1409 |
def test_update_coordinate(mocked_post, mocked_get, con, app): |
1243 | 1410 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
1244 | 1411 |
mocked_post.return_value = UPDATE_FAMILY |
1245 | 1412 |
url = get_endpoint('update-coordinate') |
1246 | 1413 |
params = { |
1247 | 1414 |
'adresse/num': '169', |
1248 |
- |