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
@@ -3,8 +3,10 @@ from pathlib import Path
from pve_backup_report.config import EmailConfig
from pve_backup_report.email_report import (
build_report_message,
EmailReportError,
message_id_domain,
send_report_email,
send_test_email,
)
@@ -41,6 +43,46 @@ def test_message_id_domain_uses_sender_domain() -> None:
assert message_id_domain(None) is None
def test_send_test_email_builds_message_without_attachment(monkeypatch) -> None:
sent = []
config = EmailConfig(
enabled=True,
smtp_host="smtp.example.invalid",
smtp_from="report@example.invalid",
smtp_to=("admin@example.invalid",),
subject="Rapport PVE",
)
monkeypatch.setattr(
"pve_backup_report.email_report.send_email_message",
lambda email_config, message: sent.append((email_config, message)),
)
send_test_email(config)
assert sent[0][0] == config
message = sent[0][1]
assert message["Subject"] == "[TEST] Rapport PVE"
assert message["To"] == "admin@example.invalid"
assert list(message.iter_attachments()) == []
def test_send_test_email_requires_enabled_config() -> None:
config = EmailConfig(
enabled=False,
smtp_host="smtp.example.invalid",
smtp_from="report@example.invalid",
smtp_to=("admin@example.invalid",),
)
try:
send_test_email(config)
except EmailReportError as exc:
assert "REPORT_EMAIL_ENABLED=false" in str(exc)
else:
raise AssertionError("EmailReportError attendu")
def test_send_report_email_uses_starttls_and_auth(tmp_path: Path, monkeypatch) -> None:
pdf_path = tmp_path / "rapport.pdf"
pdf_path.write_bytes(b"%PDF-1.7")