vigilar/tests/unit/test_sender.py
Aaron D. Lee 2c79e0c044 feat(F1): notification content mapping and Web Push sender
Add vigilar/alerts/sender.py with _CONTENT_MAP for human-readable push
notification titles/bodies, build_notification(), and send_alert() which
retrieves VAPID key, iterates push subscriptions, calls pywebpush, and
logs results to alert_log with auto-cleanup of expired (410) endpoints.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-03 18:01:07 -04:00

39 lines
1.4 KiB
Python

"""Tests for notification content builder and Web Push sender."""
from vigilar.alerts.sender import build_notification
from vigilar.constants import EventType, Severity
def test_build_notification_person_detected():
result = build_notification(EventType.PERSON_DETECTED, Severity.WARNING, "front_entrance", {})
assert result["title"] == "Person Detected"
assert "Front Entrance" in result["body"]
def test_build_notification_pet_escape():
result = build_notification(EventType.PET_ESCAPE, Severity.ALERT, "back_deck", {"pet_name": "Angel"})
assert result["title"] == "Pet Alert"
assert "Angel" in result["body"]
def test_build_notification_wildlife_predator():
result = build_notification(EventType.WILDLIFE_PREDATOR, Severity.CRITICAL, "front_entrance", {"species": "bear"})
assert result["title"] == "Wildlife Alert"
assert "bear" in result["body"].lower()
def test_build_notification_power_loss():
result = build_notification(EventType.POWER_LOSS, Severity.CRITICAL, "ups", {})
assert result["title"] == "Power Alert"
assert "battery" in result["body"].lower()
def test_build_notification_unknown_event_type():
result = build_notification(EventType.MOTION_START, Severity.WARNING, "cam1", {})
assert result["title"] == "Vigilar Alert"
def test_build_notification_has_url():
result = build_notification(EventType.PERSON_DETECTED, Severity.WARNING, "front", {})
assert "url" in result