def __init__(self, configuration): Factory.maptag("decimal", XDecimal) self.client = Client(configuration.wsdl) credentials = self.create("Credentials") credentials.IntegrationID = configuration.integration_id credentials.Username = configuration.username credentials.Password = configuration.password self.plugin = AuthenticatorPlugin(credentials, self.client) self.client.set_options(plugins=[self.plugin], port=configuration.port) self.logger = getLogger("stamps")
def test_recognize_custom_mapped_builtins(monkeypatch): """User code can register additional XSD built-ins.""" _monkeypatch_builtin_XSD_type_registry(monkeypatch) schema = _create_dummy_schema() name = "trla-baba-lan" for ns in builtin_namespaces: assert not schema.builtin((name, ns)) Factory.maptag(name, _Dummy) for ns in builtin_namespaces: assert schema.builtin((name, ns))
def test_create_custom_mapped_builtin_type_schema_objects(xsd_type_name, monkeypatch): """User code can add or update built-in XSD type registrations.""" _monkeypatch_builtin_XSD_type_registry(monkeypatch) class MockType: def __init__(self, schema, name): self.schema = schema self.name = name schema = _Dummy() Factory.maptag(xsd_type_name, MockType) xsd_object = Factory.create(schema, xsd_type_name) assert xsd_object.__class__ is MockType assert xsd_object.name == xsd_type_name assert xsd_object.schema is schema
def test_resolving_builtin_types(monkeypatch): _monkeypatch_builtin_XSD_type_registry(monkeypatch) class MockXInteger(XInteger): pass Factory.maptag("osama", MockXInteger) wsdl = tests.wsdl('<xsd:element name="wu" type="xsd:osama"/>', input="wu") client = tests.client_from_wsdl(wsdl) element, schema_object = client.sd[0].params[0] assert element.name == "wu" assert element.type == ("osama", "http://www.w3.org/2001/XMLSchema") assert schema_object.__class__ is MockXInteger assert schema_object.name == "osama" assert schema_object.schema is client.wsdl.schema
def test_resolving_builtin_types(monkeypatch): _monkeypatch_builtin_XSD_type_registry(monkeypatch) class MockXInteger(XInteger): pass Factory.maptag("osama", MockXInteger) wsdl = testutils.wsdl('<xsd:element name="wu" type="xsd:osama"/>', input="wu") client = testutils.client_from_wsdl(wsdl) element, schema_object = client.sd[0].params[0] assert element.name == "wu" assert element.type == ("osama", "http://www.w3.org/2001/XMLSchema") assert schema_object.__class__ is MockXInteger assert schema_object.name == "osama" assert schema_object.schema is client.wsdl.schema
def __init__(self, configuration, wsdl_name, wsdl_version, service_id): Factory.maptag("decimal", XDecimal) name = "{0}Service_v{1:d}.wsdl".format(wsdl_name, wsdl_version) wsdl = os.path.join(configuration.wsdls, name) self.client = Client(wsdl) self.logger = getLogger("fedex") credential = self.create("WebAuthenticationCredential") credential.Key = configuration.key credential.Password = configuration.password self.credentials = self.create("WebAuthenticationDetail") self.credentials.UserCredential = credential self.client_detail = self.create("ClientDetail") self.client_detail.AccountNumber = configuration.account_number self.client_detail.MeterNumber = configuration.meter_number self.version = self.create("VersionId") self.version.ServiceId = service_id self.version.Major = wsdl_version self.version.Intermediate = 0 self.version.Minor = 0
def test_translation(monkeypatch): """Python <--> XML representation translation on marshall/unmarshall.""" anObject = _Dummy() class MockType(XBuiltin): def __init__(self, *args, **kwargs): self._mock_translate_log = [] super(MockType, self).__init__(*args, **kwargs) def translate(self, value, topython=True): self._mock_translate_log.append((value, topython)) if topython: return anObject return "'ollywood" _monkeypatch_builtin_XSD_type_registry(monkeypatch) Factory.maptag("woof", MockType) namespace = "I'm a little tea pot, short and stout..." wsdl = testutils.wsdl("""\ <xsd:element name="wi" type="xsd:woof"/> <xsd:element name="wo" type="xsd:woof"/>""", input="wi", output="wo", xsd_target_namespace=namespace, operation_name="f") client = testutils.client_from_wsdl(wsdl, nosend=True, prettyxml=True) # Check suds library's XSD schema input parameter information. schema = client.wsdl.schema element_in = schema.elements["wi", namespace] assert element_in.name == "wi" element_out = schema.elements["wo", namespace] assert element_out.name == "wo" schema_object_in = element_in.resolve() schema_object_out = element_out.resolve() assert element_in is client.sd[0].params[0][0] assert schema_object_in is client.sd[0].params[0][1] assert schema_object_in.__class__ is MockType assert schema_object_in._mock_translate_log == [] assert schema_object_out.__class__ is MockType assert schema_object_out._mock_translate_log == [] # Construct operation invocation request - test marshalling. request = client.service.f(55) assert schema_object_in._mock_translate_log == [(55, False)] assert schema_object_out._mock_translate_log == [] CompareSAX.data2data(request.envelope, """\ <?xml version="1.0" encoding="UTF-8"?> <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> <Header/> <Body> <wi xmlns="%s">'ollywood</wi> </Body> </Envelope>""" % (namespace,)) # Process operation response - test unmarshalling. response = client.service.f(__inject=dict(reply=suds.byte_str("""\ <?xml version="1.0"?> <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> <Body> <wo xmlns="%s">fri-fru</wo> </Body> </Envelope>""" % (namespace,)))) assert response is anObject assert schema_object_in._mock_translate_log == [(55, False)] assert schema_object_out._mock_translate_log == [("fri-fru", True)]
def test_translation(monkeypatch): """Python <--> XML representation translation on marshall/unmarshall.""" anObject = _Dummy() class MockType(XBuiltin): def __init__(self, *args, **kwargs): self._mock_translate_log = [] super(MockType, self).__init__(*args, **kwargs) def translate(self, value, topython=True): self._mock_translate_log.append((value, topython)) if topython: return anObject return "'ollywood" _monkeypatch_builtin_XSD_type_registry(monkeypatch) Factory.maptag("woof", MockType) namespace = "I'm a little tea pot, short and stout..." wsdl = testutils.wsdl("""\ <xsd:element name="wi" type="xsd:woof"/> <xsd:element name="wo" type="xsd:woof"/>""", input="wi", output="wo", xsd_target_namespace=namespace, operation_name="f") client = testutils.client_from_wsdl(wsdl, nosend=True, prettyxml=True) # Check suds library's XSD schema input parameter information. schema = client.wsdl.schema element_in = schema.elements["wi", namespace] assert element_in.name == "wi" element_out = schema.elements["wo", namespace] assert element_out.name == "wo" schema_object_in = element_in.resolve() schema_object_out = element_out.resolve() assert element_in is client.sd[0].params[0][0] assert schema_object_in is client.sd[0].params[0][1] assert schema_object_in.__class__ is MockType assert schema_object_in._mock_translate_log == [] assert schema_object_out.__class__ is MockType assert schema_object_out._mock_translate_log == [] # Construct operation invocation request - test marshalling. request = client.service.f(55) assert schema_object_in._mock_translate_log == [(55, False)] assert schema_object_out._mock_translate_log == [] CompareSAX.data2data( request.envelope, """\ <?xml version="1.0" encoding="UTF-8"?> <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> <Header/> <Body> <wi xmlns="%s">'ollywood</wi> </Body> </Envelope>""" % (namespace, )) # Process operation response - test unmarshalling. response = client.service.f(__inject=dict(reply=suds.byte_str("""\ <?xml version="1.0"?> <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> <Body> <wo xmlns="%s">fri-fru</wo> </Body> </Envelope>""" % (namespace, )))) assert response is anObject assert schema_object_in._mock_translate_log == [(55, False)] assert schema_object_out._mock_translate_log == [("fri-fru", True)]