0002-toulouse-maelis-add-wrapping-of-zeep-errors-inside-A.patch
passerelle/contrib/toulouse_maelis/models.py | ||
---|---|---|
27 | 27 |
from django.utils.timezone import now |
28 | 28 |
from zeep.helpers import serialize_object |
29 | 29 |
from zeep.wsse.username import UsernameToken |
30 | 30 | |
31 | 31 |
from passerelle.base.models import BaseResource, HTTPResource |
32 | 32 |
from passerelle.utils.api import endpoint |
33 | 33 |
from passerelle.utils.conversion import simplify |
34 | 34 |
from passerelle.utils.jsonresponse import APIError |
35 |
from passerelle.utils.soap import SOAPError |
|
35 | 36 |
from passerelle.utils.templates import render_to_string |
36 | 37 | |
37 | 38 |
from . import activity_schemas, family_schemas, invoice_schemas, schemas, utils |
38 | 39 | |
39 | 40 | |
40 | 41 |
class UpdateError(Exception): |
41 | 42 |
pass |
42 | 43 | |
... | ... | |
63 | 64 |
class Meta: |
64 | 65 |
verbose_name = 'Toulouse Maelis' |
65 | 66 | |
66 | 67 |
def get_client(self, wsdl_short_name): |
67 | 68 |
wsse = UsernameToken(self.zeep_wsse_username, self.zeep_wsse_password) |
68 | 69 |
wsdl_name = wsdl_short_name + 'Service?wsdl' |
69 | 70 |
wsdl_url = urljoin(self.base_wsdl_url, wsdl_name) |
70 | 71 |
settings = zeep.Settings(strict=False, xsd_ignore_sequence_order=True) |
71 |
return self.soap_client(wsdl_url=wsdl_url, wsse=wsse, settings=settings) |
|
72 |
return self.soap_client(wsdl_url=wsdl_url, wsse=wsse, settings=settings, api_error=True)
|
|
72 | 73 | |
73 | 74 |
def call(self, wsdl_short_name, service, **kwargs): |
74 | 75 |
client = self.get_client(wsdl_short_name) |
75 | 76 |
method = getattr(client.service, service) |
76 | 77 |
try: |
77 | 78 |
return method(**kwargs) |
78 |
except zeep.exceptions.Fault as e: |
|
79 |
raise APIError(e.message, err_code='%s-%s-%s' % (wsdl_short_name, service, e.code)) |
|
79 |
except SOAPError as e: |
|
80 |
e.err_code = '%s-%s-%s' % (wsdl_short_name, service, e.data['soap_fault']['code']) |
|
81 |
raise |
|
80 | 82 | |
81 | 83 |
def check_status(self): |
82 | 84 |
assert self.call('Family', 'isWSRunning') |
83 | 85 |
assert self.call('Activity', 'isWSRunning') |
84 | 86 |
assert self.call('Invoice', 'isWSRunning') |
85 | 87 |
assert self.call('Site', 'isWSRunning') |
86 | 88 | |
87 | 89 |
def update_referential(self, referential_name, data, id_key, text_key): |
tests/test_toulouse_maelis.py | ||
---|---|---|
3654 | 3654 |
'bank/civility': 'x', |
3655 | 3655 |
'bank/lastName': 'Ewing', |
3656 | 3656 |
'bank/firstName': 'John Ross', |
3657 | 3657 |
} |
3658 | 3658 | |
3659 | 3659 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
3660 | 3660 |
resp = app.post_json(url + '?NameID=local', params=params) |
3661 | 3661 |
assert resp.json['err'] == 'Invoice-addDirectDebitOrder-soap:Server' |
3662 |
assert resp.json['err_desc'] == "E520 : La REGIE CS [{0}] n''existe pas dans la base Maelis" |
|
3662 |
assert ( |
|
3663 |
resp.json['err_desc'] |
|
3664 |
== 'SOAP service at https://example.org/InvoiceService?wsdl returned an error "E520 : La REGIE CS [{0}] n\'\'existe pas dans la base Maelis"' |
|
3665 |
) |
|
3663 | 3666 | |
3664 | 3667 | |
3665 | 3668 |
def test_get_rl1_direct_debit_order(family_service, invoice_service, con, app): |
3666 | 3669 |
def request_check(request): |
3667 | 3670 |
assert request.numDossier == 1312 |
3668 | 3671 | |
3669 | 3672 |
family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml')) |
3670 | 3673 |
invoice_service.add_soap_response( |
... | ... | |
3730 | 3733 |
params = { |
3731 | 3734 |
'codeRegie': '12345', |
3732 | 3735 |
'dateRef': '2023-01-01', |
3733 | 3736 |
} |
3734 | 3737 | |
3735 | 3738 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
3736 | 3739 |
resp = app.get(url + '?NameID=local', params=params) |
3737 | 3740 |
assert resp.json['err'] == 'Invoice-getDirectDebitOrder-soap:Server' |
3738 |
assert resp.json['err_desc'] == "E520 : La REGIE CS [{0}] n''existe pas dans la base Maelis" |
|
3741 |
assert ( |
|
3742 |
resp.json['err_desc'] |
|
3743 |
== 'SOAP service at https://example.org/InvoiceService?wsdl returned an error "E520 : La REGIE CS [{0}] n\'\'existe pas dans la base Maelis"' |
|
3744 |
) |
|
3739 | 3745 | |
3740 | 3746 | |
3741 | 3747 |
def test_read_school_year_list(con, app): |
3742 | 3748 |
url = get_endpoint('read-school-years-list') |
3743 | 3749 |
resp = app.get(url) |
3744 | 3750 |
assert resp.json['err'] == 0 |
3745 | 3751 |
assert len(resp.json['data']) == 2 |
3746 | 3752 |
assert resp.json['data'] == [ |
... | ... | |
4413 | 4419 |
assert 'text' in item |
4414 | 4420 | |
4415 | 4421 | |
4416 | 4422 |
def test_read_school_list_address_and_level_soap_error(site_service, con, app): |
4417 | 4423 |
site_service.add_soap_response( |
4418 | 4424 |
'readSchoolForAdressAndLevel', get_xml_file('R_read_school_for_adress_and_level_soap_error.xml'), status=500, |
4419 | 4425 |
) |
4420 | 4426 |
url = get_endpoint('read-schools-for-address-and-level') |
4421 |
resp = app.get(url, params={'id_street': '', 'num': '', 'year': ''})
|
|
4422 |
assert resp.json['err'] == 'Site-readSchoolForAdressAndLevel-soap:Server'
|
|
4427 |
with pytest.raises(TypeError, match='Object of type _Element is not JSON serializable') as e:
|
|
4428 |
resp = app.get(url, params={'id_street': '', 'num': '', 'year': ''})
|
|
4423 | 4429 | |
4424 | 4430 | |
4425 | 4431 |
def test_read_school_list_child_and_level(family_service, con, app): |
4426 | 4432 |
family_service.add_soap_response( |
4427 | 4433 |
'readSchoolForChildAndLevel', get_xml_file('R_read_school_for_child_and_level.xml') |
4428 | 4434 |
) |
4429 | 4435 |
url = get_endpoint('read-schools-for-child-and-level') |
4430 | 4436 |
resp = app.get(url, params={'child_id': '190115', 'year': '2023'}) |
4431 |
- |