API¶
Public Interface¶
-
soap.
get_client
(wsdl, log_prefix, plugins=[], **kwargs)[source]¶ Get a SOAP Client object for the given WSDL. Client objects are cached in
soap.clients
and keyed by the WSDL URL.- Parameters
wsdl – String URL of a SOAP WSDL
log_prefix – String prefix to prepend to log lines (when logging XML traffic in DEBUG mode)
plugins – List of additional plugins
suds.plugin.Plugin
to pass on to thesuds.client.Client
object.kwargs – Optional keyword arguments to pass on to the
suds.client.Client
object
- Returns
suds.client.Client
object- Return type
suds.client.Client
Transports¶
-
class
soap.http.
HttpTransport
[source]¶ Custom HTTPTransport to replace
suds.transport.http.HttpTransport
.The default
suds.transport.http.HttpTransport
class has issues with sending SOAP traffic through HTTP proxies like Squid. This Transport fixes the HTTP Proxy issues by using python-requests instead of urllib2.-
open
(request)[source]¶ Open a SOAP WSDL
- Parameters
request –
suds.transport.Request
object- Returns
WSDL Content as a file-like object
- Return type
io.BytesIO
-
open_timeout
= (3.05, 27)¶ Timeout for opening a WSDL file. Tuple (CONNECT_TIMEOUT, READ_TIMEOUT)
-
proxies
(url)[source]¶ Get the transport proxy configuration
- Parameters
url – string
- Returns
Proxy configuration dictionary
- Return type
Dictionary
-
send
(request)[source]¶ Send a SOAP method call
- Parameters
request –
suds.transport.Request
object- Returns
suds.transport.Reply
object- Return type
suds.transport.Reply
-
send_timeout
= (3.05, 10)¶ Timeout for sending a SOAP call. Tuple (CONNECT_TIMEOUT, READ_TIMEOUT)
-
Django Settings¶
-
soap.settings.
DEBUG
= True¶ Enables Suds request/response logging Set Django
settings.DEBUG
to override.
-
soap.settings.
REMOVE_CACHE_ON_EXIT
= False¶ Remove the Suds file cache of pickled WSDLs upon process exit Set Django
settings.SOAP_REMOVE_CACHE_ON_EXIT
to override.
-
soap.settings.
WSDL_INTERCEPTS
= {}¶ Optional mapping of
http(s)://
WSDL URLs =>file://
URLs to locally saved versions of the WSDL. Set Djangosettings.SOAP_WSDL_INTERCEPTS
to override.
-
soap.settings.
PROXY_URL
= None¶ Optional HTTP/HTTPS proxy URL DEPRECATED: Use SOAP_PROXIES instead Set Django
settings.SOAP_PROXY_URL
to override.
-
soap.settings.
OPEN_TIMEOUT
= (3.05, 27)¶ Timeout for opening WSDLs. Should be a tuple containing (1) the TCP connect timeout and (2) the response timeout. Set Django
settings.SOAP_OPEN_TIMEOUT
to override.
-
soap.settings.
SEND_TIMEOUT
= (3.05, 10)¶ Timeout for sending SOAP method calls. Should be a tuple containing (1) the TCP connect timeout and (2) the response timeout. Set Django
settings.SOAP_SEND_TIMEOUT
to override.
Logging¶
Testing Hooks¶
-
soap.
clients
= {}¶ Cache of
suds.client.Client
objects When unit-testing SOAP APIs it’s probably wise to reset this to an empty dictionary in-between tests.
-
soap.
get_transport
()[source]¶ Build a new
soap.http.HttpTransport
object. Unit tests can patch this function to return a custom transport object for the client to use. This can be useful when trying to mock an API rather than actually call it during a test.- Returns
soap.http.HttpTransport
object- Return type
Testing Utilities¶
-
class
soap.tests.
XMLAssertions
[source]¶ Unit test mixin to add XPath assertions on XML data.
-
assertNodeAttributes
(xml_str, xpath, attributes)[source]¶ Assert that each node returned by the XPath has each of the given attributes and attribute values.
- Parameters
xml_str – XML to test
xpath – XPath query to run
expected – Dictionary of attribute names and their expected values
-
-
class
soap.tests.
SoapTest
[source]¶ Subclass of
soap.tests.XMLAssertions
that adds behavior useful for mocking and testing a SOAP API at the XML level.-
_build_transport_with_reply
(body, status=200, pattern=None, test_request=None)[source]¶ Build a fake
soap.http.HttpTransport
that, when called, will reply with the given XML body and status code.- Parameters
body – XML response data as bytes.
status – HTTP status code to return.
pattern – Optional. Regexp pattern to match against the request URL. Useful if your test communicates with multiple SOAP APIs that need different mock responses.
test_request – Optional. Function to call with a request object, before returning the response. Can use this to run assertions on the SOAP request XML.
- Returns
soap.http.HttpTransport
object- Return type
-
setUp
()[source]¶ Test Setup. Clears the
soap.clients
cache.
-