feat: SMTP email notification channel with UI and ingest
Migration 006, email config DB/env, smtplib sender, settings API, Settings UI section, and dispatch on event/problem ingest. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -24,6 +24,65 @@ def test_get_notification_settings_masks_secrets(jwt_headers, client, monkeypatc
|
||||
assert body["telegram"]["bot_token_hint"].endswith("ghij")
|
||||
assert "webhook" in body
|
||||
assert body["webhook"]["enabled"] is False
|
||||
assert "email" in body
|
||||
assert body["email"]["enabled"] is False
|
||||
|
||||
|
||||
def test_put_email_settings_persists_db(jwt_headers, client, db_session, monkeypatch):
|
||||
monkeypatch.setenv("SMTP_ENABLED", "false")
|
||||
monkeypatch.setenv("SMTP_HOST", "")
|
||||
get_settings.cache_clear()
|
||||
|
||||
response = client.put(
|
||||
"/api/v1/settings/notifications/email",
|
||||
headers=jwt_headers,
|
||||
json={
|
||||
"enabled": True,
|
||||
"min_severity": "warning",
|
||||
"smtp_host": "smtp.example.com",
|
||||
"smtp_port": 587,
|
||||
"smtp_user": "monitor",
|
||||
"smtp_password": "secret",
|
||||
"mail_from": "sac@example.com",
|
||||
"mail_to": "admin@example.com,ops@example.com",
|
||||
"smtp_starttls": True,
|
||||
"smtp_ssl": False,
|
||||
},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
body = response.json()
|
||||
assert body["source"] == "db"
|
||||
assert body["configured"] is True
|
||||
assert body["smtp_port"] == 587
|
||||
|
||||
row = db_session.get(NotificationChannel, "email")
|
||||
assert row is not None
|
||||
assert row.smtp_host == "smtp.example.com"
|
||||
assert row.mail_from == "sac@example.com"
|
||||
|
||||
|
||||
def test_post_email_test_success(jwt_headers, client, db_session, monkeypatch):
|
||||
monkeypatch.setenv("SMTP_ENABLED", "false")
|
||||
get_settings.cache_clear()
|
||||
|
||||
db_session.add(
|
||||
NotificationChannel(
|
||||
channel="email",
|
||||
enabled=True,
|
||||
min_severity="warning",
|
||||
smtp_host="smtp.example.com",
|
||||
smtp_port=587,
|
||||
mail_from="sac@example.com",
|
||||
mail_to="admin@example.com",
|
||||
)
|
||||
)
|
||||
db_session.commit()
|
||||
|
||||
with patch("app.api.v1.settings.send_email_test_message") as mock_test:
|
||||
response = client.post("/api/v1/settings/notifications/email/test", headers=jwt_headers)
|
||||
assert response.status_code == 200
|
||||
assert response.json()["ok"] is True
|
||||
mock_test.assert_called_once()
|
||||
|
||||
|
||||
def test_put_webhook_settings_persists_db(jwt_headers, client, db_session, monkeypatch):
|
||||
|
||||
Reference in New Issue
Block a user