Add email delivery for generated reports
This commit is contained in:
+54
-1
@@ -2,7 +2,7 @@ import os
|
||||
|
||||
import pytest
|
||||
|
||||
from pve_backup_report.config import ConfigError, load_config, parse_pbs_servers
|
||||
from pve_backup_report.config import ConfigError, load_config, parse_email_config, parse_pbs_servers
|
||||
|
||||
|
||||
def test_load_config_from_env_file(tmp_path, monkeypatch) -> None:
|
||||
@@ -123,3 +123,56 @@ def test_load_config_rejects_invalid_report_language(tmp_path, monkeypatch) -> N
|
||||
|
||||
with pytest.raises(ConfigError, match="REPORT_LANGUAGE doit valoir fr ou en"):
|
||||
load_config(env_file)
|
||||
|
||||
|
||||
def test_parse_email_config_disabled_by_default() -> None:
|
||||
config = parse_email_config({})
|
||||
|
||||
assert config.enabled is False
|
||||
assert config.smtp_port == 587
|
||||
assert config.smtp_starttls is True
|
||||
assert config.smtp_ssl is False
|
||||
assert config.smtp_to == ()
|
||||
|
||||
|
||||
def test_parse_email_config_enabled() -> None:
|
||||
config = parse_email_config(
|
||||
{
|
||||
"REPORT_EMAIL_ENABLED": "true",
|
||||
"REPORT_EMAIL_SMTP_HOST": "smtp.example.invalid",
|
||||
"REPORT_EMAIL_SMTP_PORT": "465",
|
||||
"REPORT_EMAIL_SMTP_SSL": "true",
|
||||
"REPORT_EMAIL_SMTP_STARTTLS": "false",
|
||||
"REPORT_EMAIL_SMTP_USERNAME": "report@example.invalid",
|
||||
"REPORT_EMAIL_SMTP_PASSWORD": "secret",
|
||||
"REPORT_EMAIL_FROM": "report@example.invalid",
|
||||
"REPORT_EMAIL_TO": "admin@example.invalid,audit@example.invalid",
|
||||
"REPORT_EMAIL_SUBJECT": "Rapport PVE",
|
||||
}
|
||||
)
|
||||
|
||||
assert config.enabled is True
|
||||
assert config.smtp_host == "smtp.example.invalid"
|
||||
assert config.smtp_port == 465
|
||||
assert config.smtp_ssl is True
|
||||
assert config.smtp_starttls is False
|
||||
assert config.smtp_username == "report@example.invalid"
|
||||
assert config.smtp_password == "secret"
|
||||
assert config.smtp_from == "report@example.invalid"
|
||||
assert config.smtp_to == ("admin@example.invalid", "audit@example.invalid")
|
||||
assert config.subject == "Rapport PVE"
|
||||
|
||||
|
||||
def test_parse_email_config_rejects_incomplete_enabled_config() -> None:
|
||||
with pytest.raises(ConfigError, match="configuration email incomplete"):
|
||||
parse_email_config({"REPORT_EMAIL_ENABLED": "true"})
|
||||
|
||||
|
||||
def test_parse_email_config_rejects_conflicting_tls_modes() -> None:
|
||||
with pytest.raises(ConfigError, match="ne peuvent pas etre actifs ensemble"):
|
||||
parse_email_config(
|
||||
{
|
||||
"REPORT_EMAIL_SMTP_SSL": "true",
|
||||
"REPORT_EMAIL_SMTP_STARTTLS": "true",
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user