99 AgentCapabilities ,
1010 AgentCard ,
1111 Artifact ,
12+ GetTaskPushNotificationConfigParams ,
1213 Message ,
1314 MessageSendParams ,
1415 Part ,
2930from a2a .utils .errors import ServerError
3031
3132
32- # Fixtures
3333@pytest .fixture
3434def mock_grpc_stub () -> AsyncMock :
3535 """Provides a mock gRPC stub with methods mocked."""
@@ -105,7 +105,7 @@ def sample_message() -> Message:
105105def sample_artifact () -> Artifact :
106106 """Provides a sample Artifact object."""
107107 return Artifact (
108- artifactId = 'artifact-1' ,
108+ artifact_id = 'artifact-1' ,
109109 name = 'example.txt' ,
110110 description = 'An example artifact' ,
111111 parts = [Part (root = TextPart (text = 'Hi there' ))],
@@ -118,8 +118,8 @@ def sample_artifact() -> Artifact:
118118def sample_task_status_update_event () -> TaskStatusUpdateEvent :
119119 """Provides a sample TaskStatusUpdateEvent."""
120120 return TaskStatusUpdateEvent (
121- taskId = 'task-1' ,
122- contextId = 'ctx-1' ,
121+ task_id = 'task-1' ,
122+ context_id = 'ctx-1' ,
123123 status = TaskStatus (state = TaskState .working ),
124124 final = False ,
125125 metadata = {},
@@ -132,8 +132,8 @@ def sample_task_artifact_update_event(
132132) -> TaskArtifactUpdateEvent :
133133 """Provides a sample TaskArtifactUpdateEvent."""
134134 return TaskArtifactUpdateEvent (
135- taskId = 'task-1' ,
136- contextId = 'ctx-1' ,
135+ task_id = 'task-1' ,
136+ context_id = 'ctx-1' ,
137137 artifact = sample_artifact ,
138138 append = True ,
139139 last_chunk = True ,
@@ -168,8 +168,8 @@ def sample_task_push_notification_config(
168168) -> TaskPushNotificationConfig :
169169 """Provides a sample TaskPushNotificationConfig object."""
170170 return TaskPushNotificationConfig (
171- taskId = 'task-1' ,
172- pushNotificationConfig = sample_push_notification_config ,
171+ task_id = 'task-1' ,
172+ push_notification_config = sample_push_notification_config ,
173173 )
174174
175175
@@ -194,7 +194,7 @@ async def test_send_message_task_response(
194194
195195@pytest .mark .asyncio
196196async def test_send_message_message_response (
197- grpc_client : A2AGrpcClient ,
197+ grpc_transport : GrpcTransport ,
198198 mock_grpc_stub : AsyncMock ,
199199 sample_message_send_params : MessageSendParams ,
200200 sample_message : Message ,
@@ -204,16 +204,16 @@ async def test_send_message_message_response(
204204 msg = proto_utils .ToProto .message (sample_message )
205205 )
206206
207- response = await grpc_client .send_message (sample_message_send_params )
207+ response = await grpc_transport .send_message (sample_message_send_params )
208208
209209 mock_grpc_stub .SendMessage .assert_awaited_once ()
210210 assert isinstance (response , Message )
211- assert response .messageId == sample_message .messageId
211+ assert response .message_id == sample_message .message_id
212212
213213
214214@pytest .mark .asyncio
215- async def test_send_message_streaming (
216- grpc_client : A2AGrpcClient ,
215+ async def test_send_message_streaming ( # noqa: PLR0913
216+ grpc_transport : GrpcTransport ,
217217 mock_grpc_stub : AsyncMock ,
218218 sample_message_send_params : MessageSendParams ,
219219 sample_message : Message ,
@@ -246,20 +246,20 @@ async def test_send_message_streaming(
246246
247247 responses = [
248248 response
249- async for response in grpc_client .send_message_streaming (
249+ async for response in grpc_transport .send_message_streaming (
250250 sample_message_send_params
251251 )
252252 ]
253253
254254 mock_grpc_stub .SendStreamingMessage .assert_called_once ()
255255 assert isinstance (responses [0 ], Message )
256- assert responses [0 ].messageId == sample_message .messageId
256+ assert responses [0 ].message_id == sample_message .message_id
257257 assert isinstance (responses [1 ], Task )
258258 assert responses [1 ].id == sample_task .id
259259 assert isinstance (responses [2 ], TaskStatusUpdateEvent )
260- assert responses [2 ].taskId == sample_task_status_update_event .taskId
260+ assert responses [2 ].task_id == sample_task_status_update_event .task_id
261261 assert isinstance (responses [3 ], TaskArtifactUpdateEvent )
262- assert responses [3 ].taskId == sample_task_artifact_update_event .taskId
262+ assert responses [3 ].task_id == sample_task_artifact_update_event .task_id
263263
264264
265265@pytest .mark .asyncio
@@ -300,113 +300,118 @@ async def test_cancel_task(
300300
301301@pytest .mark .asyncio
302302async def test_set_task_callback_with_valid_task (
303- grpc_client : A2AGrpcClient ,
303+ grpc_transport : GrpcTransport ,
304304 mock_grpc_stub : AsyncMock ,
305305 sample_task_push_notification_config : TaskPushNotificationConfig ,
306306):
307307 """Test setting a task push notification config with a valid task id."""
308- task_id = 'task-1'
309- config_id = 'config-1'
310308 mock_grpc_stub .CreateTaskPushNotificationConfig .return_value = (
311- a2a_pb2 .CreateTaskPushNotificationConfigRequest (
312- parent = f'tasks/{ task_id } ' ,
313- config_id = config_id ,
314- config = proto_utils .ToProto .task_push_notification_config (
315- sample_task_push_notification_config
316- ),
309+ proto_utils .ToProto .task_push_notification_config (
310+ sample_task_push_notification_config
317311 )
318312 )
319313
320- response = await grpc_client .set_task_callback (
314+ response = await grpc_transport .set_task_callback (
321315 sample_task_push_notification_config
322316 )
323317
324318 mock_grpc_stub .CreateTaskPushNotificationConfig .assert_awaited_once_with (
325319 a2a_pb2 .CreateTaskPushNotificationConfigRequest (
320+ parent = f'tasks/{ sample_task_push_notification_config .task_id } ' ,
321+ config_id = sample_task_push_notification_config .push_notification_config .id ,
326322 config = proto_utils .ToProto .task_push_notification_config (
327323 sample_task_push_notification_config
328324 ),
329325 )
330326 )
331- assert response .taskId == task_id
327+ assert response .task_id == sample_task_push_notification_config . task_id
332328
333329
334330@pytest .mark .asyncio
335331async def test_set_task_callback_with_invalid_task (
336- grpc_client : A2AGrpcClient ,
332+ grpc_transport : GrpcTransport ,
337333 mock_grpc_stub : AsyncMock ,
338334 sample_task_push_notification_config : TaskPushNotificationConfig ,
339335):
340336 """Test setting a task push notification config with a invalid task id."""
341- task_id = 'task-1'
342- config_id = 'config-1'
343- mock_grpc_stub . CreateTaskPushNotificationConfig . return_value = (
344- a2a_pb2 . CreateTaskPushNotificationConfigRequest (
345- parent = f'invalid-path-to-tasks/ { task_id } ' ,
346- config_id = config_id ,
347- config = proto_utils . ToProto . task_push_notification_config (
348- sample_task_push_notification_config
349- ) ,
350- )
337+ mock_grpc_stub . CreateTaskPushNotificationConfig . return_value = a2a_pb2 . TaskPushNotificationConfig (
338+ name = (
339+ f'invalid-path-to-tasks/ { sample_task_push_notification_config . task_id } /'
340+ f'pushNotificationConfigs/ { sample_task_push_notification_config . push_notification_config . id } '
341+ ) ,
342+ push_notification_config = a2a_pb2 . PushNotificationConfig (
343+ id = sample_task_push_notification_config . push_notification_config . id ,
344+ url = sample_task_push_notification_config . push_notification_config . url ,
345+ token = sample_task_push_notification_config . push_notification_config . token ,
346+ ),
351347 )
352348
353349 with pytest .raises (ServerError ) as exc_info :
354- await grpc_client .set_task_callback (
350+ await grpc_transport .set_task_callback (
355351 sample_task_push_notification_config
356352 )
357- assert 'No task for' in exc_info .value .error .message
353+ assert (
354+ 'Bad TaskPushNotificationConfig resource name'
355+ in exc_info .value .error .message
356+ )
358357
359358
360359@pytest .mark .asyncio
361360async def test_get_task_callback_with_valid_task (
362- grpc_client : A2AGrpcClient ,
361+ grpc_transport : GrpcTransport ,
363362 mock_grpc_stub : AsyncMock ,
364363 sample_task_push_notification_config : TaskPushNotificationConfig ,
365364):
366365 """Test retrieving a task push notification config with a valid task id."""
367- task_id = 'task-1'
368- config_id = 'config-1'
369366 mock_grpc_stub .GetTaskPushNotificationConfig .return_value = (
370- a2a_pb2 .CreateTaskPushNotificationConfigRequest (
371- parent = f'tasks/{ task_id } ' ,
372- config_id = config_id ,
373- config = proto_utils .ToProto .task_push_notification_config (
374- sample_task_push_notification_config
375- ),
367+ proto_utils .ToProto .task_push_notification_config (
368+ sample_task_push_notification_config
376369 )
377370 )
378- params = TaskIdParams (id = sample_task_push_notification_config .taskId )
371+ params = GetTaskPushNotificationConfigParams (
372+ id = sample_task_push_notification_config .task_id ,
373+ push_notification_config_id = sample_task_push_notification_config .push_notification_config .id ,
374+ )
379375
380- response = await grpc_client .get_task_callback (params )
376+ response = await grpc_transport .get_task_callback (params )
381377
382378 mock_grpc_stub .GetTaskPushNotificationConfig .assert_awaited_once_with (
383379 a2a_pb2 .GetTaskPushNotificationConfigRequest (
384- name = f'tasks/{ params .id } /pushNotification/undefined' ,
380+ name = (
381+ f'tasks/{ params .id } /'
382+ f'pushNotificationConfigs/{ params .push_notification_config_id } '
383+ ),
385384 )
386385 )
387- assert response .taskId == task_id
386+ assert response .task_id == sample_task_push_notification_config . task_id
388387
389388
390389@pytest .mark .asyncio
391390async def test_get_task_callback_with_invalid_task (
392- grpc_client : A2AGrpcClient ,
391+ grpc_transport : GrpcTransport ,
393392 mock_grpc_stub : AsyncMock ,
394393 sample_task_push_notification_config : TaskPushNotificationConfig ,
395394):
396395 """Test retrieving a task push notification config with a invalid task id."""
397- task_id = 'task-1'
398- config_id = 'config-1'
399- mock_grpc_stub .GetTaskPushNotificationConfig .return_value = (
400- a2a_pb2 .CreateTaskPushNotificationConfigRequest (
401- parent = f'invalid-path-to-tasks/{ task_id } ' ,
402- config_id = config_id ,
403- config = proto_utils .ToProto .task_push_notification_config (
404- sample_task_push_notification_config
405- ),
406- )
396+ mock_grpc_stub .GetTaskPushNotificationConfig .return_value = a2a_pb2 .TaskPushNotificationConfig (
397+ name = (
398+ f'invalid-path-to-tasks/{ sample_task_push_notification_config .task_id } /'
399+ f'pushNotificationConfigs/{ sample_task_push_notification_config .push_notification_config .id } '
400+ ),
401+ push_notification_config = a2a_pb2 .PushNotificationConfig (
402+ id = sample_task_push_notification_config .push_notification_config .id ,
403+ url = sample_task_push_notification_config .push_notification_config .url ,
404+ token = sample_task_push_notification_config .push_notification_config .token ,
405+ ),
406+ )
407+ params = GetTaskPushNotificationConfigParams (
408+ id = sample_task_push_notification_config .task_id ,
409+ push_notification_config_id = sample_task_push_notification_config .push_notification_config .id ,
407410 )
408- params = TaskIdParams (id = sample_task_push_notification_config .taskId )
409411
410412 with pytest .raises (ServerError ) as exc_info :
411- await grpc_client .get_task_callback (params )
412- assert 'No task for' in exc_info .value .error .message
413+ await grpc_transport .get_task_callback (params )
414+ assert (
415+ 'Bad TaskPushNotificationConfig resource name'
416+ in exc_info .value .error .message
417+ )
0 commit comments