Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/tests/test_server.py
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | |||||
def test_load_and_check_config_wrong_configuration(tmpdir): | def test_load_and_check_config_wrong_configuration(tmpdir): | ||||
"""Wrong configuration raises""" | """Wrong configuration raises""" | ||||
config_path = prepare_config_file(tmpdir, "something: useless") | config_path = prepare_config_file(tmpdir, "something: useless") | ||||
with pytest.raises(KeyError, match="Missing '%scheduler' configuration"): | with pytest.raises(KeyError, match="Missing '%scheduler' configuration"): | ||||
load_and_check_config(config_path) | load_and_check_config(config_path) | ||||
def test_load_and_check_config_remote_config_local_type_raise(tmpdir): | def test_load_and_check_config_remote_config_local_type_raise(tmpdir): | ||||
"""Configuration without 'local' storage is rejected""" | """Configuration without 'postgresql' storage is rejected""" | ||||
config = {"scheduler": {"cls": "remote"}} | config_path = prepare_config_file(tmpdir, {"scheduler": {"cls": "remote"}}) | ||||
config_path = prepare_config_file(tmpdir, config) | with pytest.raises(ValueError, match="'postgresql'"): | ||||
expected_error = ( | load_and_check_config(config_path) | ||||
"The scheduler backend can only be started with a 'postgresql'" " configuration" | |||||
) | |||||
with pytest.raises(ValueError, match=expected_error): | |||||
load_and_check_config(config_path, type="local") | |||||
def test_load_and_check_config_local_incomplete_configuration(tmpdir): | def test_load_and_check_config_local_incomplete_configuration(tmpdir): | ||||
"""Incomplete 'local' configuration should raise""" | """Incomplete 'local' configuration should raise""" | ||||
config = { | config = { | ||||
"scheduler": { | "scheduler": { | ||||
"cls": "postgresql", | "cls": "postgresql", | ||||
"something": "needed-for-test", | "something": "needed-for-test", | ||||
} | } | ||||
} | } | ||||
config_path = prepare_config_file(tmpdir, config) | config_path = prepare_config_file(tmpdir, config) | ||||
expected_error = "Invalid configuration; missing 'db' config entry" | expected_error = "Invalid configuration; missing 'db' config entry" | ||||
with pytest.raises(KeyError, match=expected_error): | with pytest.raises(KeyError, match=expected_error): | ||||
load_and_check_config(config_path) | load_and_check_config(config_path) | ||||
def test_load_and_check_config_local_config_fine(tmpdir): | @pytest.mark.parametrize("clazz", ["local", "postgresql"]) | ||||
def test_load_and_check_config_local_config_fine(tmpdir, clazz): | |||||
"""Local configuration is fine""" | """Local configuration is fine""" | ||||
config = { | config = { | ||||
"scheduler": { | "scheduler": { | ||||
"cls": "postgresql", | "cls": clazz, | ||||
"db": "db", | "db": "db", | ||||
} | } | ||||
} | } | ||||
config_path = prepare_config_file(tmpdir, config) | config_path = prepare_config_file(tmpdir, config) | ||||
cfg = load_and_check_config(config_path, type="local") | cfg = load_and_check_config(config_path, type="postgresql") | ||||
assert cfg == config | assert cfg == config | ||||
def test_load_and_check_config_remote_config_fine(tmpdir): | def test_load_and_check_config_remote_config_fine(tmpdir): | ||||
"""Remote configuration is fine""" | """Remote configuration is fine""" | ||||
config = {"scheduler": {"cls": "remote"}} | config = {"scheduler": {"cls": "remote"}} | ||||
config_path = prepare_config_file(tmpdir, config) | config_path = prepare_config_file(tmpdir, config) | ||||
cfg = load_and_check_config(config_path, type="any") | cfg = load_and_check_config(config_path, type="any") | ||||
assert cfg == config | assert cfg == config |