-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_chat.py
More file actions
44 lines (28 loc) · 1.09 KB
/
test_chat.py
File metadata and controls
44 lines (28 loc) · 1.09 KB
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
44
from unittest.mock import AsyncMock, patch
import pytest
from socketio_app import ChatNamespace
@pytest.fixture
def chat_namespace():
return ChatNamespace("/chat")
async def test_on_connect(chat_namespace):
sid = "test_session_id"
environ = {}
# Test that connect doesn't raise any exceptions
chat_namespace.on_connect(sid, environ)
async def test_on_disconnect(chat_namespace):
sid = "test_session_id"
reason = "test_reason"
# Test that disconnect doesn't raise any exceptions
chat_namespace.on_disconnect(sid, reason)
async def test_on_echo_message(chat_namespace):
sid = "test_session_id"
test_data = {"message": "Hello, World!"}
# Mock the emit method
chat_namespace.emit = AsyncMock()
# Mock the logging
with patch("logging.info") as mock_log:
await chat_namespace.on_echo_message(sid, test_data)
# Verify logging was called
mock_log.assert_called_once_with("received message")
# Verify emit was called with correct arguments
chat_namespace.emit.assert_called_once_with("echo_response", test_data)