Projet

Général

Profil

0002-iparapheur-return-generated-dossier_id-if-missing-fr.patch

Emmanuel Cazenave, 25 juin 2019 14:28

Télécharger (4,09 ko)

Voir les différences:

Subject: [PATCH 2/2] 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(-)
passerelle/contrib/iparapheur/models.py
189 189

  
190 190
        doc_type = soap_client.get_type('ns0:TypeDoc')
191 191
        doc = doc_type(content, content_type)
192
        generated_dossier_id = slugify(post_data['title'])
192 193
        parameters = {'TypeTechnique': post_data['type'],
193
                      'DossierID': slugify(post_data['title']),
194
                      'DossierID': generated_dossier_id,
194 195
                      'DossierTitre': post_data['title'],
195 196
                      'SousType': post_data['subtype'],
196 197
                      'Visibilite': post_data['visibility'],
......
203 204
            raise FileError('unknown error, no response')
204 205
        if resp.MessageRetour.codeRetour == 'KO':
205 206
            raise FileError(resp.MessageRetour.message)
206
        return {'data': {'RecordId': resp.DossierID, 'message': resp.MessageRetour.message}}
207

  
208
        dossier_id = resp.DossierID
209
        if not dossier_id:
210
            dossier_id = generated_dossier_id
211
        return {'data': {'dossier_id': dossier_id, 'message': resp.MessageRetour.message}}
207 212

  
208 213
    @endpoint(perm='can_access', name='get-file', pattern='(?P<file_id>[\w-]+)')
209 214
    def get_file(self, request, file_id, appendix=None):
tests/test_iparapheur.py
133 133
        assert req.find('ns1:SousType', SOAP_NAMESPACES).text == subtyp
134 134
        assert req.find('ns1:Visibilite', SOAP_NAMESPACES).text == visibility
135 135
        assert req.find('ns1:DocumentPrincipal', SOAP_NAMESPACES).text == base64_data
136
        assert resp.json['data']['RecordId'] == file_id
136
        assert resp.json['data']['dossier_id'] == file_id
137

  
138
    # Missing dossier_id in response
139
    title = 'foo'
140
    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
141
    response._content = soap_response
142
    mocked_post.return_value = response
143
    base64_data = 'VGVzdCBEb2N1bWVudA=='
144
    data = {
145
        'type': typ, 'subtype': subtyp, 'visibility': visibility,
146
        'title': title,
147
        'file': {
148
            'content': base64_data,
149
            'content_type': 'application/pdf'
150
        }
151
    }
152

  
153
    url = reverse(
154
        'generic-endpoint',
155
        kwargs={'connector': 'iparapheur', 'endpoint': 'create-file', 'slug': conn.slug}
156
    )
157
    resp = app.post_json(url, params=data, status=403)
158
    url += '?apikey=%s' % API_KEY
159
    resp = app.post_json(url, params=data)
160
    assert resp.json['data']['dossier_id'] == title
137 161

  
138 162
    # KO
139 163
    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>"""
140
-