本文整理汇总了Python中testutils.wsdl函数的典型用法代码示例。如果您正苦于以下问题:Python wsdl函数的具体用法?Python wsdl怎么用?Python wsdl使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wsdl函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_bare_input_restriction_types
def test_bare_input_restriction_types():
client_unnamed = testutils.client_from_wsdl(testutils.wsdl("""\
<xsd:element name="Elemento">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="alfa"/>
<xsd:enumeration value="beta"/>
<xsd:enumeration value="gamma"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>""", input="Elemento", operation_name="f"))
client_named = testutils.client_from_wsdl(testutils.wsdl("""\
<xsd:simpleType name="MyType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="alfa"/>
<xsd:enumeration value="beta"/>
<xsd:enumeration value="gamma"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="Elemento" type="ns:MyType"/>""", input="Elemento",
operation_name="f"))
assert not _is_input_wrapped(client_unnamed, "f")
assert not _is_input_wrapped(client_named, "f")
示例2: test_wrapped_sequence_output
def test_wrapped_sequence_output():
client = testutils.lxmlclient_from_wsdl(testutils.wsdl("""\
<xsd:element name="Wrapper">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="result1" type="xsd:string"/>
<xsd:element name="result2" type="xsd:string"/>
<xsd:element name="result3" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>""", output="Wrapper"))
response = client.service.f(__inject=dict(reply=suds.byte_str("""\
<?xml version="1.0"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<Wrapper xmlns="my-namespace">
<result1>Uno</result1>
<result2>Due</result2>
<result3>Tre</result3>
</Wrapper>
</Body>
</Envelope>""")))
# Check response content.
assert len(response) == 3
assert response.result1 == "Uno"
assert response.result2 == "Due"
assert response.result3 == "Tre"
assert_lxml_string_value(response.result1)
assert_lxml_string_value(response.result2)
assert_lxml_string_value(response.result3)
client = testutils.lxmlclient_from_wsdl(testutils.wsdl("""\
<xsd:element name="Wrapper">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="result1" type="xsd:string"/>
<xsd:element name="result2" type="xsd:string"/>
<xsd:element name="result3" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>""", output="Wrapper"))
response = client.service.f(__inject=dict(reply=suds.byte_str("""\
<?xml version="1.0"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<Wrapper xmlns="my-namespace">
</Wrapper>
</Body>
</Envelope>""")))
# Check response content.
assert len(response) == 3
assert response.result1 is None
assert response.result2 is None
assert response.result3 is None
示例3: test_restriction_data_types
def test_restriction_data_types():
client_unnamed = testutils.client_from_wsdl(testutils.wsdl("""\
<xsd:element name="Elemento">
<xsd:simpleType>
<xsd:restriction base="xsd:int">
<xsd:enumeration value="1"/>
<xsd:enumeration value="3"/>
<xsd:enumeration value="5"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>""", output="Elemento"))
client_named = testutils.client_from_wsdl(testutils.wsdl("""\
<xsd:simpleType name="MyType">
<xsd:restriction base="xsd:int">
<xsd:enumeration value="1"/>
<xsd:enumeration value="3"/>
<xsd:enumeration value="5"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="Elemento" type="ns:MyType"/>""", output="Elemento"))
client_twice_restricted = testutils.client_from_wsdl(testutils.wsdl("""\
<xsd:simpleType name="MyTypeGeneric">
<xsd:restriction base="xsd:int">
<xsd:enumeration value="1"/>
<xsd:enumeration value="2"/>
<xsd:enumeration value="3"/>
<xsd:enumeration value="4"/>
<xsd:enumeration value="5"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="MyType">
<xsd:restriction base="ns:MyTypeGeneric">
<xsd:enumeration value="1"/>
<xsd:enumeration value="3"/>
<xsd:enumeration value="5"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="Elemento" type="ns:MyType"/>""", output="Elemento"))
for client in (client_unnamed, client_named, client_twice_restricted):
response = client.service.f(__inject=dict(reply=suds.byte_str("""\
<?xml version="1.0"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<Elemento xmlns="my-namespace">5</Elemento>
</Body>
</Envelope>""")))
assert response.__class__ is int
assert response == 5
示例4: test_enum
def test_enum():
client = testutils.lxmlclient_from_wsdl(testutils.wsdl("""\
<xsd:element name="Wrapper">
<xsd:element name="Size">
<xsd:simpleType name="DataSize">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="1" />
<xsd:enumeration value="2"/>
<xsd:enumeration value="3"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:element>""", output="Wrapper"))
response = client.service.f(__inject=dict(reply=suds.byte_str("""\
<?xml version="1.0"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<Wrapper xmlns="my-namespace">
<DataSize>1</DataSize>
</Wrapper>
</Body>
</Envelope>""")))
# Check response content.
assert len(response) == 1
assert response.size == 1
示例5: test_disabling_automated_simple_interface_unwrapping
def test_disabling_automated_simple_interface_unwrapping():
client = testutils.client_from_wsdl(testutils.wsdl("""\
<xsd:element name="Wrapper">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Elemento" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>""", output="Wrapper"), unwrap=False)
assert not _isOutputWrapped(client, "f")
response = client.service.f(__inject=dict(reply=suds.byte_str("""\
<?xml version="1.0"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<Wrapper xmlns="my-namespace">
<Elemento>La-di-da-da-da</Elemento>
</Wrapper>
</Body>
</Envelope>""")))
assert response.__class__.__name__ == "Wrapper"
assert len(response.__class__.__bases__) == 1
assert response.__class__.__bases__[0] is suds.sudsobject.Object
assert response.Elemento.__class__ is suds.sax.text.Text
assert response.Elemento == "La-di-da-da-da"
示例6: test_avoid_external_XSD_fetching
def test_avoid_external_XSD_fetching(self):
# Prepare document content.
xsd_target_namespace = "balancana"
wsdl = testutils.wsdl("""\
<xsd:import schemaLocation="suds://imported_xsd"/>
<xsd:include schemaLocation="suds://included_xsd"/>""",
xsd_target_namespace=xsd_target_namespace)
external_xsd_format = """\
<?xml version='1.0' encoding='UTF-8'?>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<element name="external%d" type="string"/>
</schema>"""
external_xsd1 = b(external_xsd_format % (1,))
external_xsd2 = b(external_xsd_format % (2,))
# Add to cache.
cache = MockCache()
store1 = MockDocumentStore(wsdl=wsdl, imported_xsd=external_xsd1,
included_xsd=external_xsd2)
c1 = suds.client.Client("suds://wsdl", cachingpolicy=1,
cache=cache, documentStore=store1, transport=MockTransport())
assert store1.mock_log == ["suds://wsdl", "suds://imported_xsd",
"suds://included_xsd"]
assert len(cache.mock_data) == 1
wsdl_object_id, wsdl_object = next(iteritems(cache.mock_data))
assert wsdl_object.__class__ is suds.wsdl.Definitions
# Reuse from cache.
cache.mock_log = []
store2 = MockDocumentStore(wsdl=wsdl)
c2 = suds.client.Client("suds://wsdl", cachingpolicy=1,
cache=cache, documentStore=store2, transport=MockTransport())
assert cache.mock_log == [("get", [wsdl_object_id])]
assert store2.mock_log == []
示例7: test_error_on_send__non_transport
def test_error_on_send__non_transport(self):
e = MyException()
t = MockTransport(send_data=e)
store = MockDocumentStore(wsdl=testutils.wsdl("", operation_name="g"))
client = suds.client.Client("suds://wsdl", documentStore=store,
cache=None, transport=t)
assert pytest.raises(MyException, client.service.g).value is e
示例8: test_operation_request_and_reply
def test_operation_request_and_reply(self):
xsd_content = '<xsd:element name="Data" type="xsd:string"/>'
web_service_URL = "Great minds think alike"
xsd_target_namespace = "omicron psi"
wsdl = testutils.wsdl(xsd_content, operation_name="pi",
xsd_target_namespace=xsd_target_namespace, input="Data",
output="Data", web_service_URL=web_service_URL)
test_input_data = "Riff-raff"
test_output_data = "La-di-da-da-da"
store = MockDocumentStore(wsdl=wsdl)
transport = MockTransport(send_data=b("""\
<?xml version="1.0"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<Data xmlns="%s">%s</Data>
</env:Body>
</env:Envelope>""" % (xsd_target_namespace, test_output_data)))
client = suds.client.Client("suds://wsdl", documentStore=store,
cache=None, transport=transport)
assert transport.mock_log == []
reply = client.service.pi(test_input_data)
assert len(transport.mock_log) == 1
assert transport.mock_log[0][0] == "send"
assert transport.mock_log[0][1][0] == web_service_URL
request_message = transport.mock_log[0][1][1]
assert b(xsd_target_namespace) in request_message
assert b(test_input_data) in request_message
assert reply == test_output_data
示例9: test_disabling_automated_simple_interface_unwrapping
def test_disabling_automated_simple_interface_unwrapping():
xsd_target_namespace = "woof"
wsdl = testutils.wsdl(
"""\
<xsd:element name="Wrapper">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Elemento" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>""",
input="Wrapper",
operation_name="f",
xsd_target_namespace=xsd_target_namespace,
)
client = testutils.client_from_wsdl(wsdl, nosend=True, prettyxml=True, unwrap=False)
assert not _is_input_wrapped(client, "f")
element_data = "Wonderwall"
wrapper = client.factory.create("my_xsd:Wrapper")
wrapper.Elemento = element_data
_assert_request_content(
client.service.f(Wrapper=wrapper),
"""\
<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Header/>
<Body>
<Wrapper xmlns="%s">
<Elemento>%s</Elemento>
</Wrapper>
</Body>
</Envelope>"""
% (xsd_target_namespace, element_data),
)
示例10: test_twice_wrapped_parameter
def test_twice_wrapped_parameter():
"""
Suds does not recognize 'twice wrapped' data structures and unwraps the
external one but keeps the internal wrapping structure in place.
"""
xsd_target_namespace = "spank me"
wsdl = testutils.wsdl("""\
<xsd:element name="Wrapper1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Wrapper2">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Elemento" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>""", input="Wrapper1", operation_name="f",
xsd_target_namespace=xsd_target_namespace)
client = testutils.client_from_wsdl(wsdl, nosend=True, prettyxml=True)
assert _is_input_wrapped(client, "f")
# Web service operation calls made with 'valid' parameters.
#
# These calls are actually illegal and result in incorrectly generated SOAP
# requests not matching the relevant WSDL schema. To make them valid we
# would need to pass a more complex value instead of a simple string, but
# the current simpler solution is good enough for what we want to test
# here.
value = "A B C"
expected_request = """\
<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Header/>
<Body>
<Wrapper1 xmlns="%s">
<Wrapper2>%s</Wrapper2>
</Wrapper1>
</Body>
</Envelope>""" % (xsd_target_namespace, value)
_assert_request_content(client.service.f(value), expected_request)
_assert_request_content(client.service.f(Wrapper2=value), expected_request)
# Web service operation calls made with 'invalid' parameters.
def test_invalid_parameter(**kwargs):
assert len(kwargs) == 1
keyword = next(iterkeys(kwargs))
expected = "f() got an unexpected keyword argument '%s'" % (keyword,)
e = pytest.raises(TypeError, client.service.f, **kwargs).value
try:
assert str(e) == expected
finally:
del e # explicitly break circular reference chain in Python 3
test_invalid_parameter(Elemento=value)
test_invalid_parameter(Wrapper1=value)
示例11: _create_dummy_schema
def _create_dummy_schema():
"""Constructs a new dummy XSD schema instance."""
#TODO: Find out how to construct this XSD schema object directly without
# first having to construct a suds.client.Client from a complete WSDL
# schema.
wsdl = testutils.wsdl('<xsd:element name="dummy"/>', input="dummy")
client = testutils.client_from_wsdl(wsdl)
return client.wsdl.schema
示例12: test_simple_bare_and_wrapped_output
def test_simple_bare_and_wrapped_output():
# Prepare web service proxies.
client_bare = testutils.client_from_wsdl(testutils.wsdl("""\
<xsd:element name="fResponse" type="xsd:string"/>""",
output="fResponse"))
client_wrapped = testutils.client_from_wsdl(testutils.wsdl("""\
<xsd:element name="Wrapper">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="fResponse" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>""", output="Wrapper"))
# Make sure suds library inteprets our WSDL definitions as wrapped or bare
# output interfaces as expected.
assert not _isOutputWrapped(client_bare, "f")
assert _isOutputWrapped(client_wrapped, "f")
# Both bare & wrapped single parameter output web service operation results
# get presented the same way even though the wrapped one actually has an
# extra wrapper element around its received output data.
data = "The meaning of life."
def get_response(client, x):
return client.service.f(__inject=dict(reply=suds.byte_str(x)))
response_bare = get_response(client_bare, """<?xml version="1.0"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<fResponse xmlns="my-namespace">%s</fResponse>
</Body>
</Envelope>""" % (data,))
assert response_bare.__class__ is suds.sax.text.Text
assert response_bare == data
response_wrapped = get_response(client_wrapped, """<?xml version="1.0"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<Wrapper xmlns="my-namespace">
<fResponse>%s</fResponse>
</Wrapper>
</Body>
</Envelope>""" % (data,))
assert response_wrapped.__class__ is suds.sax.text.Text
assert response_wrapped == data
示例13: test_error_on_send__transport
def test_error_on_send__transport(self, monkeypatch):
monkeypatch.delitem(locals(), "e", False)
t = MockTransport(send_data=suds.transport.TransportError("huku", 666))
store = MockDocumentStore(wsdl=testutils.wsdl("", operation_name="g"))
client = suds.client.Client("suds://wsdl", documentStore=store, cache=None, transport=t)
e = pytest.raises(Exception, client.service.g).value
try:
assert e.__class__ is Exception
assert e.args == ((666, "huku"),)
finally:
del e # explicitly break circular reference chain in Python 3
示例14: test_document_literal_request_for_single_element_input
def test_document_literal_request_for_single_element_input(xsd,
external_element_name, args, request_body):
wsdl = testutils.wsdl(xsd, input=external_element_name,
xsd_target_namespace="dr. Doolittle", operation_name="f")
client = testutils.client_from_wsdl(wsdl, nosend=True, prettyxml=True)
_assert_request_content(client.service.f(*args), """\
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body xmlns="dr. Doolittle">%s</SOAP-ENV:Body>
</SOAP-ENV:Envelope>""" % (request_body,))
示例15: test_external_XSD_transport
def test_external_XSD_transport(self, url, external_reference_tag):
xsd_content = '<xsd:%(tag)s schemaLocation="%(url)s"/>' % dict(
tag=external_reference_tag, url=url)
store = MockDocumentStore(wsdl=testutils.wsdl(xsd_content))
t = MockTransport(open_data=b("""\
<?xml version='1.0' encoding='UTF-8'?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"/>
"""))
suds.client.Client("suds://wsdl", cache=None, documentStore=store,
transport=t)
assert t.mock_log == [("open", [url])]