Ejemplo n.º 1
0
 def setup(self):
     public_portal_service_url = self.url_ + '/pearson-rest/services/PublicPortalServiceJSON'
     settings = Settings(strict=False, raw_response=True, forbid_dtd=False, forbid_entities=False, forbid_external=False, xsd_ignore_sequence_order=True)
     self.client_ = Client(wsdl=public_portal_service_url + '?wsdl', transport=Transport(session=self.session_), settings=settings)
Ejemplo n.º 2
0
    def create_soap_client(self,
                           url_or_path,
                           timeout=90,
                           username=None,
                           password=None,
                           auth_type='NONE',
                           settings={},
                           cache=None):
        """Creates a Soap client using the zeep library

        -----

        Param

        *url_or_path :: string*

            The URL or path to the webservice. The client can read either a
            remote webservice or a local file from the OS

        -----

        Param

        *timeout :: integer [90]*

            The number of seconds before the request to the webservice times
            out

        -----

        Param

        *username :: string [None]*

            The username used for authenticating against webservices. If this
            is set, then the auth_type must also be set to something other
            than None

        -----

        Param

        *password :: string [None]*

            The password used for authenticating against webservices

        -----

        Param

        *auth_type :: string ["NONE"]*

            The authentication type to use when communicating with
            the webservice. Options are NONE, BASIC, PROXY and DIGEST. Any
            other than None requires that credentials also be supplied

        -----

        Param

        *Settings :: dict [Empty]*

            The settings allows the user to specify various settings to
            use when communicating with the webservice. They are detailed
            here: https://python-zeep.readthedocs.io/en/master/settings.html

        -----

        Return

        *Client*

            The client used for communicating with the webservice

        -----

        | A simple example |
        |                  | ${client}= | Create Soap Client | http://some-web-url.com/webservice?wsdl |
        |                  | ${answer}= | Call Soap Method | ${client} | getTheAnswer |

        | Settings example |
        |                   | &{settings}= | Create Dictionary | strict=False | raw_response=True |
        |                   | ${client}= |  Create Soap Client | http://some-web-url.com/webservice?wsdl | settings=&{settings} |
        |                   | ${answer}= | Call Soap Method | ${client} | getTheAnswer |

        | Basic authentication example |
        |                  | ${client}= |  Create Soap Client | http://some-web-url.com/webservice?wsdl | username=bob | password=bobspassword | auth_type=BASIC |
        |                  | ${answer}= | Call Soap Method | ${client} | getTheAnswer |

        """

        url = url_or_path

        transport = Transport(timeout=timeout, cache=cache)
        if auth_type != 'NONE':
            session = Session()
            if auth_type == 'BASIC':
                session.auth = HTTPBasicAuth(username, password)
            elif auth_type == 'PROXY':
                session.auth = HTTPProxyAuth(username, password)
            elif auth_type == 'DIGEST':
                session.auth = HTTPDigestAuth(username, password)
            transport = Transport(session=session,
                                  timeout=timeout,
                                  cache=cache)

        client_settings = Settings()
        if len(settings) > 0:
            available_settings = [
                'strict', 'raw_response', 'forbid_dtd', 'forbid_entities',
                'forbid_external', 'xml_huge_tree', 'force_https',
                'extra_http_headers'
            ]
            for key in settings:
                if key in available_settings:
                    if key == 'strict':
                        client_settings.strict = settings[key]
                    elif key == 'raw_response':
                        client_settings.raw_response = settings[key]
                    elif key == 'forbid_dtd':
                        client_settings.forbid_dtd = settings[key]
                    elif key == 'forbid_entities':
                        client_settings.forbid_entities = settings[key]
                    elif key == 'forbid_external':
                        client_settings.forbid_external = settings[key]
                    elif key == 'xml_huge_tree':
                        client_settings.xml_huge_tree = settings[key]
                    elif key == 'force_https':
                        client_settings.force_https = settings[key]
                    elif key == 'extra_http_headers':
                        client_settings.extra_http_headers = settings[key]

        client = Client(url,
                        transport=transport,
                        plugins=[HistoryPlugin()],
                        settings=client_settings)

        return client
Ejemplo n.º 3
0
 def __init__(self, settings=None):
     self.schemas = []
     self.settings = settings or Settings()
Ejemplo n.º 4
0
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"')
Ejemplo n.º 5
0
def parse_xml(data):
    return zeep.loader.parse_xml(data, None, settings=Settings())