Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/tests/conftest.py
# Copyright (C) 2020 The Software Heritage developers | # Copyright (C) 2020-2022 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 functools import partial | from functools import partial | ||||
import os | import os | ||||
from typing import Any, Dict | from typing import Any, Dict | ||||
import pkg_resources.extern.packaging.version | import pkg_resources.extern.packaging.version | ||||
import pytest | import pytest | ||||
from pytest_postgresql import factories | from pytest_postgresql import factories | ||||
from swh.core.db.pytest_plugin import initialize_database_for_module, postgresql_fact | from swh.core.db.pytest_plugin import initialize_database_for_module, postgresql_fact | ||||
from swh.storage.postgresql.db import Db as StorageDb | |||||
from swh.vault import get_vault | from swh.vault import get_vault | ||||
from swh.vault.backend import VaultBackend | from swh.vault.backend import VaultBackend | ||||
os.environ["LC_ALL"] = "C.UTF-8" | os.environ["LC_ALL"] = "C.UTF-8" | ||||
# needed for directory tests on git-cloned repositories | # needed for directory tests on git-cloned repositories | ||||
# 022 is usually the default value, but some environments (eg. Debian builds) have | # 022 is usually the default value, but some environments (eg. Debian builds) have | ||||
# a different one. | # a different one. | ||||
os.umask(0o022) | os.umask(0o022) | ||||
pytest_v = pkg_resources.get_distribution("pytest").parsed_version | pytest_v = pkg_resources.get_distribution("pytest").parsed_version | ||||
if pytest_v < pkg_resources.extern.packaging.version.parse("3.9"): | if pytest_v < pkg_resources.extern.packaging.version.parse("3.9"): | ||||
@pytest.fixture | @pytest.fixture | ||||
def tmp_path(): | def tmp_path(): | ||||
import pathlib | import pathlib | ||||
import tempfile | import tempfile | ||||
with tempfile.TemporaryDirectory() as tmpdir: | with tempfile.TemporaryDirectory() as tmpdir: | ||||
yield pathlib.Path(tmpdir) | yield pathlib.Path(tmpdir) | ||||
storage_postgresql_proc = factories.postgresql_proc( | |||||
dbname="storage", | |||||
load=[ | |||||
partial(initialize_database_for_module, "storage", StorageDb.current_version) | |||||
], | |||||
) | |||||
vault_postgresql_proc = factories.postgresql_proc( | vault_postgresql_proc = factories.postgresql_proc( | ||||
dbname="vault", | dbname="vault", | ||||
load=[ | load=[ | ||||
partial(initialize_database_for_module, "vault", VaultBackend.current_version) | partial(initialize_database_for_module, "vault", VaultBackend.current_version) | ||||
], | ], | ||||
) | ) | ||||
postgres_vault = postgresql_fact("vault_postgresql_proc") | postgres_vault = postgresql_fact("vault_postgresql_proc") | ||||
postgres_storage = postgresql_fact( | |||||
"storage_postgresql_proc", | |||||
no_db_drop=True, # keep the db for performance reasons | |||||
) | |||||
@pytest.fixture | @pytest.fixture | ||||
def swh_vault_config(postgres_vault, postgres_storage, tmp_path) -> Dict[str, Any]: | def swh_vault_config(postgres_vault, tmp_path) -> Dict[str, Any]: | ||||
tmp_path = str(tmp_path) | tmp_path = str(tmp_path) | ||||
return { | return { | ||||
"db": postgres_vault.dsn, | "db": postgres_vault.dsn, | ||||
"storage": { | "storage": { | ||||
"cls": "postgresql", | "cls": "memory", | ||||
"db": postgres_storage.dsn, | |||||
"objstorage": { | |||||
"cls": "pathslicing", | |||||
"root": tmp_path, | |||||
"slicing": "0:1/1:5", | |||||
}, | |||||
}, | }, | ||||
"cache": { | "cache": { | ||||
"cls": "pathslicing", | "cls": "pathslicing", | ||||
"root": tmp_path, | "root": tmp_path, | ||||
"slicing": "0:1/1:5", | "slicing": "0:1/1:5", | ||||
"allow_delete": True, | "allow_delete": True, | ||||
}, | }, | ||||
"scheduler": { | "scheduler": { | ||||
Show All 14 Lines |