greco: new endpoint add-confirmation (#51812)

This commit is contained in:
Nicolas Roche 2021-03-09 11:57:41 +01:00 committed by Frédéric Péters
parent 3fa355cfd7
commit 11d0a41ce9
4 changed files with 79 additions and 0 deletions

View File

@ -308,3 +308,22 @@ class Greco(BaseResource):
if resp is None:
raise APIError('empty response from relancer()')
return {'data': sudsobject_to_dict(resp)}
@endpoint(perm='can_access', methods=['post'], name='add-confirmation')
def add_confirmation(self, request):
payload = json_loads(request.body)
if not isinstance(payload, dict):
raise ParameterTypeError('payload must be a dict')
idgreco = payload.get('idgreco')
iddemande = payload.get('iddemande')
nbr = payload.get('nbconfirmation')
resp = self.get_client().service.confirmer(
{
'idGreco': idgreco,
'idDemande': iddemande,
'nbconfirmation': nbr,
}
)
if resp is None:
raise APIError('empty response from confirmer()')
return {'data': sudsobject_to_dict(resp)}

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<confirmerResponse xmlns="http://mairies.services.external.coheris.com">
<confirmerReturn>
<iddemande>MDFGDZRF</iddemande>
<idgreco xsi:nil="true"/>
<motifsrejet>Le nombre de confirmation doit être un entier\r\n</motifsrejet>
</confirmerReturn>
</confirmerResponse>
</soapenv:Body>
</soapenv:Envelope>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<confirmerResponse xmlns="http://mairies.services.external.coheris.com">
<confirmerReturn>
<iddemande>MDFGDZRF</iddemande>
<idgreco>538593</idgreco>
<motifsrejet/>
</confirmerReturn>
</confirmerResponse>
</soapenv:Body>
</soapenv:Envelope>

View File

@ -67,6 +67,8 @@ ADD_INFORMATION_OK = fake_xml_response('add_information_ok')
ADD_INFORMATION_KO = fake_xml_response('add_information_ko')
UPDATE_OK = fake_xml_response('update_ok')
UPDATE_KO = fake_xml_response('update_ko')
ADD_CONFIRMATION_OK = fake_xml_response('add_confirmation_ok')
ADD_CONFIRMATION_KO = fake_xml_response('add_confirmation_ko')
CREATE_PAYLOAD = {
'datecreation': '2021-03-02T14:44:38',
@ -358,3 +360,37 @@ def test_greco_update_ko(mocked_post, app, conn):
'idgreco': '538593',
'motifsrejet': "La date de résolution prévue pour la demande 538593 n\\'est pas dépassée\\r\\n",
}
@mock.patch('passerelle.utils.Request.post', side_effect=(TOKEN, ADD_CONFIRMATION_OK))
def test_greco_add_confirmation_ok(mocked_post, app, conn):
url = reverse(
'generic-endpoint', kwargs={'connector': 'greco', 'endpoint': 'add-confirmation', 'slug': conn.slug}
)
url += '?apikey=grecokey'
resp = app.post_json(url, params={'idgreco': '538593', 'iddemande': 'MDFGDZRF', 'nbconfirmation': '2'})
assert not resp.json['err']
assert resp.json['data'] == {
'iddemande': 'MDFGDZRF',
'idgreco': '538593',
'motifsrejet': None,
}
@mock.patch('passerelle.utils.Request.post', side_effect=(TOKEN, ADD_CONFIRMATION_KO))
def test_greco_add_confirmation_ko(mocked_post, app, conn):
url = reverse(
'generic-endpoint', kwargs={'connector': 'greco', 'endpoint': 'add-confirmation', 'slug': conn.slug}
)
url += '?apikey=grecokey'
resp = app.post_json(
url, params={'idgreco': '538593', 'iddemande': 'MDFGDZRF', 'nbconfirmation': 'a lot'}
)
assert not resp.json['err']
assert resp.json['data'] == {
'iddemande': 'MDFGDZRF',
'idgreco': None,
'motifsrejet': 'Le nombre de confirmation doit être un entier\\r\\n',
}