Migrate Notifications interface patterns
This commit is contained in:
@@ -21,12 +21,14 @@ from govoplan_notifications.backend.db.models import NotificationDeliveryAttempt
|
||||
from govoplan_notifications.backend.router import api_get_notification, api_list_notifications, api_notification_summary, api_update_notification
|
||||
from govoplan_notifications.backend.schemas import NotificationCreateRequest, NotificationPreferencesUpdateRequest, NotificationUpdateRequest
|
||||
from govoplan_notifications.backend.service import (
|
||||
NotificationError,
|
||||
create_notification,
|
||||
deliver_pending,
|
||||
notification_preferences_response,
|
||||
notification_response,
|
||||
notification_summary,
|
||||
update_notification_preferences,
|
||||
update_notification,
|
||||
)
|
||||
|
||||
|
||||
@@ -222,6 +224,37 @@ class NotificationServiceTests(unittest.TestCase):
|
||||
session.commit()
|
||||
enqueue.assert_not_called()
|
||||
|
||||
def test_cancellation_is_limited_to_locally_controllable_delivery_states(self) -> None:
|
||||
with self.Session() as session:
|
||||
notification = create_notification(
|
||||
session,
|
||||
tenant_id="tenant-1",
|
||||
payload=self._inbox_payload(recipient_id="user-1", subject="Cancellation boundary"),
|
||||
)
|
||||
notification.status = "sent"
|
||||
session.flush()
|
||||
|
||||
with self.assertRaisesRegex(
|
||||
NotificationError,
|
||||
"cannot be cancelled from status sent",
|
||||
):
|
||||
update_notification(
|
||||
session,
|
||||
tenant_id="tenant-1",
|
||||
notification_id=notification.id,
|
||||
payload=NotificationUpdateRequest(status="cancelled"),
|
||||
)
|
||||
|
||||
notification.status = "queued"
|
||||
cancelled = update_notification(
|
||||
session,
|
||||
tenant_id="tenant-1",
|
||||
notification_id=notification.id,
|
||||
payload=NotificationUpdateRequest(status="cancelled"),
|
||||
)
|
||||
self.assertEqual("cancelled", cancelled.status)
|
||||
self.assertIsNotNone(cancelled.cancelled_at)
|
||||
|
||||
def test_action_url_accepts_only_application_relative_paths(self) -> None:
|
||||
payload = self._inbox_payload(recipient_id="user-1", subject="Safe action")
|
||||
safe = payload.model_copy(update={"action_url": "/calendar?event=event-1#details"})
|
||||
|
||||
Reference in New Issue
Block a user