Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/tests/test_init_cookers.py
# Copyright (C) 2017-2020 The Software Heritage developers | # Copyright (C) 2017-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 Dict | from typing import Dict | ||||
import pytest | import pytest | ||||
import yaml | import yaml | ||||
from swh.vault.cookers import COOKER_TYPES, get_cooker | from swh.vault.cookers import COOKER_TYPES, get_cooker | ||||
from swh.vault.tests.test_backend import TEST_HEX_ID | from swh.vault.tests.test_backend import TEST_SWHID | ||||
@pytest.fixture | @pytest.fixture | ||||
def swh_cooker_config(): | def swh_cooker_config(): | ||||
return { | return { | ||||
"vault": { | "vault": { | ||||
"cls": "remote", | "cls": "remote", | ||||
"args": { | "args": { | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | def test_get_cooker_config_ko( | ||||
config_ko, exception_class, exception_msg, monkeypatch, tmp_path | config_ko, exception_class, exception_msg, monkeypatch, tmp_path | ||||
): | ): | ||||
"""Misconfigured cooker should fail the instantiation with exception message | """Misconfigured cooker should fail the instantiation with exception message | ||||
""" | """ | ||||
write_config_to_env(config_ko, tmp_path, monkeypatch) | write_config_to_env(config_ko, tmp_path, monkeypatch) | ||||
with pytest.raises(exception_class, match=exception_msg): | with pytest.raises(exception_class, match=exception_msg): | ||||
get_cooker("directory", TEST_HEX_ID) | get_cooker("flat", TEST_SWHID) | ||||
@pytest.mark.parametrize( | @pytest.mark.parametrize( | ||||
"config_ok", | "config_ok", | ||||
[ | [ | ||||
{ | { | ||||
"vault": { | "vault": { | ||||
"cls": "remote", | "cls": "remote", | ||||
Show All 15 Lines | |||||
) | ) | ||||
def test_get_cooker_nominal(config_ok, tmp_path, monkeypatch): | def test_get_cooker_nominal(config_ok, tmp_path, monkeypatch): | ||||
"""Correct configuration should allow the instantiation of the cookers | """Correct configuration should allow the instantiation of the cookers | ||||
""" | """ | ||||
for cooker_type in COOKER_TYPES.keys(): | for cooker_type in COOKER_TYPES.keys(): | ||||
write_config_to_env(config_ok, tmp_path, monkeypatch) | write_config_to_env(config_ok, tmp_path, monkeypatch) | ||||
cooker = get_cooker(cooker_type, TEST_HEX_ID) | cooker = get_cooker(cooker_type, TEST_SWHID) | ||||
assert cooker is not None | assert cooker is not None | ||||
assert isinstance(cooker, COOKER_TYPES[cooker_type]) | assert isinstance(cooker, tuple(COOKER_TYPES[cooker_type])) |