From 4c93ed933a363473a4db4a1df0e747604b8155f7 Mon Sep 17 00:00:00 2001 From: eshizhan Date: Thu, 25 Apr 2024 02:07:57 +0800 Subject: [PATCH] Support process SOAP 1.2 Fault reply --- suds/client.py | 7 +++++++ tests/test_reply_handling.py | 26 ++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/suds/client.py b/suds/client.py index b65ebd8a..53041715 100644 --- a/suds/client.py +++ b/suds/client.py @@ -870,9 +870,16 @@ def __get_fault(self, replyroot): """ envns = suds.bindings.binding.envns + envns12 = suds.bindings.binding.envns12 soapenv = replyroot and replyroot.getChild("Envelope", envns) + if not soapenv: + soapenv = replyroot and replyroot.getChild("Envelope", envns12) soapbody = soapenv and soapenv.getChild("Body", envns) + if not soapbody: + soapbody = soapenv and soapenv.getChild("Body", envns12) fault = soapbody and soapbody.getChild("Fault", envns) + if not fault: + fault = soapbody and soapbody.getChild("Fault", envns12) return fault is not None and UmxBasic().process(fault) def __headers(self): diff --git a/tests/test_reply_handling.py b/tests/test_reply_handling.py index 83820b3d..b9f46b78 100644 --- a/tests/test_reply_handling.py +++ b/tests/test_reply_handling.py @@ -481,7 +481,9 @@ def test_wrapped_sequence_output(): assert response.result3.__class__ is suds.sax.text.Text -def test_soap12_envns(): +def test_soap12_envns(monkeypatch): + monkeypatch.delitem(locals(), "e", False) + # Prepare web service proxies. client_bare = testutils.client_from_wsdl(testutils.wsdl("""\ """, @@ -493,7 +495,8 @@ def test_soap12_envns(): def get_response(client, x): return client.service.f(__inject=dict(reply=suds.byte_str(x))) # Envelope namespace URI is SOAP 1.2 - response_bare = get_response(client_bare, """ + response_bare = get_response(client_bare, """\ + %s @@ -502,6 +505,25 @@ def get_response(client, x): assert response_bare.__class__ is suds.sax.text.Text assert response_bare == data + inject = dict(reply=suds.byte_str("""\ + + + + + env:Client + Dummy error. + + + +"""), status=http.client.INTERNAL_SERVER_ERROR) + e = pytest.raises(suds.WebFault, client_bare.service.f, __inject=inject).value + try: + _test_fault(e.fault, False) + assert e.document.__class__ is suds.sax.document.Document + assert str(e) == "Server raised fault: 'Dummy error.'" + finally: + del e # explicitly break circular reference chain in Python 3 + def _attributes(object): result = set()