Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/storage/test_storage.py
# Copyright (C) 2015-2019 The Software Heritage developers | # Copyright (C) 2015-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 inspect | |||||
import threading | import threading | ||||
import pytest | import pytest | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.indexer.storage.interface import IndexerStorageInterface | |||||
def prepare_mimetypes_from(fossology_licenses): | def prepare_mimetypes_from(fossology_licenses): | ||||
"""Fossology license needs some consistent data in db to run. | """Fossology license needs some consistent data in db to run. | ||||
""" | """ | ||||
mimetypes = [] | mimetypes = [] | ||||
for c in fossology_licenses: | for c in fossology_licenses: | ||||
mimetypes.append({ | mimetypes.append({ | ||||
▲ Show 20 Lines • Show All 1,830 Lines • ▼ Show 20 Lines | |||||
class TestIndexerStorageMisc: | class TestIndexerStorageMisc: | ||||
"""Misc endpoints tests for the IndexerStorage. | """Misc endpoints tests for the IndexerStorage. | ||||
""" | """ | ||||
def test_check_config(self, swh_indexer_storage): | def test_check_config(self, swh_indexer_storage): | ||||
storage = swh_indexer_storage | storage = swh_indexer_storage | ||||
assert storage.check_config(check_write=True) | assert storage.check_config(check_write=True) | ||||
assert storage.check_config(check_write=False) | assert storage.check_config(check_write=False) | ||||
def test_types(self, swh_indexer_storage): | |||||
"""Checks all methods of StorageInterface are implemented by this | |||||
backend, and that they have the same signature.""" | |||||
# Create an instance of the protocol (which cannot be instantiated | |||||
# directly, so this creates a subclass, then instantiates it) | |||||
interface = type('_', (IndexerStorageInterface,), {})() | |||||
assert 'content_mimetype_add' in dir(interface) | |||||
missing_methods = [] | |||||
for meth_name in dir(interface): | |||||
if meth_name.startswith('_'): | |||||
continue | |||||
interface_meth = getattr(interface, meth_name) | |||||
try: | |||||
concrete_meth = getattr(swh_indexer_storage, meth_name) | |||||
except AttributeError: | |||||
missing_methods.append(meth_name) | |||||
continue | |||||
expected_signature = inspect.signature(interface_meth) | |||||
actual_signature = inspect.signature(concrete_meth) | |||||
assert expected_signature == actual_signature, meth_name | |||||
assert missing_methods == [] |