Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support process SOAP 1.2 Fault reply #99

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions suds/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,10 +869,12 @@ def __get_fault(self, replyroot):
@rtype: L{Object}

"""
envns = suds.bindings.binding.envns
soapenv = replyroot and replyroot.getChild("Envelope", envns)
soapbody = soapenv and soapenv.getChild("Body", envns)
fault = soapbody and soapbody.getChild("Fault", envns)
def get_fault(envns):
soapenv = replyroot and replyroot.getChild("Envelope", envns)
soapbody = soapenv and soapenv.getChild("Body", envns)
return soapbody and soapbody.getChild("Fault", envns)

fault = get_fault(suds.bindings.binding.envns) or get_fault(suds.bindings.binding.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
eshizhan marked this conversation as resolved.
Show resolved Hide resolved


def _attributes(object):
result = set()
Expand Down
Loading