"""Tests for SAC webhook notification helpers.""" from datetime import datetime, timezone from unittest.mock import patch from app.models import Event from app.services import webhook_notify from app.services.notification_settings import WebhookConfig def test_notify_event_respects_min_severity(): sent: list[dict] = [] def fake_send(payload: dict, **kwargs) -> None: sent.append(payload) event = Event( event_id="00000000-0000-4000-8000-000000000201", host_id=1, occurred_at=datetime(2026, 5, 29, 12, 0, tzinfo=timezone.utc), category="auth", type="rdp.login.failed", severity="warning", title="failed", summary="e2e", payload={}, ) cfg = WebhookConfig( enabled=True, url="https://example.com/hook", secret_header="", secret="", min_severity="high", source="env", ) with patch.object(webhook_notify, "get_effective_webhook_config", return_value=cfg): with patch.object(webhook_notify, "send_webhook_payload", side_effect=fake_send): webhook_notify.notify_event(event) assert sent == [] cfg_high = WebhookConfig( enabled=True, url="https://example.com/hook", secret_header="", secret="", min_severity="warning", source="env", ) event.severity = "warning" with patch.object(webhook_notify, "get_effective_webhook_config", return_value=cfg_high): with patch.object(webhook_notify, "send_webhook_payload", side_effect=fake_send): webhook_notify.notify_event(event) assert len(sent) == 1 assert sent[0]["kind"] == "event"