Skip to content

Commit

Permalink
Support process SOAP 1.2 Fault reply
Browse files Browse the repository at this point in the history
  • Loading branch information
eshizhan committed Apr 24, 2024
1 parent 7924301 commit 4c93ed9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
7 changes: 7 additions & 0 deletions suds/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
26 changes: 24 additions & 2 deletions tests/test_reply_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("""\
<xsd:element name="fResponse" type="xsd:string"/>""",
Expand All @@ -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, """<?xml version="1.0"?>
response_bare = get_response(client_bare, """\
<?xml version="1.0"?>
<Envelope xmlns="http://www.w3.org/2003/05/soap-envelope">
<Body>
<fResponse xmlns="my-namespace">%s</fResponse>
Expand All @@ -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("""\
<?xml version="1.0"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<env:Body>
<env:Fault>
<faultcode>env:Client</faultcode>
<faultstring>Dummy error.</faultstring>
</env:Fault>
</env:Body>
</env:Envelope>
"""), 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()
Expand Down

0 comments on commit 4c93ed9

Please sign in to comment.