0001-axel-handle-transport-errors-58925.patch
passerelle/contrib/utils/axel.py | ||
---|---|---|
20 | 20 |
import os |
21 | 21 |
import re |
22 | 22 |
import xml.etree.ElementTree as ET |
23 | 23 |
from collections import namedtuple |
24 | 24 | |
25 | 25 |
import pytz |
26 | 26 |
import xmlschema |
27 | 27 |
from django.utils.encoding import force_text |
28 |
from zeep.exceptions import TransportError |
|
28 | 29 | |
29 | 30 |
from passerelle.utils.xml import JSONSchemaFromXMLSchema |
30 | 31 | |
31 | 32 |
boolean_type = { |
32 | 33 |
'oneOf': [ |
33 | 34 |
{'type': 'boolean'}, |
34 | 35 |
{ |
35 | 36 |
'type': 'string', |
... | ... | |
235 | 236 |
raise AxelError('invalid request %s' % str(e)) |
236 | 237 |
indent(serialized_request) |
237 | 238 |
serialized_request = force_text(ET.tostring(serialized_request)) |
238 | 239 |
try: |
239 | 240 |
self.request_converter.xml_schema.validate(serialized_request) |
240 | 241 |
except xmlschema.XMLSchemaValidationError as e: |
241 | 242 |
raise AxelError('invalid request %s' % str(e), xml_request=serialized_request) |
242 | 243 | |
243 |
result = getattr(client.service, self.data_method)( |
|
244 |
self.operation, serialized_request, '' |
|
245 |
) # FIXME: What is the user parameter for ? |
|
244 |
try: |
|
245 |
result = getattr(client.service, self.data_method)( |
|
246 |
self.operation, serialized_request, '' |
|
247 |
) # FIXME: What is the user parameter for ? |
|
248 |
except TransportError as e: |
|
249 |
raise AxelError('invalid response %s' % str(e), xml_request=serialized_request) |
|
246 | 250 | |
247 | 251 |
xml_result = ET.fromstring(result.encode('utf-8')) |
248 | 252 |
indent(xml_result) |
249 | 253 |
pretty_result = force_text(ET.tostring(xml_result)) |
250 | 254 |
if xml_result.find('RESULTAT/STATUS').text != 'OK': |
251 | 255 |
msg = xml_result.find('RESULTAT/COMMENTAIRES').text |
252 | 256 |
raise AxelError(msg, xml_request=serialized_request, xml_response=pretty_result) |
253 | 257 |
tests/test_caluire_axel.py | ||
---|---|---|
20 | 20 |
import xml.etree.ElementTree as ET |
21 | 21 |
from contextlib import contextmanager |
22 | 22 | |
23 | 23 |
import freezegun |
24 | 24 |
import mock |
25 | 25 |
import pytest |
26 | 26 |
import utils |
27 | 27 |
import xmlschema |
28 |
from zeep.exceptions import TransportError |
|
28 | 29 | |
29 | 30 |
from passerelle.contrib.caluire_axel import schemas |
30 | 31 |
from passerelle.contrib.caluire_axel.models import CaluireAxel, Link |
31 | 32 |
from passerelle.contrib.utils.axel import AxelError, OperationResult, json_date_format, xml_date_format |
32 | 33 |
from passerelle.utils.soap import SOAPError |
33 | 34 | |
34 | 35 |
XML_RESPONSE_TEMPLATE = '''<?xml version="1.0"?> |
35 | 36 |
<PORTAILSERVICE> |
... | ... | |
216 | 217 |
'TEL': None, |
217 | 218 |
'MAIL': None, |
218 | 219 |
} |
219 | 220 |
} |
220 | 221 |
}, |
221 | 222 |
) |
222 | 223 | |
223 | 224 | |
225 |
def test_operation_transport_error(resource): |
|
226 |
with mock.patch('passerelle.contrib.caluire_axel.models.CaluireAxel.soap_client') as client: |
|
227 |
client.return_value.service.setData.side_effect = TransportError('Foo reason') |
|
228 |
with pytest.raises(AxelError, match='Foo reason'): |
|
229 |
schemas.set_paiement( |
|
230 |
resource, |
|
231 |
{ |
|
232 |
'PORTAIL': { |
|
233 |
'SETPAIEMENT': { |
|
234 |
'IDFACTURE': 42, |
|
235 |
'IDENTREGIEENC': 'MAREGIE', |
|
236 |
'MONTANT': '4.94', |
|
237 |
'IDENTMODEREGLEMENT': 'INCB', |
|
238 |
} |
|
239 |
} |
|
240 |
}, |
|
241 |
) |
|
242 | ||
243 | ||
224 | 244 |
def test_link_endpoint_nameid_empty(app, resource, link_params): |
225 | 245 |
resp = app.post_json('/caluire-axel/test/link?NameID=', params=link_params, status=400) |
226 | 246 |
assert resp.json['err_desc'] == "NameID is empty" |
227 | 247 |
assert resp.json['err'] == 'bad-request' |
228 | 248 | |
229 | 249 | |
230 | 250 |
def test_link_endpoint_axel_error(app, resource, link_params): |
231 | 251 |
with mock.patch('passerelle.contrib.caluire_axel.schemas.find_individus') as operation: |
tests/test_toulouse_axel.py | ||
---|---|---|
27 | 27 | |
28 | 28 |
import freezegun |
29 | 29 |
import jsonschema |
30 | 30 |
import mock |
31 | 31 |
import pytest |
32 | 32 |
import utils |
33 | 33 |
import xmlschema |
34 | 34 |
from django.core.cache import cache |
35 |
from zeep.exceptions import TransportError |
|
35 | 36 | |
36 | 37 |
from passerelle.contrib.toulouse_axel import schemas |
37 | 38 |
from passerelle.contrib.toulouse_axel.models import Link, Lock, ToulouseAxel |
38 | 39 |
from passerelle.contrib.toulouse_axel.utils import ( |
39 | 40 |
csp_mapping, |
40 | 41 |
lien_parente_mapping, |
41 | 42 |
regime_mapping, |
42 | 43 |
situation_familiale_mapping, |
... | ... | |
296 | 297 |
'NOM': 'Doe', |
297 | 298 |
'NAISSANCE': '2010-10-10', |
298 | 299 |
} |
299 | 300 |
} |
300 | 301 |
}, |
301 | 302 |
) |
302 | 303 | |
303 | 304 | |
305 |
def test_operation_transport_error(resource): |
|
306 |
with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.soap_client') as client: |
|
307 |
client.return_value.service.getData.side_effect = TransportError('Foo reason') |
|
308 |
with pytest.raises(AxelError, match='Foo reason'): |
|
309 |
schemas.form_paiement_dui( |
|
310 |
resource, |
|
311 |
{ |
|
312 |
'PORTAIL': { |
|
313 |
'DUI': { |
|
314 |
'DATEPAIEMENT': '01/01/2020 13:00:00', |
|
315 |
'IDFACTURE': 42, |
|
316 |
'IDREGIEENCAISSEMENT': '', |
|
317 |
'MONTANTPAYE': decimal.Decimal('4.94'), |
|
318 |
'REFERENCE': 'foo', |
|
319 |
} |
|
320 |
} |
|
321 |
}, |
|
322 |
) |
|
323 | ||
324 | ||
304 | 325 |
@contextmanager |
305 | 326 |
def mock_getdata(content, operation): |
306 | 327 |
with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.soap_client') as client: |
307 | 328 |
resp = ''' |
308 | 329 |
<?xml version="1.0"?> |
309 | 330 |
<PORTAILSERVICE> |
310 | 331 |
<RESULTAT> |
311 | 332 |
<TYPE>%s</TYPE> |
312 |
- |