Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/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 | ||||
from unittest.mock import patch | |||||
import pytest | import pytest | ||||
from swh.storage.api.client import RemoteStorage | from swh.storage.api.client import RemoteStorage | ||||
import swh.storage.api.server as server | import swh.storage.api.server as server | ||||
import swh.storage.storage | import swh.storage.storage | ||||
from swh.storage.tests.test_storage import ( # noqa | from swh.storage.tests.test_storage import TestStorageGeneratedData # noqa | ||||
TestStorage, TestStorageGeneratedData) | from swh.storage.tests.test_storage import TestStorage as _TestStorage | ||||
# tests are executed using imported classes (TestStorage and | # tests are executed using imported classes (TestStorage and | ||||
# TestStorageGeneratedData) using overloaded swh_storage fixture | # TestStorageGeneratedData) using overloaded swh_storage fixture | ||||
# below | # below | ||||
@pytest.fixture | @pytest.fixture | ||||
def app(): | def app_server(): | ||||
storage_config = { | storage_config = { | ||||
'cls': 'memory', | 'cls': 'memory', | ||||
'journal_writer': { | 'journal_writer': { | ||||
'cls': 'memory', | 'cls': 'memory', | ||||
}, | }, | ||||
} | } | ||||
server.storage = swh.storage.get_storage(**storage_config) | server.storage = swh.storage.get_storage(**storage_config) | ||||
# hack hack hack! | yield server | ||||
# We attach the journal storage to the app here to make it accessible to | |||||
# the test (as swh_storage.journal_writer); see swh_storage below. | |||||
server.app.journal_writer = server.storage.journal_writer | @pytest.fixture | ||||
yield server.app | def app(app_server): | ||||
del server.app.journal_writer | return app_server.app | ||||
@pytest.fixture | @pytest.fixture | ||||
def swh_rpc_client_class(): | def swh_rpc_client_class(): | ||||
return RemoteStorage | return RemoteStorage | ||||
@pytest.fixture | @pytest.fixture | ||||
def swh_storage(swh_rpc_client, app): | def swh_storage(swh_rpc_client, app_server): | ||||
# This version of the swh_storage fixture uses the swh_rpc_client fixture | # This version of the swh_storage fixture uses the swh_rpc_client fixture | ||||
# to instantiate a RemoteStorage (see swh_rpc_client_class above) that | # to instantiate a RemoteStorage (see swh_rpc_client_class above) that | ||||
# proxies, via the swh.core RPC mechanism, the local (in memory) storage | # proxies, via the swh.core RPC mechanism, the local (in memory) storage | ||||
# configured in the app fixture above. | # configured in the app_server fixture above. | ||||
# | # | ||||
# Also note that, for the sake of | # Also note that, for the sake of | ||||
# making it easier to write tests, the in-memory journal writer of the | # making it easier to write tests, the in-memory journal writer of the | ||||
# in-memory backend storage is attached to the RemoteStorage as its | # in-memory backend storage is attached to the RemoteStorage as its | ||||
# journal_writer attribute. | # journal_writer attribute. | ||||
storage = swh_rpc_client | storage = swh_rpc_client | ||||
journal_writer = getattr(storage, 'journal_writer', None) | journal_writer = getattr(storage, 'journal_writer', None) | ||||
storage.journal_writer = app.journal_writer | storage.journal_writer = app_server.storage.journal_writer | ||||
yield storage | yield storage | ||||
storage.journal_writer = journal_writer | storage.journal_writer = journal_writer | ||||
class TestStorage(_TestStorage): | |||||
def test_content_update(self, swh_storage, app_server): | |||||
swh_storage.journal_writer = None # TODO, journal_writer not supported | |||||
with patch.object(server.storage, 'journal_writer', None): | |||||
ardumont: I don't understand what we are doing with the journal initialization.
if it's not supported… | |||||
Done Inline Actions
because it's supported in all tests except this one.
I agree, but it will be more work than you assume, and it's out of the scope of my current work on merging the cassandra backend. vlorentz: > if it's not supported, why do we declare it in the dict configuration?
because it's… | |||||
Not Done Inline Actions
yes, completely out of scope, just a heads up since i started talking journal ;) the good side is that you are in the loop as well ;) ardumont: > I agree, but it will be more work than you assume, and it's out of the scope of my current… | |||||
super().test_content_update(swh_storage) |
I don't understand what we are doing with the journal initialization.
if it's not supported, why do we declare it in the dict configuration?
Can't we just remove the configuration key if it's unused?
That reminds me that i discussed with @douardda the possibility to have the journal part moved to a dedicated storage proxy (server side). That would avoid seeing everywhere within our add methods the journal instructions... [1]
I'd be less invasive in the _add endpoints.
What do you think?
[1] @douardda proposed another approach, keep the original storage (storage.py, cassandra.py) the interface with a default implementation (i call that an abstract class...). And push the abstration over the storage backend (db.py, cql.py). I'm not sure which is better.