Add email delivery check command

This commit is contained in:
2026-05-20 15:29:19 +02:00
parent 6bdddc3d54
commit 86f7c0589c
8 changed files with 157 additions and 8 deletions
+42
View File
@@ -41,6 +41,12 @@ def test_cli_has_dump_pbs_users() -> None:
assert args.dump_pbs_users is True
def test_cli_has_check_email() -> None:
args = build_parser().parse_args(["--check-email"])
assert args.check_email is True
def test_dump_report_data_does_not_export_sensitive_raw_fields(
monkeypatch,
capsys,
@@ -246,3 +252,39 @@ def test_generate_pdf_sends_email_when_enabled(tmp_path, monkeypatch) -> None:
assert run(["--generate-pdf"]) == 0
assert sent == [("smtp.example.invalid", pdf_path)]
def test_check_email_sends_test_email(monkeypatch) -> None:
config = AppConfig(
pve_api_url="https://pve.example.invalid:8006",
pve_api_token_id="backup-report@pve!report",
pve_api_token_secret="secret",
report_output_dir=Path("reports"),
report_timezone="Europe/Paris",
pve_verify_tls=True,
pve_ca_bundle=None,
pve_timeout_seconds=30,
pve_backup_jobs_endpoint="/cluster/backup",
pve_task_history_limit=500,
pve_task_log_limit=5000,
pbs_hostnames={},
pbs_servers=(),
log_level="INFO",
report_filename_prefix="rapport-sauvegardes-pve",
email=EmailConfig(
enabled=True,
smtp_host="smtp.example.invalid",
smtp_from="report@example.invalid",
smtp_to=("admin@example.invalid",),
),
)
sent = []
monkeypatch.setattr("pve_backup_report.cli.load_config", lambda: config)
monkeypatch.setattr(
"pve_backup_report.cli.send_test_email",
lambda email_config: sent.append(email_config.smtp_host),
)
assert run(["--check-email"]) == 0
assert sent == ["smtp.example.invalid"]