Updated streaming tests

This commit is contained in:
Cyber MacGeddon 2026-01-06 20:00:21 +00:00
parent b1a4ae91d2
commit 35ee0141f7

View file

@ -129,7 +129,15 @@ async def test_handle_normal_flow():
mock_tg = AsyncMock() mock_tg = AsyncMock()
mock_tg.__aenter__ = AsyncMock(return_value=mock_tg) mock_tg.__aenter__ = AsyncMock(return_value=mock_tg)
mock_tg.__aexit__ = AsyncMock(return_value=None) mock_tg.__aexit__ = AsyncMock(return_value=None)
mock_tg.create_task = MagicMock(return_value=AsyncMock())
# Create proper mock tasks that look like asyncio.Task objects
def create_task_mock(coro):
task = AsyncMock()
task.done = MagicMock(return_value=True)
task.cancelled = MagicMock(return_value=False)
return task
mock_tg.create_task = MagicMock(side_effect=create_task_mock)
mock_task_group.return_value = mock_tg mock_task_group.return_value = mock_tg
result = await socket_endpoint.handle(request) result = await socket_endpoint.handle(request)
@ -176,7 +184,15 @@ async def test_handle_exception_group_cleanup():
mock_tg = AsyncMock() mock_tg = AsyncMock()
mock_tg.__aenter__ = AsyncMock(return_value=mock_tg) mock_tg.__aenter__ = AsyncMock(return_value=mock_tg)
mock_tg.__aexit__ = AsyncMock(side_effect=exception_group) mock_tg.__aexit__ = AsyncMock(side_effect=exception_group)
mock_tg.create_task = MagicMock(side_effect=TestException("test"))
# Create proper mock tasks that look like asyncio.Task objects
def create_task_mock(coro):
task = AsyncMock()
task.done = MagicMock(return_value=True)
task.cancelled = MagicMock(return_value=False)
return task
mock_tg.create_task = MagicMock(side_effect=create_task_mock)
mock_task_group.return_value = mock_tg mock_task_group.return_value = mock_tg
with patch('trustgraph.gateway.endpoint.socket.asyncio.wait_for') as mock_wait_for: with patch('trustgraph.gateway.endpoint.socket.asyncio.wait_for') as mock_wait_for:
@ -227,7 +243,15 @@ async def test_handle_dispatcher_cleanup_timeout():
mock_tg = AsyncMock() mock_tg = AsyncMock()
mock_tg.__aenter__ = AsyncMock(return_value=mock_tg) mock_tg.__aenter__ = AsyncMock(return_value=mock_tg)
mock_tg.__aexit__ = AsyncMock(side_effect=exception_group) mock_tg.__aexit__ = AsyncMock(side_effect=exception_group)
mock_tg.create_task = MagicMock(side_effect=Exception("test"))
# Create proper mock tasks that look like asyncio.Task objects
def create_task_mock(coro):
task = AsyncMock()
task.done = MagicMock(return_value=True)
task.cancelled = MagicMock(return_value=False)
return task
mock_tg.create_task = MagicMock(side_effect=create_task_mock)
mock_task_group.return_value = mock_tg mock_task_group.return_value = mock_tg
# Mock asyncio.wait_for to raise TimeoutError # Mock asyncio.wait_for to raise TimeoutError
@ -314,7 +338,15 @@ async def test_handle_websocket_already_closed():
mock_tg = AsyncMock() mock_tg = AsyncMock()
mock_tg.__aenter__ = AsyncMock(return_value=mock_tg) mock_tg.__aenter__ = AsyncMock(return_value=mock_tg)
mock_tg.__aexit__ = AsyncMock(return_value=None) mock_tg.__aexit__ = AsyncMock(return_value=None)
mock_tg.create_task = MagicMock(return_value=AsyncMock())
# Create proper mock tasks that look like asyncio.Task objects
def create_task_mock(coro):
task = AsyncMock()
task.done = MagicMock(return_value=True)
task.cancelled = MagicMock(return_value=False)
return task
mock_tg.create_task = MagicMock(side_effect=create_task_mock)
mock_task_group.return_value = mock_tg mock_task_group.return_value = mock_tg
result = await socket_endpoint.handle(request) result = await socket_endpoint.handle(request)