0001-astregs-add-endpoints-to-update-and-delection-indana.patch
passerelle/apps/astregs/models.py | ||
---|---|---|
260 | 260 |
} |
261 | 261 |
} |
262 | 262 | |
263 |
INDANA_KEY_SCHEMA = { |
|
264 |
"$schema": "http://json-schema.org/draft-03/schema#", |
|
265 |
"title": "AstreGS INDANA indicator key", |
|
266 |
"description": "", |
|
267 |
"type": "object", |
|
268 |
"properties": { |
|
269 |
"CodeDossier": { |
|
270 |
"type": "string", |
|
271 |
"required": True |
|
272 |
}, |
|
273 |
"CodeInd_1": { |
|
274 |
"type": "string", |
|
275 |
"required": True |
|
276 |
}, |
|
277 |
"AnneeInd_1": { |
|
278 |
"type": "string", |
|
279 |
"required": True |
|
280 |
} |
|
281 |
} |
|
282 |
} |
|
283 | ||
284 | ||
263 | 285 | |
264 | 286 |
class AstreGS(BaseResource): |
265 | 287 |
wsdl_base_url = models.URLField(_('Webservices base URL')) |
... | ... | |
585 | 607 |
return {'data': serialize_object(r)} |
586 | 608 | |
587 | 609 | |
610 |
@endpoint(name='update-indana-indicator', perm='can_access', |
|
611 |
post={'description': _('Update indana indicator'), |
|
612 |
'request_body': { |
|
613 |
'schema': { |
|
614 |
'application/json': INDANA_SCHEMA |
|
615 |
} |
|
616 |
} |
|
617 |
} |
|
618 |
) |
|
619 |
def update_indana_indicator(self, request, post_data): |
|
620 |
r = self.call('DossierIndicateur', 'Modification', |
|
621 |
DossierIndicateur=post_data |
|
622 |
) |
|
623 |
return {'data': serialize_object(r)} |
|
624 | ||
625 | ||
626 |
@endpoint(name='delete-indana-indicator', perm='can_access', |
|
627 |
post={'description': _('Delete indana indicator'), |
|
628 |
'request_body': { |
|
629 |
'schema': { |
|
630 |
'application/json': INDANA_KEY_SCHEMA |
|
631 |
} |
|
632 |
} |
|
633 |
} |
|
634 |
) |
|
635 |
def delete_indana_indicator(self, request, post_data): |
|
636 |
r = self.call('DossierIndicateur', 'Suppression', |
|
637 |
DossierIndicateurCle=post_data |
|
638 |
) |
|
639 |
return {'data': serialize_object(r)} |
|
640 | ||
641 | ||
588 | 642 |
class Link(models.Model): |
589 | 643 |
resource = models.ForeignKey(AstreGS) |
590 | 644 |
name_id = models.CharField(max_length=32) |
tests/data/astregs/DossierIndicateurModificationResponse.xml | ||
---|---|---|
1 |
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns1:modificationResponse xmlns:ns1="http://gfi.astre.webservices/gad/dossierindicateur"><ns1:response><ns1:DossierIndicateurReturn><ns1:CodeDossier>2019_06407</ns1:CodeDossier><ns1:CodeInd_1>501</ns1:CodeInd_1><ns1:AnneeInd_1>2019</ns1:AnneeInd_1><ns1:ValInd_1>N</ns1:ValInd_1><ns1:IndAide>Non</ns1:IndAide></ns1:DossierIndicateurReturn></ns1:response></ns1:modificationResponse></soapenv:Body></soapenv:Envelope> |
tests/data/astregs/DossierIndicateurSuppressionResponse.xml | ||
---|---|---|
1 |
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns1:suppressionResponse xmlns:ns1="http://gfi.astre.webservices/gad/dossierindicateur"><ns1:response><ns1:DossierIndicateurReturn><ns1:CodeDossier>2019_06407</ns1:CodeDossier><ns1:CodeInd_1>501</ns1:CodeInd_1><ns1:AnneeInd_1>2019</ns1:AnneeInd_1><ns1:ValInd_1>N</ns1:ValInd_1><ns1:IndAide>Non</ns1:IndAide></ns1:DossierIndicateurReturn></ns1:response></ns1:suppressionResponse></soapenv:Body></soapenv:Envelope> |
tests/test_astregs.py | ||
---|---|---|
452 | 452 |
assert data['AnneeInd_1'] == '2019' |
453 | 453 |
assert data['ValInd_1'] == 'O' |
454 | 454 |
assert data['IndAide'] == 'Non' |
455 | ||
456 | ||
457 |
@mock.patch('passerelle.utils.Request.get') |
|
458 |
@mock.patch('passerelle.utils.Request.post') |
|
459 |
def test_update_indana_indicator(mocked_post, mocked_get, connector, app): |
|
460 |
mocked_get.return_value = mock.Mock(content=get_xml_file('DossierIndicateur.wsdl')) |
|
461 |
mocked_post.return_value = mock.Mock(content=get_xml_file('DossierIndicateurModificationResponse.xml'), |
|
462 |
headers={'Content-Type': 'text/xml'}, |
|
463 |
status_code=200) |
|
464 |
payload = { |
|
465 |
'CodeDossier': '2019_06407', |
|
466 |
'CodeInd_1': '501', |
|
467 |
'AnneeInd_1': '2019', |
|
468 |
'ValInd_1': 'N' |
|
469 |
} |
|
470 |
resp = app.post_json('/astregs/test/update-indana-indicator', params=payload) |
|
471 |
assert resp.json == { |
|
472 |
'err': 0, |
|
473 |
'data': { |
|
474 |
'CodeDossier':'2019_06407', |
|
475 |
'CodeInd_1': '501', |
|
476 |
'AnneeInd_1': '2019', |
|
477 |
'ValInd_1': 'N', |
|
478 |
'IndAide': 'Non' |
|
479 |
} |
|
480 |
} |
|
481 | ||
482 | ||
483 |
@mock.patch('passerelle.utils.Request.get') |
|
484 |
@mock.patch('passerelle.utils.Request.post') |
|
485 |
def test_delete_indana_indicator(mocked_post, mocked_get, connector, app): |
|
486 |
mocked_get.return_value = mock.Mock(content=get_xml_file('DossierIndicateur.wsdl')) |
|
487 |
mocked_post.return_value = mock.Mock(content=get_xml_file('DossierIndicateurSuppressionResponse.xml'), |
|
488 |
headers={'Content-Type': 'text/xml'}, |
|
489 |
status_code=200) |
|
490 |
payload = { |
|
491 |
'CodeDossier': '2019_06407', |
|
492 |
'CodeInd_1': '501', |
|
493 |
'AnneeInd_1': '2019' |
|
494 |
} |
|
495 |
resp = app.post_json('/astregs/test/delete-indana-indicator', params=payload) |
|
496 |
assert resp.json == { |
|
497 |
'err': 0, |
|
498 |
'data': { |
|
499 |
'CodeDossier':'2019_06407', |
|
500 |
'CodeInd_1': '501', |
|
501 |
'AnneeInd_1': '2019', |
|
502 |
'ValInd_1': 'N', |
|
503 |
'IndAide': 'Non' |
|
504 |
} |
|
505 |
} |
|
455 |
- |