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)
|
||||
|
||||
@@ -235,6 +235,27 @@ def test_render_html_keeps_css_unescaped() -> None:
|
||||
assert '<h1 class="section-group-title">Retention des sauvegardes VM/CT</h1>' not in html
|
||||
|
||||
|
||||
def test_render_html_supports_english_labels() -> None:
|
||||
report_data = ReportData(
|
||||
coverage=[
|
||||
BackupCoverage(
|
||||
guest=Guest(vmid=100, name="srv", guest_type="qemu"),
|
||||
status="non_sauvegardee",
|
||||
)
|
||||
],
|
||||
summary=ReportSummary(generated_at=datetime(2026, 5, 9, 2, 0)),
|
||||
)
|
||||
|
||||
html = render_html(report_data, language="en")
|
||||
|
||||
assert '<html lang="en">' in html
|
||||
assert "Proxmox VE Backup Report" in html
|
||||
assert "Table of contents" in html
|
||||
assert "VM/CT without backup" in html
|
||||
assert "not specified" in html
|
||||
assert "Rapport des sauvegardes Proxmox VE" not in html
|
||||
|
||||
|
||||
def test_pdf_pbs_access_users_table_keeps_expected_fields_without_raw_secrets() -> None:
|
||||
report_data = ReportData(
|
||||
pbs_access_users=[
|
||||
|
||||
Reference in New Issue
Block a user