grantforge-api / backend /tests /test_notifications.py
GrantForge Bot
Deploy sha-9a5957fcdef15b7e2623f8b147cda6026475aee0 — source build (no GHCR)
3a3734f
Raw
History Blame Contribute Delete
1.68 kB
"""Tests for notification inbox and deadline alerts."""
import pytest
from core.notifications.deadline_alerts import send_deadline_alert_email
from core.notifications.inbox import (
NOTIFICATIONS,
add_notification,
create_post_award_deadline_notification,
list_notifications,
mark_read,
)
@pytest.fixture(autouse=True)
def clear_notifications():
NOTIFICATIONS.clear()
yield
NOTIFICATIONS.clear()
def test_add_and_list_notifications():
add_notification(
ntype="info",
title="Test",
body="Tresc",
user_id="user_a",
)
items = list_notifications("user_a")
assert len(items) == 1
assert items[0]["title"] == "Test"
assert items[0]["read"] is False
def test_mark_read():
note = add_notification(
ntype="info",
title="Do odczytu",
body="x",
user_id="user_b",
)
updated = mark_read(note["id"])
assert updated and updated["read"] is True
assert list_notifications("user_b", unread_only=True) == []
def test_deadline_alert_degraded_without_smtp(monkeypatch):
monkeypatch.delenv("SMTP_HOST", raising=False)
result = send_deadline_alert_email("a@example.com", "Subj", "Body")
assert result["status"] == "degraded"
assert "SMTP_HOST" in result["message"]
def test_post_award_deadline_notification_creation():
note = create_post_award_deadline_notification(
project_id="proj-1",
milestone="Raport koncowy",
deadline_iso="2026-12-01T00:00:00+00:00",
)
assert note["type"] == "post_award_deadline"
assert note["project_id"] == "proj-1"
assert note["deadline"].startswith("2026-12-01")