Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/tests/conftest.py
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | ) -> Dict[str, str]: | ||||
) | ) | ||||
return postgresql.get_dsn_parameters() | return postgresql.get_dsn_parameters() | ||||
# the Flask app used as server in these tests | # the Flask app used as server in these tests | ||||
@pytest.fixture | @pytest.fixture | ||||
def app(populated_db: Dict[str, str]) -> Iterator[server.ProvenanceStorageServerApp]: | def app(populated_db: Dict[str, str]) -> Iterator[server.ProvenanceStorageServerApp]: | ||||
assert hasattr(server, "storage") | assert hasattr(server, "storage") | ||||
server.storage = get_provenance_storage(cls="local", db=populated_db) | server.storage = get_provenance_storage(cls="postgresql", db=populated_db) | ||||
yield server.app | yield server.app | ||||
# the RPCClient class used as client used in these tests | # the RPCClient class used as client used in these tests | ||||
@pytest.fixture | @pytest.fixture | ||||
def swh_rpc_client_class() -> type: | def swh_rpc_client_class() -> type: | ||||
return RemoteProvenanceStorage | return RemoteProvenanceStorage | ||||
@pytest.fixture(params=["local", "remote"]) | @pytest.fixture(params=["postgresql", "remote"]) | ||||
def provenance_storage( | def provenance_storage( | ||||
request: SubRequest, | request: SubRequest, | ||||
populated_db: Dict[str, str], | populated_db: Dict[str, str], | ||||
swh_rpc_client: RemoteProvenanceStorage, | swh_rpc_client: RemoteProvenanceStorage, | ||||
) -> ProvenanceStorageInterface: | ) -> ProvenanceStorageInterface: | ||||
"""Return a working and initialized ProvenanceStorageInterface object""" | """Return a working and initialized ProvenanceStorageInterface object""" | ||||
if request.param == "remote": | if request.param == "remote": | ||||
Show All 18 Lines | ) -> ProvenanceInterface: | ||||
from swh.core.cli.db import populate_database_for_package | from swh.core.cli.db import populate_database_for_package | ||||
populate_database_for_package( | populate_database_for_package( | ||||
"swh.provenance", provenance_postgresql.dsn, flavor="with-path" | "swh.provenance", provenance_postgresql.dsn, flavor="with-path" | ||||
) | ) | ||||
# in test sessions, we DO want to raise any exception occurring at commit time | # in test sessions, we DO want to raise any exception occurring at commit time | ||||
return get_provenance( | return get_provenance( | ||||
cls="local", db=provenance_postgresql.get_dsn_parameters(), raise_on_commit=True | cls="postgresql", | ||||
db=provenance_postgresql.get_dsn_parameters(), | |||||
raise_on_commit=True, | |||||
) | ) | ||||
@pytest.fixture | @pytest.fixture | ||||
def archive(swh_storage: StorageInterface) -> ArchiveInterface: | def archive(swh_storage: StorageInterface) -> ArchiveInterface: | ||||
"""Return an ArchiveStorage-based ArchiveInterface object""" | """Return an ArchiveStorage-based ArchiveInterface object""" | ||||
return ArchiveStorage(swh_storage) | return ArchiveStorage(swh_storage) | ||||
Show All 35 Lines |