Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/tests/conftest.py
# Copyright (C) 2020 The Software Heritage developers | # Copyright (C) 2020 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 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 | ||||
import yaml | |||||
from swh.core.db.pytest_plugin import postgresql_fact | from swh.core.db.pytest_plugin import postgresql_fact | ||||
from swh.storage.tests import SQL_DIR as STORAGE_SQL_DIR | from swh.storage.tests import SQL_DIR as STORAGE_SQL_DIR | ||||
import swh.vault | import swh.vault | ||||
from swh.vault import get_vault | from swh.vault import get_vault | ||||
os.environ["LC_ALL"] = "C.UTF-8" | os.environ["LC_ALL"] = "C.UTF-8" | ||||
Show All 39 Lines | return { | ||||
"db": postgres_storage.dsn, | "db": postgres_storage.dsn, | ||||
"objstorage": { | "objstorage": { | ||||
"cls": "pathslicing", | "cls": "pathslicing", | ||||
"args": {"root": tmp_path, "slicing": "0:1/1:5",}, | "args": {"root": tmp_path, "slicing": "0:1/1:5",}, | ||||
}, | }, | ||||
}, | }, | ||||
"cache": { | "cache": { | ||||
"cls": "pathslicing", | "cls": "pathslicing", | ||||
"args": {"root": tmp_path, "slicing": "0:1/1:5", "allow_delete": True,}, | "args": {"root": tmp_path, "slicing": "0:1/1:5", "allow_delete": True}, | ||||
}, | }, | ||||
"scheduler": {"cls": "remote", "url": "http://swh-scheduler:5008",}, | "scheduler": {"cls": "remote", "url": "http://swh-scheduler:5008",}, | ||||
} | } | ||||
@pytest.fixture | @pytest.fixture | ||||
def swh_local_vault_config(swh_vault_config: Dict[str, Any]) -> Dict[str, Any]: | |||||
return { | |||||
"vault": {"cls": "local", "args": swh_vault_config}, | |||||
"client_max_size": 1024 ** 3, | |||||
} | |||||
@pytest.fixture | |||||
def swh_vault_config_file(swh_local_vault_config, monkeypatch, tmp_path): | |||||
conf_path = os.path.join(str(tmp_path), "vault-server.yml") | |||||
with open(conf_path, "w") as f: | |||||
f.write(yaml.dump(swh_local_vault_config)) | |||||
monkeypatch.setenv("SWH_CONFIG_FILENAME", conf_path) | |||||
return conf_path | |||||
@pytest.fixture | |||||
def swh_vault(request, swh_vault_config): | def swh_vault(request, swh_vault_config): | ||||
return get_vault("local", **swh_vault_config) | return get_vault("local", **swh_vault_config) | ||||
@pytest.fixture | @pytest.fixture | ||||
def swh_storage(swh_vault): | def swh_storage(swh_vault): | ||||
return swh_vault.storage | return swh_vault.storage |