Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/conftest.py
Show All 35 Lines | |||||
@pytest.fixture | @pytest.fixture | ||||
def idx_storage(): | def idx_storage(): | ||||
"""An instance of in-memory indexer storage that gets injected into all | """An instance of in-memory indexer storage that gets injected into all | ||||
indexers classes. | indexers classes. | ||||
""" | """ | ||||
idx_storage = get_indexer_storage('memory', {}) | idx_storage = get_indexer_storage('memory', {}) | ||||
with patch('swh.indexer.storage.get_indexer_storage') \ | with patch('swh.indexer.storage.in_memory.IndexerStorage') \ | ||||
as idx_storage_mock: | as idx_storage_mock: | ||||
idx_storage_mock.return_value = idx_storage | idx_storage_mock.return_value = idx_storage | ||||
yield idx_storage | yield idx_storage | ||||
@pytest.fixture | @pytest.fixture | ||||
def storage(): | def storage(): | ||||
"""An instance of in-memory storage that gets injected into all indexers | """An instance of in-memory storage that gets injected into all indexers | ||||
classes. | classes. | ||||
""" | """ | ||||
storage = get_storage('memory') | storage = get_storage('memory') | ||||
fill_storage(storage) | fill_storage(storage) | ||||
with patch('swh.storage.get_storage') as storage_mock: | with patch('swh.storage.in_memory.InMemoryStorage') as storage_mock: | ||||
storage_mock.return_value = storage | storage_mock.return_value = storage | ||||
yield storage | yield storage | ||||
@pytest.fixture | @pytest.fixture | ||||
def obj_storage(): | def obj_storage(): | ||||
"""An instance of in-memory objstorage that gets injected into all indexers | """An instance of in-memory objstorage that gets injected into all indexers | ||||
classes. | classes. | ||||
""" | """ | ||||
objstorage = get_objstorage('memory', {}) | objstorage = get_objstorage('memory', {}) | ||||
fill_obj_storage(objstorage) | fill_obj_storage(objstorage) | ||||
with patch('swh.objstorage.get_objstorage') as objstorage_mock: | with patch.dict('swh.objstorage._STORAGE_CLASSES', | ||||
objstorage_mock.return_value = objstorage | {'memory': lambda: objstorage}): | ||||
yield objstorage | yield objstorage | ||||
@pytest.fixture(scope='session') # type: ignore # expected redefinition | @pytest.fixture(scope='session') # type: ignore # expected redefinition | ||||
def celery_includes(): | def celery_includes(): | ||||
return [ | return [ | ||||
'swh.indexer.tests.tasks', | 'swh.indexer.tests.tasks', | ||||
'swh.indexer.tasks', | 'swh.indexer.tasks', | ||||
] | ] |