2626 TextPart ,
2727)
2828from a2a .utils import proto_utils
29+ from a2a .utils .errors import ServerError
2930
3031
3132# Fixtures
@@ -38,7 +39,7 @@ def mock_grpc_stub() -> AsyncMock:
3839 stub .GetTask = AsyncMock ()
3940 stub .CancelTask = AsyncMock ()
4041 stub .CreateTaskPushNotificationConfig = AsyncMock ()
41- stub .GetTaskPushNotification = AsyncMock ()
42+ stub .GetTaskPushNotificationConfig = AsyncMock ()
4243 return stub
4344
4445
@@ -292,3 +293,109 @@ async def test_cancel_task(
292293 a2a_pb2 .CancelTaskRequest (name = f'tasks/{ sample_task .id } ' )
293294 )
294295 assert response .status .state == TaskState .canceled
296+
297+
298+ @pytest .mark .asyncio
299+ async def test_set_task_callback_with_valid_task (
300+ grpc_client : A2AGrpcClient ,
301+ mock_grpc_stub : AsyncMock ,
302+ sample_task_push_notification_config : TaskPushNotificationConfig ,
303+ ):
304+ """Test setting a task push notification config with a valid task id."""
305+ mock_grpc_stub .CreateTaskPushNotificationConfig .return_value = (
306+ a2a_pb2 .CreateTaskPushNotificationConfigRequest (
307+ parent = 'tasks/task-1' ,
308+ config_id = 'config-1' ,
309+ config = proto_utils .ToProto .task_push_notification_config (
310+ sample_task_push_notification_config
311+ ),
312+ )
313+ )
314+
315+ response = await grpc_client .set_task_callback (
316+ sample_task_push_notification_config
317+ )
318+
319+ mock_grpc_stub .CreateTaskPushNotificationConfig .assert_awaited_once_with (
320+ a2a_pb2 .CreateTaskPushNotificationConfigRequest (
321+ config = proto_utils .ToProto .task_push_notification_config (
322+ sample_task_push_notification_config
323+ ),
324+ )
325+ )
326+ assert response .taskId == 'task-1'
327+
328+
329+ @pytest .mark .asyncio
330+ async def test_set_task_callback_with_invalid_task (
331+ grpc_client : A2AGrpcClient ,
332+ mock_grpc_stub : AsyncMock ,
333+ sample_task_push_notification_config : TaskPushNotificationConfig ,
334+ ):
335+ """Test setting a task push notification config with a invalid task id."""
336+ mock_grpc_stub .CreateTaskPushNotificationConfig .return_value = (
337+ a2a_pb2 .CreateTaskPushNotificationConfigRequest (
338+ parent = 'invalid-path-to-tasks/task-1' ,
339+ config_id = 'config-1' ,
340+ config = proto_utils .ToProto .task_push_notification_config (
341+ sample_task_push_notification_config
342+ ),
343+ )
344+ )
345+
346+ with pytest .raises (ServerError ) as exc_info :
347+ await grpc_client .set_task_callback (
348+ sample_task_push_notification_config
349+ )
350+ assert 'No task for' in exc_info .value .error .message
351+
352+
353+ @pytest .mark .asyncio
354+ async def test_get_task_callback_with_valid_task (
355+ grpc_client : A2AGrpcClient ,
356+ mock_grpc_stub : AsyncMock ,
357+ sample_task_push_notification_config : TaskPushNotificationConfig ,
358+ ):
359+ """Test retrieving a task push notification config with a valid task id."""
360+ mock_grpc_stub .GetTaskPushNotificationConfig .return_value = (
361+ a2a_pb2 .CreateTaskPushNotificationConfigRequest (
362+ parent = 'tasks/task-1' ,
363+ config_id = 'config-1' ,
364+ config = proto_utils .ToProto .task_push_notification_config (
365+ sample_task_push_notification_config
366+ ),
367+ )
368+ )
369+ params = TaskIdParams (id = sample_task_push_notification_config .taskId )
370+
371+ response = await grpc_client .get_task_callback (params )
372+
373+ mock_grpc_stub .GetTaskPushNotificationConfig .assert_awaited_once_with (
374+ a2a_pb2 .GetTaskPushNotificationConfigRequest (
375+ name = f'tasks/{ params .id } /pushNotification/undefined' ,
376+ )
377+ )
378+ assert response .taskId == 'task-1'
379+
380+
381+ @pytest .mark .asyncio
382+ async def test_get_task_callback_with_invalid_task (
383+ grpc_client : A2AGrpcClient ,
384+ mock_grpc_stub : AsyncMock ,
385+ sample_task_push_notification_config : TaskPushNotificationConfig ,
386+ ):
387+ """Test retrieving a task push notification config with a invalid task id."""
388+ mock_grpc_stub .GetTaskPushNotificationConfig .return_value = (
389+ a2a_pb2 .CreateTaskPushNotificationConfigRequest (
390+ parent = 'invalid-path-to-tasks/task-1' ,
391+ config_id = 'config-1' ,
392+ config = proto_utils .ToProto .task_push_notification_config (
393+ sample_task_push_notification_config
394+ ),
395+ )
396+ )
397+ params = TaskIdParams (id = sample_task_push_notification_config .taskId )
398+
399+ with pytest .raises (ServerError ) as exc_info :
400+ await grpc_client .get_task_callback (params )
401+ assert 'No task for' in exc_info .value .error .message
0 commit comments