Пример #1
0
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))
Пример #2
0
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))
Пример #3
0
 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")
Пример #4
0
 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")
Пример #5
0
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
Пример #6
0
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
Пример #7
0
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
Пример #8
0
 def execute(self, schema):
     """
     Execute this query using the specified schema.
     @param schema: The schema associated with the query.  The schema
         is used by the query to search for items.
     @type schema: L{schema.Schema}
     @return: The item matching the search criteria.
     @rtype: L{sxbase.SchemaObject}
     """
     if schema.builtin(self.ref):
         name = self.ref[0]
         b = Factory.create(schema, name)
         log.debug('%s, found builtin (%s)', self.id, name)
         return b
     result = None
     for d in (schema.elements, schema.types):
         result = d.get(self.ref)
         if self.filter(result):
             result = None
         else:
             break
     if result is None:
         eq = ElementQuery(self.ref)
         eq.history = self.history
         result = eq.execute(schema)
     return self.result(result)
Пример #9
0
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
Пример #10
0
 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
Пример #11
0
 def execute(self, schema):
     if schema.builtin(self.ref):
         name = self.ref[0]
         b = Factory.create(schema, name)
         #log.debug('%s, found builtin (%s)', self.id, name)
         return b
     result = schema.types.get(self.ref)
     if self.filter(result):
         result = None
     return self.result(result)
Пример #12
0
 def execute(self, schema):
     if schema.builtin(self.ref):
         name = self.ref[0]
         b = Factory.create(schema, name)
         log.debug('%s, found builtin (%s)', self.id, name)
         return b
     result = schema.types.get(self.ref)
     if self.filter(result):
         result = None
     return self.result(result)
Пример #13
0
 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
Пример #14
0
 def execute(self, schema):
     if schema.builtin(self.ref):
         name = self.ref[0]
         b = Factory.create(schema, name)
         log.debug('%s, found builtin (%s)', self.id, name)
         return b
     result = None
     for d in (schema.elements, schema.types):
         result = d.get(self.ref)
         if self.filter(result):
             result = None
         else:
             break
     if result is None:
         eq = ElementQuery(self.ref)
         eq.history = self.history
         result = eq.execute(schema)
     return self.result(result)
Пример #15
0
 def execute(self, schema):
     if schema.builtin(self.ref):
         name = self.ref[0]
         b = Factory.create(schema, name)
         #log.debug('%s, found builtin (%s)', self.id, name)
         return b
     result = None
     for d in (schema.elements, schema.types):
         result = d.get(self.ref)
         if self.filter(result):
             result = None
         else:
             break
     if result is None:
         eq = ElementQuery(self.ref)
         eq.history = self.history
         result = eq.execute(schema)
     return self.result(result)
Пример #16
0
def test_create_builtin_type_schema_objects(xsd_type_name, xsd_type):
    schema = _create_dummy_schema()
    xsd_object = Factory.create(schema, xsd_type_name)
    assert xsd_object.__class__ is xsd_type
    assert xsd_object.name == xsd_type_name
    assert xsd_object.schema is schema
Пример #17
0
def test_create_builtin_type_schema_objects(xsd_type_name, xsd_type):
    schema = _create_dummy_schema()
    xsd_object = Factory.create(schema, xsd_type_name)
    assert xsd_object.__class__ is xsd_type
    assert xsd_object.name == xsd_type_name
    assert xsd_object.schema is schema
Пример #18
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">&apos;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)]
Пример #19
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">&apos;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)]