44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
import pytest
|
|
import asyncio
|
|
from unittest.mock import AsyncMock, patch
|
|
from app.services.websocket_manager import WebSocketManager
|
|
|
|
|
|
class TestWebSocketManager:
|
|
@pytest.fixture
|
|
def ws_manager(self):
|
|
return WebSocketManager()
|
|
|
|
@pytest.fixture
|
|
def mock_websocket(self):
|
|
ws = AsyncMock()
|
|
ws.send_json = AsyncMock()
|
|
return ws
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_connect(self, ws_manager, mock_websocket):
|
|
await ws_manager.connect(mock_websocket)
|
|
|
|
mock_websocket.accept.assert_called_once()
|
|
assert len(ws_manager._clients) == 1
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.skip(reason="Requires async polling environment")
|
|
async def test_start_poll_task(self, ws_manager):
|
|
mock_client = AsyncMock()
|
|
with patch("app.services.websocket_manager.opencode_client", mock_client):
|
|
await ws_manager.start_poll_task("task-1", "session-1")
|
|
|
|
assert "task-1" in ws_manager._poll_tasks
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.skip(reason="Requires async polling environment")
|
|
async def test_stop_poll_task(self, ws_manager):
|
|
mock_client = AsyncMock()
|
|
with patch("app.services.websocket_manager.opencode_client", mock_client):
|
|
await ws_manager.start_poll_task("task-1", "session-1")
|
|
|
|
await ws_manager.stop_poll_task("task-1")
|
|
|
|
assert "task-1" not in ws_manager._poll_tasks
|