@@ -139,6 +139,16 @@ async def test_build_call_context(self, rest_dispatcher_instance):
139139
140140@pytest .mark .asyncio
141141class TestRestDispatcherEndpoints :
142+ async def test_on_message_send_throws_error_for_unsupported_version (
143+ self , rest_dispatcher_instance , mock_handler
144+ ):
145+ # 0.3 is currently not supported for direct message sending on RestDispatcher
146+ req = make_mock_request (method = 'POST' , headers = {'a2a-version' : '0.3.0' })
147+ response = await rest_dispatcher_instance .on_message_send (req )
148+
149+ # VersionNotSupportedError maps to 400 Bad Request
150+ assert response .status_code == 400
151+
142152 async def test_on_message_send_returns_message (
143153 self , rest_dispatcher_instance , mock_handler
144154 ):
@@ -286,3 +296,36 @@ async def test_on_subscribe_to_task_unsupported(
286296
287297 response = await dispatcher .on_subscribe_to_task (req )
288298 assert response .status_code == 400
299+
300+ async def test_on_message_send_stream_success (
301+ self , rest_dispatcher_instance
302+ ):
303+ req = make_mock_request (method = 'POST' )
304+ response = await rest_dispatcher_instance .on_message_send_stream (req )
305+
306+ assert response .status_code == 200
307+
308+ chunks = []
309+ async for chunk in response .body_iterator :
310+ chunks .append (chunk )
311+
312+ assert len (chunks ) == 2
313+ # sse-starlette yields strings or bytes formatted as Server-Sent Events
314+ assert 'chunk1' in str (chunks [0 ])
315+ assert 'chunk2' in str (chunks [1 ])
316+
317+ async def test_on_subscribe_to_task_success (
318+ self , rest_dispatcher_instance
319+ ):
320+ req = make_mock_request (method = 'GET' , path_params = {'id' : 'test_task' })
321+ response = await rest_dispatcher_instance .on_subscribe_to_task (req )
322+
323+ assert response .status_code == 200
324+
325+ chunks = []
326+ async for chunk in response .body_iterator :
327+ chunks .append (chunk )
328+
329+ assert len (chunks ) == 2
330+ assert 'chunk1' in str (chunks [0 ])
331+ assert 'chunk2' in str (chunks [1 ])
0 commit comments