Skip to content

A mock library for mocking openstack the swift storage backend for use with python-swiftclient

License

Notifications You must be signed in to change notification settings

canonical/swiftmock

Repository files navigation

swiftmock: A mock backend for testing swift.

🐉 Installation

Install from PyPI:

$ pip install swiftmock

🐉 Usage

Importing directly

You can use swiftmock directly in your code:

from swiftmock.swift import MockConnection
with MockConnection() as conn:
    conn.put_container("fake-container")
    conn.put_object("fake-container", "path/to/object", b"contents")
    header, contents = conn.get_object("fake-container", "path/to/object")
assert contents == b"contents"

Using with Pytest

You can also use this library as a pytest plugin.

def my_test_using_swift(mock_swift):
    # optional, the mock automatically replaces *swiftclient.client.Connection*
    # so that it automatically returns the mocked instance
    mock_swift.put_container("fake-container")
    with pytest.assert_raises(swiftclient.exceptions.ClientException):
        mock_swift.get_object("fake-container", "non/existent/object")

About

A mock library for mocking openstack the swift storage backend for use with python-swiftclient

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages