11import pytest
2+ import redis .asyncio as redis
23from app .domain .enums import NotificationChannel , NotificationSeverity , NotificationStatus
3- from app .schemas_pydantic .execution import ExecutionResponse
4+ from app .schemas_pydantic .execution import ExecutionRequest
45from app .schemas_pydantic .notification import (
56 DeleteNotificationResponse ,
67 NotificationListResponse ,
7- NotificationResponse ,
88 NotificationSubscription ,
99 SubscriptionsResponse ,
1010 UnreadCountResponse ,
1111)
1212from httpx import AsyncClient
1313
14+ from tests .e2e .conftest import create_execution_with_notification
15+
1416pytestmark = [pytest .mark .e2e , pytest .mark .kafka ]
1517
1618
@@ -104,10 +106,11 @@ async def test_mark_nonexistent_notification_read(
104106 async def test_mark_notification_read (
105107 self ,
106108 test_user : AsyncClient ,
107- execution_with_notification : tuple [ExecutionResponse , NotificationResponse ],
109+ redis_client : redis .Redis ,
110+ exec_request : ExecutionRequest ,
108111 ) -> None :
109112 """Mark existing notification as read."""
110- _ , notification = execution_with_notification
113+ _ , notification = await create_execution_with_notification ( test_user , redis_client , exec_request )
111114
112115 response = await test_user .put (
113116 f"/api/v1/notifications/{ notification .notification_id } /read"
@@ -131,19 +134,19 @@ class TestMarkAllRead:
131134 async def test_mark_all_read (
132135 self ,
133136 test_user : AsyncClient ,
134- execution_with_notification : tuple [ExecutionResponse , NotificationResponse ],
137+ redis_client : redis .Redis ,
138+ exec_request : ExecutionRequest ,
135139 ) -> None :
136140 """Mark all notifications as read returns 204."""
137- _ , notification = execution_with_notification
141+ _ , notification = await create_execution_with_notification ( test_user , redis_client , exec_request )
138142
139143 response = await test_user .post ("/api/v1/notifications/mark-all-read" )
140144 assert response .status_code == 204
141145
142146 # Verify the specific notification was marked as read.
143147 # We assert on the individual notification rather than global unread_count
144- # because other tests create executions (via created_execution without
145- # waiting for notifications) whose async notifications can arrive between
146- # mark-all-read and any subsequent count query.
148+ # because other tests create executions whose async notifications can
149+ # arrive between mark-all-read and any subsequent count query.
147150 resp = await test_user .get ("/api/v1/notifications" )
148151 assert resp .status_code == 200
149152 result = NotificationListResponse .model_validate (resp .json ())
@@ -284,9 +287,12 @@ class TestUnreadCount:
284287 async def test_get_unread_count (
285288 self ,
286289 test_user : AsyncClient ,
287- execution_with_notification : tuple [ExecutionResponse , NotificationResponse ],
290+ redis_client : redis .Redis ,
291+ exec_request : ExecutionRequest ,
288292 ) -> None :
289293 """Get unread notification count."""
294+ await create_execution_with_notification (test_user , redis_client , exec_request )
295+
290296 response = await test_user .get ("/api/v1/notifications/unread-count" )
291297
292298 assert response .status_code == 200
@@ -313,10 +319,11 @@ async def test_delete_nonexistent_notification(
313319 async def test_delete_notification (
314320 self ,
315321 test_user : AsyncClient ,
316- execution_with_notification : tuple [ExecutionResponse , NotificationResponse ],
322+ redis_client : redis .Redis ,
323+ exec_request : ExecutionRequest ,
317324 ) -> None :
318325 """Delete existing notification returns success."""
319- _ , notification = execution_with_notification
326+ _ , notification = await create_execution_with_notification ( test_user , redis_client , exec_request )
320327
321328 response = await test_user .delete (
322329 f"/api/v1/notifications/{ notification .notification_id } "
@@ -342,10 +349,11 @@ async def test_user_cannot_see_other_users_notifications(
342349 self ,
343350 test_user : AsyncClient ,
344351 another_user : AsyncClient ,
345- execution_with_notification : tuple [ExecutionResponse , NotificationResponse ],
352+ redis_client : redis .Redis ,
353+ exec_request : ExecutionRequest ,
346354 ) -> None :
347355 """User's notification list does not include other users' notifications."""
348- _ , notification = execution_with_notification
356+ _ , notification = await create_execution_with_notification ( test_user , redis_client , exec_request )
349357
350358 response = await another_user .get ("/api/v1/notifications" )
351359 assert response .status_code == 200
@@ -360,10 +368,11 @@ async def test_cannot_mark_other_users_notification_read(
360368 self ,
361369 test_user : AsyncClient ,
362370 another_user : AsyncClient ,
363- execution_with_notification : tuple [ExecutionResponse , NotificationResponse ],
371+ redis_client : redis .Redis ,
372+ exec_request : ExecutionRequest ,
364373 ) -> None :
365374 """Cannot mark another user's notification as read."""
366- _ , notification = execution_with_notification
375+ _ , notification = await create_execution_with_notification ( test_user , redis_client , exec_request )
367376
368377 response = await another_user .put (
369378 f"/api/v1/notifications/{ notification .notification_id } /read"
@@ -382,10 +391,11 @@ async def test_cannot_delete_other_users_notification(
382391 self ,
383392 test_user : AsyncClient ,
384393 another_user : AsyncClient ,
385- execution_with_notification : tuple [ExecutionResponse , NotificationResponse ],
394+ redis_client : redis .Redis ,
395+ exec_request : ExecutionRequest ,
386396 ) -> None :
387397 """Cannot delete another user's notification."""
388- _ , notification = execution_with_notification
398+ _ , notification = await create_execution_with_notification ( test_user , redis_client , exec_request )
389399
390400 response = await another_user .delete (
391401 f"/api/v1/notifications/{ notification .notification_id } "
0 commit comments