Exemplo n.º 1
0
def client_from_wsdl(wsdl_content, *args, **kwargs):
    """
    Constructs a non-caching suds Client based on the given WSDL content.

      The wsdl_content is expected to be a raw byte string and not a unicode
    string. This simple structure suits us fine here because XML content holds
    its own embedded encoding identification ('utf-8' if not specified
    explicitly).

      Stores the content directly inside the suds library internal document
    store under a hard-coded id to avoid having to load the data from a
    temporary file.

      Uses a locally created empty document store unless one is provided
    externally using the 'documentStore' keyword argument.

      Explicitly disables caching or otherwise, because we use the same
    hardcoded id for our main WSDL document, suds would always reuse the first
    such local document from its cache instead of fetching it from our document
    store.

    """
    assert wsdl_content.__class__ is suds.byte_str_class, "bad test data"
    store = kwargs.get("documentStore")
    if store is None:
        store = suds.store.DocumentStore()
        kwargs.update(documentStore=store)
    test_file_id = "whatchamacallit"
    store.update({test_file_id: wsdl_content})
    kwargs.update(cache=None)
    return suds.client.Client("suds://" + test_file_id, *args, **kwargs)
Exemplo n.º 2
0
def lxmlclient_from_wsdl(wsdl_content, *args, **kwargs):
    """
    Constructs a non-caching suds Client based on the given WSDL content.

      The wsdl_content is expected to be a raw byte string and not a unicode
    string. This simple structure suits us fine here because XML content holds
    its own embedded encoding identification ('utf-8' if not specified
    explicitly).

      Stores the content directly inside the suds library internal document
    store under a hard-coded id to avoid having to load the data from a
    temporary file.

      Uses a locally created empty document store unless one is provided
    externally using the 'documentStore' keyword argument.

      Explicitly disables caching or otherwise, because we use the same
    hardcoded id for our main WSDL document, suds would always reuse the first
    such local document from its cache instead of fetching it from our document
    store.

    """
    assert wsdl_content.__class__ is suds.byte_str_class, "bad test data"
    store = kwargs.get("documentStore")
    if store is None:
        store = suds.store.DocumentStore()
        kwargs.update(documentStore=store)
    test_file_id = "whatchamacallit"
    store.update({test_file_id: wsdl_content})
    kwargs.update(cache=None)
    return suds.lxmlclient.Client("suds://" + test_file_id, *args, **kwargs)    
def test_updating_DocumentStore_content():
    content1 = suds.byte_str("one")
    content2 = suds.byte_str("two")
    content1_1 = suds.byte_str("one one")

    store = suds.store.DocumentStore()
    assert len(store) == 1
    __test_default_DocumentStore_content(store)

    store.update({"1":content1})
    assert len(store) == 2
    __test_default_DocumentStore_content(store)
    __test_open(store, "1", content1)

    store.update({"1":content1, "2":content2, "1 1":content1_1})
    assert len(store) == 4
    __test_default_DocumentStore_content(store)
    __test_open(store, "1", content1)
    __test_open(store, "2", content2)
    __test_open(store, "1 1", content1_1)

    store.update({"2":content2, "1 1":content1_1})
    assert len(store) == 4
    __test_default_DocumentStore_content(store)
    __test_open(store, "1", content1)
    __test_open(store, "2", content2)
    __test_open(store, "1 1", content1_1)

    store.update(uno=content1, due=content2)
    assert len(store) == 6
    __test_default_DocumentStore_content(store)
    __test_open(store, "1", content1)
    __test_open(store, "2", content2)
    __test_open(store, "1 1", content1_1)
    __test_open(store, "uno", content1)
    __test_open(store, "due", content2)
def test_updating_DocumentStore_content():
    content1 = suds.byte_str("one")
    content2 = suds.byte_str("two")
    content1_1 = suds.byte_str("one one")

    store = suds.store.DocumentStore()
    assert len(store) == 1
    __test_default_DocumentStore_content(store)

    store.update({"1": content1})
    assert len(store) == 2
    __test_default_DocumentStore_content(store)
    __test_open(store, "1", content1)

    store.update({"1": content1, "2": content2, "1 1": content1_1})
    assert len(store) == 4
    __test_default_DocumentStore_content(store)
    __test_open(store, "1", content1)
    __test_open(store, "2", content2)
    __test_open(store, "1 1", content1_1)

    store.update({"2": content2, "1 1": content1_1})
    assert len(store) == 4
    __test_default_DocumentStore_content(store)
    __test_open(store, "1", content1)
    __test_open(store, "2", content2)
    __test_open(store, "1 1", content1_1)

    store.update(uno=content1, due=content2)
    assert len(store) == 6
    __test_default_DocumentStore_content(store)
    __test_open(store, "1", content1)
    __test_open(store, "2", content2)
    __test_open(store, "1 1", content1_1)
    __test_open(store, "uno", content1)
    __test_open(store, "due", content2)