From 223dcd7e5e62728d824a6e1e32906db11fc6916c Mon Sep 17 00:00:00 2001 From: Emmanuel Cazenave Date: Tue, 25 Jun 2019 14:09:09 +0200 Subject: [PATCH] iparapheur: return generated dossier_id if missing from response (#34298) --- passerelle/contrib/iparapheur/models.py | 9 +++++++-- tests/test_iparapheur.py | 26 ++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/passerelle/contrib/iparapheur/models.py b/passerelle/contrib/iparapheur/models.py index f416e934..b0e426eb 100644 --- a/passerelle/contrib/iparapheur/models.py +++ b/passerelle/contrib/iparapheur/models.py @@ -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[\w-]+)') def get_file(self, request, file_id, appendix=None): diff --git a/tests/test_iparapheur.py b/tests/test_iparapheur.py index 4ffc3e91..c1af4a25 100644 --- a/tests/test_iparapheur.py +++ b/tests/test_iparapheur.py @@ -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 = """OKDossier %s soumis dans le circuitINFO""" % 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 = """KOKOmessageINFO"""