def test_document_message_serializer_header_custom_elm(): wsdl = stub(schema=stub(_prefix_map={})) operation = stub(soapaction='my-actiGn') msg = messages.DocumentMessage(wsdl=wsdl, name=None, operation=operation, nsmap=soap.Soap11Binding.nsmap) namespace = 'http://test.python-zeep.org/tests/document' # Fake resolve() msg.body = xsd.Element( etree.QName(namespace, 'response'), xsd.ComplexType([ xsd.Element(etree.QName(namespace, 'arg1'), xsd.String()), xsd.Element(etree.QName(namespace, 'arg2'), xsd.String()), ])) header = xsd.Element( '{http://test.python-zeep.org}auth', xsd.ComplexType([ xsd.Element('{http://test.python-zeep.org}username', xsd.String()), ])) msg.namespace = { 'body': 'http://test.python-zeep.org/tests/document', 'header': None, 'headerfault': None } header_value = header(username='******') serialized = msg.serialize(arg1='ah1', arg2='ah2', _soapheader=header_value) expected = """ <?xml version="1.0"?> <soap-env:Envelope xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap-env:Header> <ns0:auth xmlns:ns0="http://test.python-zeep.org"> <ns0:username>mvantellingen</ns0:username> </ns0:auth> </soap-env:Header> <soap-env:Body> <ns0:response xmlns:ns0="http://test.python-zeep.org/tests/document"> <ns0:arg1>ah1</ns0:arg1> <ns0:arg2>ah2</ns0:arg2> </ns0:response> </soap-env:Body> </soap-env:Envelope> """ assert_nodes_equal(expected, serialized.content)
def test_deserialize_choice(): response_body = load_xml(""" <SOAP-ENV:Body xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <mns:response xmlns:mns="http://test.python-zeep.org/tests/document" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <mns:return type="xsd:string">foobar</mns:return> </mns:response> </SOAP-ENV:Body> """) # noqa wsdl = stub(types=stub( _prefix_map={}, _get_schema_document=lambda namespace: None )) operation = stub(soapaction='my-action', name='something') msg = messages.DocumentMessage( wsdl=wsdl, name=None, operation=operation, nsmap=soap.Soap11Binding.nsmap, type='input') # Fake resolve() namespace = 'http://test.python-zeep.org/tests/document' msg.abstract = definitions.AbstractMessage( etree.QName(namespace, 'Method1Response')) msg.abstract.parts = OrderedDict([ ('body', definitions.MessagePart( element=xsd.Element( etree.QName(namespace, 'response'), xsd.ComplexType( xsd.Choice([ xsd.Element(etree.QName(namespace, 'return'), xsd.String()), ]) ) ), type=None)) ]) msg.namespace = { 'body': 'http://test.python-zeep.org/tests/document', 'header': None, 'headerfault': None } result = msg.deserialize(response_body) assert result == 'foobar'
def test_document_message_serializer(): wsdl = stub(schema=stub(_prefix_map={})) operation = stub(soapaction='my-action') msg = messages.DocumentMessage( wsdl=wsdl, name=None, operation=operation, nsmap=soap.Soap11Binding.nsmap, type='input') namespace = 'http://test.python-zeep.org/tests/document' # Fake resolve() msg.body = xsd.Element( etree.QName(namespace, 'response'), xsd.ComplexType([ xsd.Element(etree.QName(namespace, 'arg1'), xsd.String()), xsd.Element(etree.QName(namespace, 'arg2'), xsd.String()), ]) ) msg.namespace = { 'body': 'http://test.python-zeep.org/tests/document', 'header': None, 'headerfault': None } serialized = msg.serialize(arg1='ah1', arg2='ah2') expected = """ <?xml version="1.0"?> <soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"> <soap-env:Body> <ns0:response xmlns:ns0="http://test.python-zeep.org/tests/document"> <ns0:arg1>ah1</ns0:arg1> <ns0:arg2>ah2</ns0:arg2> </ns0:response> </soap-env:Body> </soap-env:Envelope> """ assert_nodes_equal(expected, serialized.content)