iparapheur: return generated dossier_id if missing from response (#34298)

This commit is contained in:
Emmanuel Cazenave 2019-06-25 14:09:09 +02:00
parent b62b45b4fa
commit 223dcd7e5e
2 changed files with 32 additions and 3 deletions

View File

@ -189,8 +189,9 @@ class IParapheur(BaseResource, HTTPResource):
doc_type = soap_client.get_type('ns0:TypeDoc')
doc = doc_type(content, content_type)
generated_dossier_id = slugify(post_data['title'])
parameters = {'TypeTechnique': post_data['type'],
'DossierID': slugify(post_data['title']),
'DossierID': generated_dossier_id,
'DossierTitre': post_data['title'],
'SousType': post_data['subtype'],
'Visibilite': post_data['visibility'],
@ -203,7 +204,11 @@ class IParapheur(BaseResource, HTTPResource):
raise FileError('unknown error, no response')
if resp.MessageRetour.codeRetour == 'KO':
raise FileError(resp.MessageRetour.message)
return {'data': {'RecordId': resp.DossierID, 'message': resp.MessageRetour.message}}
dossier_id = resp.DossierID
if not dossier_id:
dossier_id = generated_dossier_id
return {'data': {'dossier_id': dossier_id, 'message': resp.MessageRetour.message}}
@endpoint(perm='can_access', name='get-file', pattern='(?P<file_id>[\w-]+)')
def get_file(self, request, file_id, appendix=None):

View File

@ -133,7 +133,31 @@ def test_create_file(mocked_post, mocked_get, app, conn):
assert req.find('ns1:SousType', SOAP_NAMESPACES).text == subtyp
assert req.find('ns1:Visibilite', SOAP_NAMESPACES).text == visibility
assert req.find('ns1:DocumentPrincipal', SOAP_NAMESPACES).text == base64_data
assert resp.json['data']['RecordId'] == file_id
assert resp.json['data']['dossier_id'] == file_id
# Missing dossier_id in response
title = 'foo'
soap_response = """<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><CreerDossierResponse xmlns="http://www.adullact.org/spring-ws/iparapheur/1.0" xmlns:xmime="http://www.w3.org/2005/05/xmlmime"><MessageRetour><codeRetour>OK</codeRetour><message>Dossier %s soumis dans le circuit</message><severite>INFO</severite></MessageRetour><DossierID></DossierID></CreerDossierResponse></S:Body></S:Envelope>""" % title
response._content = soap_response
mocked_post.return_value = response
base64_data = 'VGVzdCBEb2N1bWVudA=='
data = {
'type': typ, 'subtype': subtyp, 'visibility': visibility,
'title': title,
'file': {
'content': base64_data,
'content_type': 'application/pdf'
}
}
url = reverse(
'generic-endpoint',
kwargs={'connector': 'iparapheur', 'endpoint': 'create-file', 'slug': conn.slug}
)
resp = app.post_json(url, params=data, status=403)
url += '?apikey=%s' % API_KEY
resp = app.post_json(url, params=data)
assert resp.json['data']['dossier_id'] == title
# KO
soap_response = """<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><CreerDossierResponse xmlns="http://www.adullact.org/spring-ws/iparapheur/1.0" xmlns:xmime="http://www.w3.org/2005/05/xmlmime"><MessageRetour><codeRetour>KO</codeRetour><message>KOmessage</message><severite>INFO</severite></MessageRetour></CreerDossierResponse></S:Body></S:Envelope>"""