Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/storage/test_api_client.py
# Copyright (C) 2015-2018 The Software Heritage developers | # Copyright (C) 2015-2018 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 unittest | import unittest | ||||
from swh.core.api.tests.server_testing import ServerTestFixture | from swh.core.api.tests.server_testing import ServerTestFixture | ||||
import swh.indexer.storage as storage | |||||
from swh.indexer.storage import INDEXER_CFG_KEY | from swh.indexer.storage import INDEXER_CFG_KEY | ||||
from swh.indexer.storage.api.client import RemoteStorage | from swh.indexer.storage.api.client import RemoteStorage | ||||
from swh.indexer.storage.api.server import app | from swh.indexer.storage.api.server import app | ||||
from swh.storage.journal_writer import \ | |||||
get_journal_writer, InMemoryJournalWriter | |||||
from .test_storage import CommonTestStorage, BasePgTestStorage | from .test_storage import CommonTestStorage, BasePgTestStorage | ||||
class TestRemoteStorage(CommonTestStorage, ServerTestFixture, | class TestRemoteStorage(CommonTestStorage, ServerTestFixture, | ||||
BasePgTestStorage, unittest.TestCase): | BasePgTestStorage, unittest.TestCase): | ||||
"""Test the indexer's remote storage API. | """Test the indexer's remote storage API. | ||||
This class doesn't define any tests as we want identical | This class doesn't define any tests as we want identical | ||||
functionality between local and remote storage. All the tests are | functionality between local and remote storage. All the tests are | ||||
therefore defined in | therefore defined in | ||||
`class`:swh.indexer.storage.test_storage.CommonTestStorage. | `class`:swh.indexer.storage.test_storage.CommonTestStorage. | ||||
""" | """ | ||||
def setUp(self): | def setUp(self): | ||||
def mock_get_journal_writer(cls, args=None): | |||||
assert cls == 'inmemory' | |||||
return journal_writer | |||||
storage.get_journal_writer = mock_get_journal_writer | |||||
journal_writer = InMemoryJournalWriter() | |||||
self.journal_writer = journal_writer | |||||
self.config = { | self.config = { | ||||
INDEXER_CFG_KEY: { | INDEXER_CFG_KEY: { | ||||
'cls': 'local', | 'cls': 'local', | ||||
'args': { | 'args': { | ||||
'db': 'dbname=%s' % self.TEST_DB_NAME, | 'db': 'dbname=%s' % self.TEST_DB_NAME, | ||||
'journal_writer': { | |||||
'cls': 'inmemory', | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } | ||||
self.app = app | self.app = app | ||||
super().setUp() | super().setUp() | ||||
self.storage = RemoteStorage(self.url()) | self.storage = RemoteStorage(self.url()) | ||||
def tearDown(self): | |||||
super().tearDown() | |||||
storage.get_journal_writer = get_journal_writer |