11"""Tests for the JSON-RPC client transport."""
22
33import json
4- from google .protobuf import json_format
5- from unittest import mock
4+
65from unittest .mock import AsyncMock , MagicMock , patch
76from uuid import uuid4
87
98import httpx
109import pytest
11- import respx
10+
11+ from google .protobuf import json_format
1212from httpx_sse import EventSource , SSEError
1313
1414from a2a .client .errors import A2AClientError
15- from a2a .utils .errors import InvalidRequestError
1615from a2a .client .transports .jsonrpc import JsonRpcTransport
1716from a2a .types .a2a_pb2 import (
1817 AgentCapabilities ,
19- AgentInterface ,
2018 AgentCard ,
19+ AgentInterface ,
2120 CancelTaskRequest ,
22- CreateTaskPushNotificationConfigRequest ,
2321 DeleteTaskPushNotificationConfigRequest ,
2422 GetTaskPushNotificationConfigRequest ,
25- ListTaskPushNotificationConfigsRequest ,
26- ListTaskPushNotificationConfigsResponse ,
2723 GetTaskRequest ,
24+ ListTaskPushNotificationConfigsRequest ,
2825 Message ,
2926 Part ,
3027 SendMessageConfiguration ,
3330 Task ,
3431 TaskPushNotificationConfig ,
3532 TaskState ,
36- TaskStatus ,
3733)
34+ from a2a .utils .errors import JSON_RPC_ERROR_CODE_MAP
3835
3936
4037@pytest .fixture
@@ -174,16 +171,19 @@ async def test_send_message_success(self, transport, mock_httpx_client):
174171 payload = call_args [1 ]['json' ]
175172 assert payload ['method' ] == 'SendMessage'
176173
174+ @pytest .mark .parametrize (
175+ 'error_cls, error_code' , JSON_RPC_ERROR_CODE_MAP .items ()
176+ )
177177 @pytest .mark .asyncio
178178 async def test_send_message_jsonrpc_error (
179- self , transport , mock_httpx_client
179+ self , transport , mock_httpx_client , error_cls , error_code
180180 ):
181- """Test handling of JSON-RPC error response."""
181+ """Test handling of JSON-RPC mapped error response."""
182182 mock_response = MagicMock ()
183183 mock_response .json .return_value = {
184184 'jsonrpc' : '2.0' ,
185185 'id' : '1' ,
186- 'error' : {'code' : - 32600 , 'message' : 'Invalid Request ' },
186+ 'error' : {'code' : error_code , 'message' : 'Mapped Error ' },
187187 'result' : None ,
188188 }
189189 mock_response .raise_for_status = MagicMock ()
@@ -192,7 +192,7 @@ async def test_send_message_jsonrpc_error(
192192 request = create_send_message_request ()
193193
194194 # The transport raises the specific A2AError mapped from code
195- with pytest .raises (InvalidRequestError ):
195+ with pytest .raises (error_cls ):
196196 await transport .send_message (request )
197197
198198 @pytest .mark .asyncio
0 commit comments