-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathtest_socket_events.py
43 lines (31 loc) · 1.51 KB
/
test_socket_events.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from unittest.mock import AsyncMock, patch
import pytest
from openhands.server.listen_socket import oh_action, oh_user_action
@pytest.mark.asyncio
async def test_oh_user_action():
"""Test that oh_user_action correctly forwards data to the conversation manager."""
connection_id = 'test_connection_id'
test_data = {'action': 'test_action', 'data': 'test_data'}
# Mock the conversation_manager
with patch('openhands.server.listen_socket.conversation_manager') as mock_manager:
mock_manager.send_to_event_stream = AsyncMock()
# Call the function
await oh_user_action(connection_id, test_data)
# Verify the conversation manager was called with the correct arguments
mock_manager.send_to_event_stream.assert_called_once_with(
connection_id, test_data
)
@pytest.mark.asyncio
async def test_oh_action():
"""Test that oh_action (legacy handler) correctly forwards data to the conversation manager."""
connection_id = 'test_connection_id'
test_data = {'action': 'test_action', 'data': 'test_data'}
# Mock the conversation_manager
with patch('openhands.server.listen_socket.conversation_manager') as mock_manager:
mock_manager.send_to_event_stream = AsyncMock()
# Call the function
await oh_action(connection_id, test_data)
# Verify the conversation manager was called with the correct arguments
mock_manager.send_to_event_stream.assert_called_once_with(
connection_id, test_data
)