def setUp(self): self.app = Application([MultipleReturnService], 'tns', in_protocol=Soap12(), out_protocol=Soap12()) self.app.transport = 'none' self.wsdl = Wsdl11(self.app.interface) self.wsdl.build_interface_document('URL')
def test_fault_generation(self): class SoapException(ServiceBase): @srpc() def soap_exception(): raise Fault("Client.Plausible", "A plausible fault", 'http://faultactor.example.com') app = Application([SoapException], 'tns', in_protocol=Soap12(), out_protocol=Soap12()) req = b""" <soap12env:Envelope xmlns:soap12env="http://www.w3.org/2003/05/soap-envelope" xmlns:tns="tns"> <soap12env:Body> <tns:soap_exception/> </soap12env:Body> </soap12env:Envelope> """ server = WsgiApplication(app) response = etree.fromstring(b''.join( server( { 'QUERY_STRING': '', 'PATH_INFO': '/call', 'REQUEST_METHOD': 'POST', 'CONTENT_TYPE': 'text/xml; charset=utf8', 'wsgi.input': BytesIO(req) }, start_response, "http://null"))) response_str = etree.tostring(response, pretty_print=True) print(response_str) expected = b""" <soap12env:Envelope xmlns:soap12env="http://www.w3.org/2003/05/soap-envelope"> <soap12env:Body> <soap12env:Fault> <soap12env:Reason> <soap12env:Text xml:lang="en">A plausible fault</soap12env:Text> </soap12env:Reason> <soap12env:Role>http://faultactor.example.com</soap12env:Role> <soap12env:Code> <soap12env:Value>soap12env:Sender</soap12env:Value> <soap12env:Subcode> <soap12env:Value>Plausible</soap12env:Value> </soap12env:Subcode> </soap12env:Code> </soap12env:Fault> </soap12env:Body> </soap12env:Envelope>""" if not LXMLOutputChecker().check_output(expected, response_str, PARSE_XML): raise Exception("Got: %s but expected: %s" % (response_str, expected))
def setUp(self): self.app = Application([TestService], 'tns', in_protocol=Soap12(), out_protocol=Soap12()) self.app.transport = 'null.spyne' self.srv = TestService() wsdl = Wsdl11(self.app.interface) wsdl.build_interface_document('URL') self.wsdl_str = wsdl.get_interface_document() self.wsdl_doc = etree.fromstring(self.wsdl_str)
def test_mtom_join_envelope_chunks(self): FILE_NAME = 'EA055406-5881-4F02-A3DC-9A5A7510D018.dat' TNS = 'http://gib.gov.tr/vedop3/eFatura' # large enough payload to be chunked PAYLOAD = b"sample data " * 1024 class SomeService(Service): @rpc(Unicode(sub_name="fileName"), ByteArray(sub_name='binaryData'), ByteArray(sub_name="hash"), _returns=Unicode) def documentRequest(ctx, file_name, file_data, data_hash): assert file_name == FILE_NAME assert file_data == (PAYLOAD, ) return file_name app = Application([SomeService], tns=TNS, in_protocol=Soap12(), out_protocol=Soap12()) server = WsgiApplication(app, block_length=1024) response = etree.fromstring(b''.join( server( { 'QUERY_STRING': '', 'PATH_INFO': '/call', 'REQUEST_METHOD': 'POST', 'CONTENT_TYPE': 'Content-Type: multipart/related; ' 'type="application/xop+xml"; ' 'boundary="uuid:2e53e161-b47f-444a-b594-eb6b72e76997"; ' 'start="<*****@*****.**>"; ' 'start-info="application/soap+xml"; action="sendDocument"', 'wsgi.input': BytesIO( MTOM_REQUEST.replace(b"\n", b"\r\n").replace( b"sample data", PAYLOAD)), }, start_response, "http://null"))) response_str = etree.tostring(response, pretty_print=True) print(response_str) nsdict = dict(tns=TNS) assert etree.fromstring(response_str) \ .xpath(".//tns:documentRequestResult/text()", namespaces=nsdict) \ == [FILE_NAME]
def test_gen_fault_codes(self): fault_string = "Server.Plausible.error" value, faultstrings = Soap12().gen_fault_codes( faultstring=fault_string) self.assertEqual(value, "%s:Receiver" % (Soap12.soap_env)) self.assertEqual(faultstrings[0], "Plausible") self.assertEqual(faultstrings[1], "error") fault_string = "UnknownFaultCode.Plausible.error" with self.assertRaises(TypeError): value, faultstrings = Soap12().gen_fault_codes( faultstring=fault_string)
def test_soap12(self): element = etree.fromstring(""" <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"> <soap:Body> <soap:Fault> <soap:Code> <soap:Value>env:Sender</soap:Value> <soap:Subcode> <soap:Value>st:SomeDomainProblem</soap:Value> </soap:Subcode> </soap:Code> <soap:Reason> <soap:Text xml:lang="en-US"> Some_Policy </soap:Text> </soap:Reason> </soap:Fault> </soap:Body> </soap:Envelope>""") so = Soap12() ret = so.from_element(None, Fault, element[0][0]) assert ret.faultcode == "env:Sender.st:SomeDomainProblem"