def test_raise_invalid_port(self): app = build_app([TBadRPCPortService()], 'MisingPortTns', 'MissingPortApp') interface_doc = Wsdl11(app.interface) self.assertRaises(ValueError, interface_doc.build_interface_document, self.url) app = build_app( [TBadRPCPortService(), TSinglePortService()], 'MissingPort2Tns', 'MissingPortApp') interface_doc = Wsdl11(app.interface) self.assertRaises(ValueError, interface_doc.build_interface_document, self.url)
def __handle_wsdl_request(self, request): ctx = HttpMethodContext(self.http_transport, request, "text/xml; charset=utf-8") url = _reconstruct_url(request) try: ctx.transport.wsdl = self._wsdl if ctx.transport.wsdl is None: from spyne.interface.wsdl.wsdl11 import Wsdl11 wsdl = Wsdl11(self.http_transport.app.interface) wsdl.build_interface_document(url) self._wsdl = ctx.transport.wsdl = wsdl.get_interface_document() assert ctx.transport.wsdl != None self.http_transport.event_manager.fire_event('wsdl', ctx) for k, v in ctx.transport.resp_headers.items(): if isinstance(v, (list, tuple)): for v2 in v: request.setHeader(k, v2) else: request.setHeader(k, v) return ctx.transport.wsdl except Exception, e: ctx.transport.wsdl_error = e self.http_transport.event_manager.fire_event('wsdl_exception', ctx) raise
def test_binding_simple(self): sa = build_app([TS1()], 'S1Port', 'TestServiceName') interface_doc = Wsdl11(sa.interface) interface_doc.build_interface_document(self.url) services = interface_doc.root_elt.xpath( '/wsdl:definitions/wsdl:service', namespaces = { 'wsdl':'http://schemas.xmlsoap.org/wsdl/' }) self.assertEqual(len(services), 1) portTypes = interface_doc.root_elt.xpath( '/wsdl:definitions/wsdl:portType', namespaces = { 'wsdl':'http://schemas.xmlsoap.org/wsdl/' }) self.assertEqual(len(portTypes), 1) ports = interface_doc.root_elt.xpath( '/wsdl:definitions/wsdl:service[@name="%s"]/wsdl:port' % "S1", namespaces = { 'wsdl':'http://schemas.xmlsoap.org/wsdl/' }) self.assertEqual(len(ports), 1)
def test_port_count(self): sa = build_app([TSinglePortService()], 'tns', name='SinglePortApp') wsdl = Wsdl11(sa.interface) wsdl.build_interface_document(self.url) sa_wsdl_el = wsdl.root_elt self.assertEquals(1, len(sa_wsdl_el.findall(self.port_type_string))) pl = sa_wsdl_el.findall(self.port_type_string) self.assertEqual(1, len(pl)) da = build_app([TDoublePortService()], 'tns', name='DoublePortApp') wsdl = Wsdl11(da.interface) wsdl.build_interface_document(self.url) from lxml import etree print(etree.tostring(wsdl.root_elt, pretty_print=True)) self.assertEquals(2, len(wsdl.root_elt.findall(self.port_type_string)))
def setUp(self): self.app = Application([SomeService], 'tns', in_protocol=Soap11(), out_protocol=Soap11()) self.app.transport = 'test' self.server = WsgiApplication(self.app) self.wsdl = Wsdl11(self.app.interface) self.wsdl.build_interface_document('prot://url')
def test_raise_missing_port(self): # Test that an exception is raised when a port is declared in the service class # but the rpc method does not declare a port. app = build_app([TMissingRPCPortService()], 'MisingPortTns', 'MissingPortApp') interface_doc = Wsdl11(app.interface) self.assertRaises(ValueError, interface_doc.build_interface_document, self.url) app = build_app([TSinglePortService(), TMissingRPCPortService()], 'MissingPort2Tns', 'MissingPort2App') interface_doc = Wsdl11(app.interface) self.assertRaises(ValueError, interface_doc.build_interface_document, self.url)
def test_tns(self): sa = build_app([TSinglePortService()], 'SinglePort', 'TestServiceName') wsdl = Wsdl11(sa.interface) wsdl.build_interface_document(self.url) sa_el = wsdl.root_elt tns = sa_el.get('targetNamespace') self.assertEqual('SinglePort', tns) sa = build_app( [TSinglePortService(), TDoublePortService()], 'MultiServiceTns', 'AppName') wsdl = Wsdl11(sa.interface) wsdl.build_interface_document(self.url) tns = wsdl.root_elt.get('targetNamespace') self.assertEqual(tns, 'MultiServiceTns')
def test_port_name(self): sa = build_app([TSinglePortService()], 'tns', name='SinglePortApp') wsdl = Wsdl11(sa.interface) wsdl.build_interface_document(self.url) sa_wsdl_el = wsdl.root_elt pl = sa_wsdl_el.findall(self.port_type_string) print(('\n', pl, pl[0].attrib)) self.assertEqual('FirstPortType', pl[0].get('name')) da = build_app([TDoublePortService()], 'tns', name='DoublePortApp') wsdl = Wsdl11(da.interface) wsdl.build_interface_document(self.url) da_wsdl_el = wsdl.root_elt pl2 = da_wsdl_el.findall(self.port_type_string) self.assertEqual('FirstPort', pl2[0].get('name')) self.assertEqual('SecondPort', pl2[1].get('name'))
def test_service_name(self): sa = build_app([TSinglePortService()], 'SinglePort', 'TestServiceName') wsdl = Wsdl11(sa.interface) wsdl.build_interface_document(self.url) sa_el = wsdl.root_elt sl = [s for s in sa_el.iterfind(self.service_string)] name = sl[0].get('name') print((len(sl))) self.assertEqual('SinglePortService_ServiceInterface', name)
def test_binding_multiple(self): SinglePortService, DoublePortService = TSinglePortService( ), TDoublePortService() sa = build_app([SinglePortService, DoublePortService], 'MultiServiceTns', 'AppName') interface_doc = Wsdl11(sa.interface) interface_doc.build_interface_document(self.url) # 2 Service, # First has 1 port # Second has 2 # => need 2 service, 3 port and 3 bindings services = interface_doc.root_elt.xpath( '/wsdl:definitions/wsdl:service', namespaces={'wsdl': 'http://schemas.xmlsoap.org/wsdl/'}) self.assertEqual(len(services), 2) portTypes = interface_doc.root_elt.xpath( '/wsdl:definitions/wsdl:portType', namespaces={'wsdl': 'http://schemas.xmlsoap.org/wsdl/'}) self.assertEqual(len(portTypes), 3) bindings = interface_doc.root_elt.xpath( '/wsdl:definitions/wsdl:binding', namespaces={'wsdl': 'http://schemas.xmlsoap.org/wsdl/'}) self.assertEqual(len(bindings), 3) ports = interface_doc.root_elt.xpath( '/wsdl:definitions/wsdl:service[@name="%s"]/wsdl:port' % SinglePortService.__service_name__, namespaces={'wsdl': 'http://schemas.xmlsoap.org/wsdl/'}) self.assertEqual(len(ports), 1) ports = interface_doc.root_elt.xpath( '/wsdl:definitions/wsdl:service[@name="%s"]/wsdl:port' % "DoublePortService", namespaces={'wsdl': 'http://schemas.xmlsoap.org/wsdl/'}) self.assertEqual(len(ports), 2) # checking name and type #service SinglePortService for srv in (SinglePortService, DoublePortService): for port in srv.__port_types__: bindings = interface_doc.root_elt.xpath( '/wsdl:definitions/wsdl:binding[@name="%s"]' % port, namespaces={'wsdl': 'http://schemas.xmlsoap.org/wsdl/'}) self.assertEqual(bindings[0].get('type'), "tns:%s" % port)
def __init__(self): info_app = Application([InfoServer], tns=SOAP_NAMESPACE, name='InfoService', interface=Wsdl11(), in_protocol=Soap11(), out_protocol=Soap11()) info_app.event_manager.add_listener('wsgi_close', shutdown_session) list_app = Application([ListServer], tns=SOAP_NAMESPACE, name='ListService', interface=Wsdl11(), in_protocol=Soap11(), out_protocol=Soap11()) list_app.event_manager.add_listener('wsgi_close', shutdown_session) schedule_app = Application([ScheduleServer], tns=SOAP_NAMESPACE, name='ScheduleService', interface=Wsdl11(), in_protocol=Soap11(), out_protocol=Soap11()) schedule_app.event_manager.add_listener('wsgi_close', shutdown_session) epgu_gate_app = Application([EPGUGateServer], tns='http://erGateService.er.atc.ru/ws', name='GateService', interface=Wsdl11(), in_protocol=Soap11(), out_protocol=Soap11()) epgu_gate_app.event_manager.add_listener('wsgi_close', shutdown_session) self.applications = CustomWsgiMounter({ 'info': info_app, 'list': list_app, 'schedule': schedule_app, 'gate': epgu_gate_app, })