Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_init.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import pytest | import pytest | ||||
from swh.storage import get_storage | from swh.storage import get_storage | ||||
from swh.storage.api.client import RemoteStorage | from swh.storage.api.client import RemoteStorage | ||||
# from swh.storage.storage import Storage as DbStorage | # from swh.storage.storage import Storage as DbStorage | ||||
from swh.storage.in_memory import Storage as MemoryStorage | from swh.storage.in_memory import Storage as MemoryStorage | ||||
from swh.storage.buffer import BufferingProxyStorage | |||||
from swh.storage.filter import FilteringProxyStorage | from swh.storage.filter import FilteringProxyStorage | ||||
def test_get_storage(): | def test_get_storage(): | ||||
"""Instantiating an existing storage should be ok | """Instantiating an existing storage should be ok | ||||
""" | """ | ||||
for cls, real_class, dummy_args in [ | for cls, real_class, dummy_args in [ | ||||
('remote', RemoteStorage, {'url': 'url'}), | ('remote', RemoteStorage, {'url': 'url'}), | ||||
('memory', MemoryStorage, {}), | ('memory', MemoryStorage, {}), | ||||
# FIXME: make it work, right now it does not due to actual db | # FIXME: make it work, right now it does not due to actual db | ||||
# connection happening (at instantiation time) | # connection happening (at instantiation time) | ||||
# ('local', DbStorage, { | # ('local', DbStorage, { | ||||
# 'db': 'postgresql://db', 'objstorage': { | # 'db': 'postgresql://db', 'objstorage': { | ||||
# 'cls': 'local', 'args': {} | # 'cls': 'local', 'args': {} | ||||
# } | # } | ||||
# }), | # }), | ||||
('filter', FilteringProxyStorage, {'storage': { | ('filter', FilteringProxyStorage, {'storage': { | ||||
'cls': 'memory', 'args': {}} | 'cls': 'memory', 'args': {}} | ||||
}) | }), | ||||
('buffer', BufferingProxyStorage, {'storage': { | |||||
'cls': 'memory', 'args': {}} | |||||
}), | |||||
]: | ]: | ||||
actual_storage = get_storage(cls, args=dummy_args) | actual_storage = get_storage(cls, args=dummy_args) | ||||
assert actual_storage is not None | assert actual_storage is not None | ||||
assert isinstance(actual_storage, real_class) | assert isinstance(actual_storage, real_class) | ||||
def test_get_storage_failure(): | def test_get_storage_failure(): | ||||
"""Instantiating an unknown storage should raise | """Instantiating an unknown storage should raise | ||||
""" | """ | ||||
with pytest.raises(ValueError, match='Unknown storage class `unknown`'): | with pytest.raises(ValueError, match='Unknown storage class `unknown`'): | ||||
get_storage('unknown', args=[]) | get_storage('unknown', args=[]) |