def test_bare_simple(self): class SomeService(Service): @srpc(String, _returns=String, _body_style='bare') def whatever(ss): return ss app = Application([SomeService], tns='tns') app.transport = 'None' wsdl = Wsdl11(app.interface) wsdl.build_interface_document('url') wsdl = etree.fromstring(wsdl.get_interface_document()) schema = wsdl.xpath( '/wsdl:definitions/wsdl:types/xs:schema[@targetNamespace="tns"]', namespaces=ns, ) assert len(schema) == 1 print(etree.tostring(wsdl, pretty_print=True)) elts = schema[0].xpath( 'xs:element[@name="whatever%s"]' % REQUEST_SUFFIX, namespaces=ns) assert len(elts) > 0 assert elts[0].attrib['type'] == 'xs:string' elts = schema[0].xpath( 'xs:element[@name="whatever%s"]' % RESPONSE_SUFFIX, namespaces=ns) assert len(elts) > 0 assert elts[0].attrib['type'] == 'xs:string'
def test_bare_with_conflicting_types(self): class SomeService(Service): @srpc(Array(String), _returns=Array(String)) def whatever(sa): return sa @srpc(Array(String), _returns=Array(String), _body_style='bare') def whatever_bare(sa): return sa app = Application([SomeService], tns='tns') app.transport = 'None' wsdl = Wsdl11(app.interface) wsdl.build_interface_document('url') wsdl = etree.fromstring(wsdl.get_interface_document()) schema, = wsdl.xpath( '/wsdl:definitions/wsdl:types/xs:schema[@targetNamespace="tns"]', namespaces=ns, ) print(etree.tostring(schema, pretty_print=True)) assert len(schema.xpath( 'xs:complexType[@name="string%s"]' % ARRAY_SUFFIX, namespaces=ns)) > 0 elts = schema.xpath( 'xs:element[@name="whatever_bare%s"]' % REQUEST_SUFFIX, namespaces=ns) assert len(elts) > 0 assert elts[0].attrib['type'] == 'tns:string%s' % ARRAY_SUFFIX elts = schema.xpath( 'xs:element[@name="whatever_bare%s"]' % RESPONSE_SUFFIX, namespaces=ns) assert len(elts) > 0 assert elts[0].attrib['type'] == 'tns:string%s' % ARRAY_SUFFIX
def test_attribute_of(self): class SomeObject(ComplexModel): c = String a = XmlAttribute(Integer, attribute_of='c') class SomeService(ServiceBase): @srpc(SomeObject) def echo_simple_bare(ss): pass app = Application([SomeService], tns='tns', in_protocol=Soap11(), out_protocol=Soap11()) app.transport = 'None' wsdl = Wsdl11(app.interface) wsdl.build_interface_document('url') wsdl = etree.fromstring(wsdl.get_interface_document()) print(etree.tostring(wsdl, pretty_print=True)) assert len( wsdl.xpath( "/wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='%s']" "/xs:complexType[@name='SomeObject']/xs:sequence/xs:element[@name='c']" '/xs:complexType/xs:simpleContent/xs:extension/xs:attribute[@name="a"]' % (SomeObject.get_namespace()), namespaces=const_nsmap)) > 0
def test_bare(self): ns = { 'wsdl':'http://schemas.xmlsoap.org/wsdl/', 'xs':'http://www.w3.org/2001/XMLSchema', } class InteropBare(ServiceBase): @srpc(String, _returns=String, _body_style='bare') def echo_simple_bare(ss): return ss @srpc(Array(String), _returns=Array(String), _body_style='bare') def echo_complex_bare(ss): return ss app = Application([InteropBare], tns='tns', in_protocol=Soap11(), out_protocol=Soap11()) app.transport = 'None' wsdl = Wsdl11(app.interface) wsdl.build_interface_document('url') wsdl = etree.fromstring(wsdl.get_interface_document()) schema = wsdl.xpath( '/wsdl:definitions/wsdl:types/xs:schema[@targetNamespace]', namespaces=ns ) assert len(schema[0].xpath( 'xs:complexType[@name="string%s"]' % ARRAY_SUFFIX, namespaces=ns)) > 0 elts = schema[0].xpath( 'xs:element[@name="echo_complex_bare%s"]' % RESPONSE_SUFFIX, namespaces=ns) assert len(elts) > 0 assert elts[0].attrib['type'] == 'tns:stringArray'
def build_app(service_list, tns, name): app = Application(service_list, tns, name=name, in_protocol=Soap11(), out_protocol=Soap11()) app.transport = 'http://schemas.xmlsoap.org/soap/http' return app
def test_bare_more(self): from spyne.test.interop.server._service import InteropBare app = Application([InteropBare], tns='tns', in_protocol=Soap11(), out_protocol=Soap11()) app.transport = 'None' wsdl = Wsdl11(app.interface) wsdl.build_interface_document('url') wsdl = etree.fromstring(wsdl.get_interface_document()) print etree.tostring(wsdl, pretty_print=True) assert len(wsdl.xpath('//xs:element[@name="echo_simple_bare"]', namespaces=const_nsmap)) == 1
def test_bare(self): ns = { 'wsdl': 'http://schemas.xmlsoap.org/wsdl/', 'xs': 'http://www.w3.org/2001/XMLSchema', } from spyne.model.complex import Array from spyne.model.primitive import String from spyne.protocol.soap import Soap11 from spyne.service import ServiceBase from spyne.decorator import srpc from spyne.interface.wsdl import Wsdl11 from lxml import etree class InteropBare(ServiceBase): @srpc(String, _returns=String, _body_style='bare') def echo_simple_bare(ss): return ss @srpc(Array(String), _returns=Array(String), _body_style='bare') def echo_complex_bare(ss): return ss app = Application([InteropBare], tns='tns', in_protocol=Soap11(), out_protocol=Soap11()) app.transport = 'None' wsdl = Wsdl11(app.interface) wsdl.build_interface_document('url') wsdl = etree.fromstring(wsdl.get_interface_document()) schema = wsdl.xpath( '/wsdl:definitions/wsdl:types/xs:schema[@targetNamespace]', namespaces=ns) assert len( schema[0].xpath('xs:complexType[@name="string%s"]' % ARRAY_SUFFIX, namespaces=ns)) > 0 elts = schema[0].xpath('xs:element[@name="echo_complex_bare%s"]' % RESPONSE_SUFFIX, namespaces=ns) assert len(elts) > 0 assert elts[0].attrib['type'] == 'tns:stringArray'
def test_attribute_of(self): class SomeObject(ComplexModel): c = String a = XmlAttribute(Integer, attribute_of='c') class SomeService(ServiceBase): @srpc(SomeObject) def echo_simple_bare(ss): pass app = Application([SomeService], tns='tns', in_protocol=Soap11(), out_protocol=Soap11()) app.transport = 'None' wsdl = Wsdl11(app.interface) wsdl.build_interface_document('url') wsdl = etree.fromstring(wsdl.get_interface_document()) print(etree.tostring(wsdl, pretty_print=True)) assert len(wsdl.xpath( "/wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='%s']" "/xs:complexType[@name='SomeObject']/xs:sequence/xs:element[@name='c']" '/xs:complexType/xs:simpleContent/xs:extension/xs:attribute[@name="a"]' % (SomeObject.get_namespace()), namespaces=const_nsmap)) > 0
def build_app(service_list, tns, name): app = Application(service_list, tns, Wsdl11(), Soap11(), Soap11(), name=name) app.transport = 'http://schemas.xmlsoap.org/soap/http' return app
#!/usr/bin/env python from lxml import etree from spyne.test.sort_wsdl import sort_wsdl from spyne.interface.wsdl import Wsdl11 from spyne.test.interop.server._service import services from spyne.application import Application app = Application(services, 'spyne.test.interop.server') app.transport = 'http://schemas.xmlsoap.org/soap/http' wsdl = Wsdl11(app.interface) wsdl.build_interface_document('http://localhost:9754/') elt = etree.ElementTree(etree.fromstring(wsdl.get_interface_document())) sort_wsdl(elt) s = etree.tostring(elt) # minidom's serialization seems to put attributes in alphabetic order. # this is exactly what we want here. from xml.dom.minidom import parseString doc = parseString(s) s = doc.toprettyxml(indent=' ', newl='\n', encoding='utf8') s = s.replace(" xmlns:","\n xmlns:") open('wsdl.xml', 'w').write(s) print 'wsdl.xml written'