Projet

Général

Profil

0001-iparapheur-accept-wcs-style-parameters-33869.patch

Emmanuel Cazenave, 12 juin 2019 14:21

Télécharger (5,05 ko)

Voir les différences:

Subject: [PATCH] iparapheur: accept wcs style parameters (#33869)

 passerelle/contrib/iparapheur/models.py |  6 +--
 tests/test_iparapheur.py                | 52 ++++++++++++++++---------
 2 files changed, 37 insertions(+), 21 deletions(-)
passerelle/contrib/iparapheur/models.py
139 139
        subtyp = data['subtype']
140 140
        email = data.get('email')
141 141
        visibility = data['visibility']
142
        content = base64.b64decode(data['data'])
143
        content_type = data.get('content_type') if data.get('content_type') \
144
            else get_magic_mime(content)
142
        content = base64.b64decode(data.get('file', {}).get('content') or data['data'])
143
        content_type = data.get('file', {}).get('content_type') or data.get('content_type') \
144
            or get_magic_mime(content)
145 145

  
146 146
        soap_client = get_client(self)
147 147
        if visibility not in ['PUBLIC', 'SERVICE', 'CONFIDENTIEL']:
tests/test_iparapheur.py
110 110
        title, ext = filename.split('.')
111 111
        base64_data = 'VGVzdCBEb2N1bWVudA=='
112 112
        data = {'type': typ, 'subtype': subtyp, 'visibility': visibility,
113
                'title': title, 'data': base64_data, 'content-type':'application/pdf'}
114
        url = reverse('generic-endpoint', kwargs={'connector': 'iparapheur',
115
                                'endpoint': 'create-file', 'slug': conn.slug})
116
        resp = app.post_json(url, params=data, status=403)
117
        url += '?apikey=%s' % API_KEY
118
        resp = app.post_json(url, params=data)
119
        # check output call args
120
        assert (BASE_URL,) == mocked_post.call_args[0]
121
        xml = ET.fromstring(mocked_post.call_args[1].get('data'))
122
        req = xml.find('soap:Body', SOAP_NAMESPACES).find('ns1:CreerDossierRequest', SOAP_NAMESPACES)
123
        assert req.find('ns1:DossierTitre', SOAP_NAMESPACES).text == title
124
        assert req.find('ns1:DossierID', SOAP_NAMESPACES).text == title
125
        assert req.find('ns1:TypeTechnique', SOAP_NAMESPACES).text == typ
126
        assert req.find('ns1:SousType', SOAP_NAMESPACES).text == subtyp
127
        assert req.find('ns1:Visibilite', SOAP_NAMESPACES).text == visibility
128
        assert req.find('ns1:DocumentPrincipal', SOAP_NAMESPACES).text == base64_data
129
        assert resp.json['data']['RecordId'] == file_id
130

  
113
                'title': title}
114

  
115
        for param_style in ('old_style', 'new_style'):
116
            real_data = data.copy()
117
            if param_style == 'old_style':
118
                real_data.update({'data': base64_data, 'content-type':'application/pdf'})
119
            else:
120
                real_data.update({
121
                    'file': {
122
                        'content': base64_data, 'content_type':'application/pdf'
123
                    }
124
                })
125

  
126
            url = reverse('generic-endpoint', kwargs={'connector': 'iparapheur',
127
                                    'endpoint': 'create-file', 'slug': conn.slug})
128
            resp = app.post_json(url, params=real_data, status=403)
129
            url += '?apikey=%s' % API_KEY
130
            resp = app.post_json(url, params=real_data)
131
            # check output call args
132
            assert (BASE_URL,) == mocked_post.call_args[0]
133
            xml = ET.fromstring(mocked_post.call_args[1].get('data'))
134
            req = xml.find('soap:Body', SOAP_NAMESPACES).find('ns1:CreerDossierRequest', SOAP_NAMESPACES)
135
            assert req.find('ns1:DossierTitre', SOAP_NAMESPACES).text == title
136
            assert req.find('ns1:DossierID', SOAP_NAMESPACES).text == title
137
            assert req.find('ns1:TypeTechnique', SOAP_NAMESPACES).text == typ
138
            assert req.find('ns1:SousType', SOAP_NAMESPACES).text == subtyp
139
            assert req.find('ns1:Visibilite', SOAP_NAMESPACES).text == visibility
140
            assert req.find('ns1:DocumentPrincipal', SOAP_NAMESPACES).text == base64_data
141
            assert resp.json['data']['RecordId'] == file_id
142

  
143
    data = {
144
        'type': typ, 'subtype': subtyp, 'visibility': visibility,
145
        'title': title, 'data': base64_data, 'content-type':'application/pdf'
146
    }
131 147
    # KO
132 148
    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>"""
133 149
    response._content = soap_response
134
-