You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/tests/test_config.py

32 lines
993 B
Python

"""The panel starts without a prefilled host or administrator config file."""
from dataclasses import replace
from pathlib import Path
import pytest
from virsh_panel.config import PROJECT_DIR, Settings
def test_default_data_directory_stays_inside_project(monkeypatch):
monkeypatch.delenv("PANEL_DATA_DIR", raising=False)
assert Settings.from_env().data_dir == PROJECT_DIR / "data"
def test_runtime_settings_require_no_host_or_admin_values(tmp_path):
settings = Settings(data_dir=tmp_path)
settings.validate()
assert settings.secure_cookie is True
assert settings.ssh_binary == "ssh"
@pytest.mark.parametrize("bad_path", [Path("relative/data"), Path("/")])
def test_rejects_unsafe_data_directory(bad_path):
with pytest.raises(ValueError):
replace(Settings(), data_dir=bad_path).validate()
def test_rejects_missing_static_assets(tmp_path):
with pytest.raises(ValueError):
replace(Settings(), static_dir=tmp_path / "missing").validate()