Add configurable report language
This commit is contained in:
@@ -23,6 +23,7 @@ def test_load_config_from_env_file(tmp_path, monkeypatch) -> None:
|
||||
monkeypatch.delenv("PVE_API_URL", raising=False)
|
||||
monkeypatch.delenv("PVE_API_TOKEN_ID", raising=False)
|
||||
monkeypatch.delenv("PVE_API_TOKEN_SECRET", raising=False)
|
||||
monkeypatch.delenv("REPORT_LANGUAGE", raising=False)
|
||||
for key in list(os.environ):
|
||||
if key.startswith("PBS") and key != "PBS_HOSTNAMES":
|
||||
monkeypatch.delenv(key, raising=False)
|
||||
@@ -35,6 +36,7 @@ def test_load_config_from_env_file(tmp_path, monkeypatch) -> None:
|
||||
assert config.pve_backup_jobs_endpoint == "/cluster/backup"
|
||||
assert config.pve_task_history_limit == 500
|
||||
assert config.pve_task_log_limit == 5000
|
||||
assert config.report_language == "fr"
|
||||
assert config.configured_pbs_servers == ()
|
||||
assert config.pbs_hostnames == {
|
||||
"192.0.2.10": "backup-a",
|
||||
@@ -76,3 +78,48 @@ def test_parse_pbs_servers_rejects_incomplete_api_block() -> None:
|
||||
pve_verify_tls=True,
|
||||
pve_timeout_seconds=30,
|
||||
)
|
||||
|
||||
|
||||
def test_load_config_accepts_report_language(tmp_path, monkeypatch) -> None:
|
||||
env_file = tmp_path / ".env"
|
||||
env_file.write_text(
|
||||
"\n".join(
|
||||
[
|
||||
"PVE_API_URL=https://pve.example.invalid:8006",
|
||||
"PVE_API_TOKEN_ID=backup-report@pve!report",
|
||||
"PVE_API_TOKEN_SECRET=secret",
|
||||
"REPORT_LANGUAGE=en",
|
||||
]
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
monkeypatch.delenv("PVE_API_URL", raising=False)
|
||||
monkeypatch.delenv("PVE_API_TOKEN_ID", raising=False)
|
||||
monkeypatch.delenv("PVE_API_TOKEN_SECRET", raising=False)
|
||||
monkeypatch.delenv("REPORT_LANGUAGE", raising=False)
|
||||
|
||||
config = load_config(env_file)
|
||||
|
||||
assert config.report_language == "en"
|
||||
|
||||
|
||||
def test_load_config_rejects_invalid_report_language(tmp_path, monkeypatch) -> None:
|
||||
env_file = tmp_path / ".env"
|
||||
env_file.write_text(
|
||||
"\n".join(
|
||||
[
|
||||
"PVE_API_URL=https://pve.example.invalid:8006",
|
||||
"PVE_API_TOKEN_ID=backup-report@pve!report",
|
||||
"PVE_API_TOKEN_SECRET=secret",
|
||||
"REPORT_LANGUAGE=de",
|
||||
]
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
monkeypatch.delenv("PVE_API_URL", raising=False)
|
||||
monkeypatch.delenv("PVE_API_TOKEN_ID", raising=False)
|
||||
monkeypatch.delenv("PVE_API_TOKEN_SECRET", raising=False)
|
||||
monkeypatch.delenv("REPORT_LANGUAGE", raising=False)
|
||||
|
||||
with pytest.raises(ConfigError, match="REPORT_LANGUAGE doit valoir fr ou en"):
|
||||
load_config(env_file)
|
||||
|
||||
Reference in New Issue
Block a user