0001-iparapheur-add-handling-of-invalid-response-content.patch
passerelle/contrib/iparapheur/soap.py | ||
---|---|---|
23 | 23 | |
24 | 24 |
from suds.client import Client |
25 | 25 |
from suds.transport.http import HttpAuthenticated |
26 |
from suds.transport import Reply |
|
26 |
from suds.transport import Reply, TransportError
|
|
27 | 27 |
from suds.plugin import MessagePlugin, DocumentPlugin |
28 | 28 | |
29 | 29 |
from suds.sudsobject import asdict |
30 | 30 | |
31 | 31 | |
32 |
class CustomTransportError(TransportError): |
|
33 | ||
34 |
def __init__(self, *args, **kwargs): |
|
35 |
super(CustomTransportError, self).__init__(*args, **kwargs) |
|
36 |
self.http_status = 200 |
|
37 |
self.log_error = False |
|
38 | ||
39 | ||
32 | 40 |
class Filter(MessagePlugin): |
33 | 41 | |
34 | 42 |
def marshalled(self, context): |
... | ... | |
75 | 83 |
self.addcredentials(request) |
76 | 84 |
resp = self.model.requests.post(request.url, data=request.message, |
77 | 85 |
headers=request.headers, **self.get_requests_kwargs()) |
78 |
return Reply(resp.status_code, resp.headers, resp.content) |
|
86 | ||
87 |
if resp.status_code in (202, 204): |
|
88 |
return None |
|
89 |
elif not resp.ok(): |
|
90 |
raise CustomTransportError( |
|
91 |
resp.reason, |
|
92 |
resp.status_code, fp=StringIO.StringIO(resp.content)) |
|
93 |
else: |
|
94 |
return Reply(resp.status_code, resp.headers, resp.content) |
|
79 | 95 | |
80 | 96 |
def get_client(instance): |
81 | 97 |
transport = Transport(instance) |
tests/test_iparapheur.py | ||
---|---|---|
154 | 154 |
file_sent = os.path.join(os.path.dirname(__file__), 'data/iparapheur_test.pdf') |
155 | 155 |
assert resp.headers['Content-Type'] == 'application/pdf' |
156 | 156 |
assert hashlib.md5(resp.body[:8192]).hexdigest() == hashlib.md5(file(file_sent).read()[:8192]).hexdigest() |
157 | ||
158 | ||
159 |
@mock.patch('passerelle.utils.LoggedRequest.get') |
|
160 |
@mock.patch('passerelle.utils.LoggedRequest.post') |
|
161 |
@mock.patch('passerelle.contrib.iparapheur.soap.HttpAuthenticated.open') |
|
162 |
def test_invalid_response(http_open, mocked_post, mocked_get, setup, xmlmime, wsdl_file): |
|
163 |
app, conn = setup |
|
164 |
file_id = str(uuid.uuid4()) |
|
165 | ||
166 |
http_open.return_value = file(xmlmime) |
|
167 |
mocked_get.return_value = mock.Mock(content = file(wsdl_file).read(), |
|
168 |
status_code=200) |
|
169 |
mocked_post.return_value = mock.Mock(status_code=502, content='<p>Bad Gateway</p>', reason='Bad Gateway') |
|
170 |
url = reverse('generic-endpoint', kwargs={'slug': conn.slug, |
|
171 |
'connector': 'iparapheur', 'endpoint': 'get-file', |
|
172 |
'rest': file_id}) |
|
173 |
resp = app.get(url) |
|
174 |
import pdb; pdb.set_trace() |
|
157 |
- |