23 lines
665 B
Python
23 lines
665 B
Python
import pytest
|
|
from chatapp.chat_server import ChatServer
|
|
from chatapp.models import UserConnection
|
|
import asyncio
|
|
|
|
@pytest.fixture
|
|
def chat_server():
|
|
"""Returns a ChatServer instance."""
|
|
return ChatServer()
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_add_user(chat_server: ChatServer):
|
|
"""Test adding a user to the chat server."""
|
|
username = "testuser"
|
|
message_queue = asyncio.Queue()
|
|
user_conn = UserConnection(username, message_queue)
|
|
|
|
chat_server.add_user(username, user_conn)
|
|
|
|
assert username in chat_server.users
|
|
assert chat_server.users[username] == user_conn
|
|
assert username in chat_server.channels['global'].members
|