def _create(self, operation, args, kwargs, client=None, options=None): """Create the XML document to send to the server. Note that this generates the soap envelope without the wsse applied. """ operation_obj = self.get(operation) if not operation_obj: raise ValueError("Operation %r not found" % operation) # Create the SOAP envelope serialized = operation_obj.create(*args, **kwargs) self._set_http_headers(serialized, operation_obj) envelope = serialized.content http_headers = serialized.headers # Apply ws-addressing if client: if not options: options = client.service._binding_options if operation_obj.abstract.input_message.wsa_action: envelope, http_headers = wsa.WsAddressingPlugin().egress( envelope, http_headers, operation_obj, options) # Apply plugins envelope, http_headers = plugins.apply_egress( client, envelope, http_headers, operation_obj, options) # Apply WSSE if client.wsse: envelope, http_headers = client.wsse.apply(envelope, http_headers) return envelope, http_headers
def test_force_wsa(recwarn, monkeypatch): monkeypatch.setattr( uuid, 'uuid4', lambda: uuid.UUID('ada686f9-5995-4088-bea4-239f694b2eaf')) wsdl_main = StringIO(""" <?xml version="1.0"?> <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://tests.python-zeep.org/xsd-main" xmlns:sec="http://tests.python-zeep.org/wsdl-secondary" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://tests.python-zeep.org/xsd-main"> <wsdl:types> <xsd:schema targetNamespace="http://tests.python-zeep.org/xsd-main" xmlns:tns="http://tests.python-zeep.org/xsd-main"> <xsd:element name="input" type="xsd:string"/> <xsd:element name="input2" type="xsd:string"/> </xsd:schema> </wsdl:types> <wsdl:message name="dummyRequest"> <wsdl:part name="response" element="tns:input"/> </wsdl:message> <wsdl:message name="dummyResponse"> <wsdl:part name="response" element="tns:input2"/> </wsdl:message> <wsdl:portType name="TestPortType"> <wsdl:operation name="TestOperation1"> <wsdl:input message="dummyRequest"/> <wsdl:output message="dummyResponse"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="TestBinding" type="tns:TestPortType"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="TestOperation1"> <soap:operation soapAction="urn:dummyRequest"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="TestService"> <wsdl:documentation>Test service</wsdl:documentation> <wsdl:port name="TestPortType" binding="tns:TestBinding"> <soap:address location="http://tests.python-zeep.org/test"/> </wsdl:port> </wsdl:service> </wsdl:definitions> """.strip()) transport = DummyTransport() client = Client(wsdl_main, transport=transport, plugins=[wsa.WsAddressingPlugin()]) binding = client.wsdl.services.get('TestService').ports.get( 'TestPortType').binding envelope, headers = binding._create( 'TestOperation1', args=['foo'], kwargs={}, client=client, options={'address': 'http://tests.python-zeep.org/test'}) expected = """ <soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"> <soap-env:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"> <wsa:Action>urn:dummyRequest</wsa:Action> <wsa:MessageID>urn:uuid:ada686f9-5995-4088-bea4-239f694b2eaf</wsa:MessageID> <wsa:To>http://tests.python-zeep.org/test</wsa:To> </soap-env:Header> <soap-env:Body> <ns0:input xmlns:ns0="http://tests.python-zeep.org/xsd-main">foo</ns0:input> </soap-env:Body> </soap-env:Envelope> """ assert_nodes_equal(expected, envelope)
def test_force_wsa_soap12(recwarn, monkeypatch): monkeypatch.setattr( uuid, "uuid4", lambda: uuid.UUID("ada686f9-5995-4088-bea4-239f694b2eaf")) wsdl_main = StringIO(""" <?xml version="1.0"?> <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://tests.python-zeep.org/xsd-main" xmlns:sec="http://tests.python-zeep.org/wsdl-secondary" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://tests.python-zeep.org/xsd-main"> <wsdl:types> <xsd:schema targetNamespace="http://tests.python-zeep.org/xsd-main" xmlns:tns="http://tests.python-zeep.org/xsd-main"> <xsd:element name="input" type="xsd:string"/> <xsd:element name="input2" type="xsd:string"/> </xsd:schema> </wsdl:types> <wsdl:message name="dummyRequest"> <wsdl:part name="response" element="tns:input"/> </wsdl:message> <wsdl:message name="dummyResponse"> <wsdl:part name="response" element="tns:input2"/> </wsdl:message> <wsdl:portType name="TestPortType"> <wsdl:operation name="TestOperation1"> <wsdl:input message="dummyRequest"/> <wsdl:output message="dummyResponse"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="TestBinding" type="tns:TestPortType"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="TestOperation1"> <soap:operation soapAction="urn:dummyRequest"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="TestService"> <wsdl:documentation>Test service</wsdl:documentation> <wsdl:port name="TestPortType" binding="tns:TestBinding"> <soap:address location="http://tests.python-zeep.org/test"/> </wsdl:port> </wsdl:service> </wsdl:definitions> """.strip()) client = stub(plugins=[wsa.WsAddressingPlugin()], wsse=None, settings=Settings()) transport = DummyTransport() doc = wsdl.Document(wsdl_main, transport, settings=client.settings) binding = doc.services.get("TestService").ports.get("TestPortType").binding envelope, headers = binding._create( "TestOperation1", args=["foo"], kwargs={}, client=client, options={"address": "http://tests.python-zeep.org/test"}, ) expected = """ <soap-env:Envelope xmlns:soap-env="http://www.w3.org/2003/05/soap-envelope"> <soap-env:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"> <wsa:Action>urn:dummyRequest</wsa:Action> <wsa:MessageID>urn:uuid:ada686f9-5995-4088-bea4-239f694b2eaf</wsa:MessageID> <wsa:To>http://tests.python-zeep.org/test</wsa:To> </soap-env:Header> <soap-env:Body> <ns0:input xmlns:ns0="http://tests.python-zeep.org/xsd-main">foo</ns0:input> </soap-env:Body> </soap-env:Envelope> """ assert_nodes_equal(expected, envelope) assert headers["Content-Type"] == ( 'application/soap+xml; charset=utf-8; action="urn:dummyRequest"')