fix: Lint fixes of last tests
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
"""Tests for socket service."""
|
||||
# ruff: noqa: ANN001, ANN201, ARG002, PLR2004, SLF001, E501, ANN202
|
||||
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
@@ -22,7 +23,7 @@ class TestSocketManager:
|
||||
socket_manager.sio = AsyncMock(spec=socketio.AsyncServer)
|
||||
return socket_manager.sio
|
||||
|
||||
def test_init_creates_socket_server(self):
|
||||
def test_init_creates_socket_server(self) -> None:
|
||||
"""Test that socket manager initializes with proper configuration."""
|
||||
manager = SocketManager()
|
||||
|
||||
@@ -33,7 +34,7 @@ class TestSocketManager:
|
||||
assert len(manager.socket_users) == 0
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_to_user_success(self, socket_manager, mock_sio):
|
||||
async def test_send_to_user_success(self, socket_manager, mock_sio) -> None:
|
||||
"""Test sending message to connected user."""
|
||||
user_id = "123"
|
||||
room_id = "user_123"
|
||||
@@ -48,7 +49,7 @@ class TestSocketManager:
|
||||
mock_sio.emit.assert_called_once_with(event, data, room=room_id)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_to_user_not_connected(self, socket_manager, mock_sio):
|
||||
async def test_send_to_user_not_connected(self, socket_manager, mock_sio) -> None:
|
||||
"""Test sending message to user who is not connected."""
|
||||
user_id = "999"
|
||||
event = "test_event"
|
||||
@@ -60,7 +61,7 @@ class TestSocketManager:
|
||||
mock_sio.emit.assert_not_called()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_broadcast_to_all(self, socket_manager, mock_sio):
|
||||
async def test_broadcast_to_all(self, socket_manager, mock_sio) -> None:
|
||||
"""Test broadcasting message to all users."""
|
||||
event = "broadcast_event"
|
||||
data = {"message": "announcement"}
|
||||
@@ -69,7 +70,7 @@ class TestSocketManager:
|
||||
|
||||
mock_sio.emit.assert_called_once_with(event, data)
|
||||
|
||||
def test_get_connected_users(self, socket_manager):
|
||||
def test_get_connected_users(self, socket_manager) -> None:
|
||||
"""Test getting list of connected users."""
|
||||
# Add some users
|
||||
socket_manager.user_rooms["1"] = "user_1"
|
||||
@@ -83,7 +84,7 @@ class TestSocketManager:
|
||||
assert "2" in connected_users
|
||||
assert "3" in connected_users
|
||||
|
||||
def test_get_room_info(self, socket_manager):
|
||||
def test_get_room_info(self, socket_manager) -> None:
|
||||
"""Test getting room information."""
|
||||
# Add some users
|
||||
socket_manager.user_rooms["1"] = "user_1"
|
||||
@@ -99,7 +100,7 @@ class TestSocketManager:
|
||||
@patch("app.services.socket.JWTUtils.decode_access_token")
|
||||
async def test_connect_handler_success(
|
||||
self, mock_decode, mock_extract_token, socket_manager, mock_sio,
|
||||
):
|
||||
) -> None:
|
||||
"""Test successful connection with valid token."""
|
||||
# Setup mocks
|
||||
mock_extract_token.return_value = "valid_token"
|
||||
@@ -110,7 +111,6 @@ class TestSocketManager:
|
||||
|
||||
# Access the connect handler directly
|
||||
handlers = {}
|
||||
original_event = socket_manager.sio.event
|
||||
|
||||
def mock_event(func):
|
||||
handlers[func.__name__] = func
|
||||
@@ -134,7 +134,7 @@ class TestSocketManager:
|
||||
@patch("app.services.socket.extract_access_token_from_cookies")
|
||||
async def test_connect_handler_no_token(
|
||||
self, mock_extract_token, socket_manager, mock_sio,
|
||||
):
|
||||
) -> None:
|
||||
"""Test connection with no access token."""
|
||||
# Setup mocks
|
||||
mock_extract_token.return_value = None
|
||||
@@ -144,7 +144,6 @@ class TestSocketManager:
|
||||
|
||||
# Access the connect handler directly
|
||||
handlers = {}
|
||||
original_event = socket_manager.sio.event
|
||||
|
||||
def mock_event(func):
|
||||
handlers[func.__name__] = func
|
||||
@@ -168,7 +167,7 @@ class TestSocketManager:
|
||||
@patch("app.services.socket.JWTUtils.decode_access_token")
|
||||
async def test_connect_handler_invalid_token(
|
||||
self, mock_decode, mock_extract_token, socket_manager, mock_sio,
|
||||
):
|
||||
) -> None:
|
||||
"""Test connection with invalid token."""
|
||||
# Setup mocks
|
||||
mock_extract_token.return_value = "invalid_token"
|
||||
@@ -179,7 +178,6 @@ class TestSocketManager:
|
||||
|
||||
# Access the connect handler directly
|
||||
handlers = {}
|
||||
original_event = socket_manager.sio.event
|
||||
|
||||
def mock_event(func):
|
||||
handlers[func.__name__] = func
|
||||
@@ -203,7 +201,7 @@ class TestSocketManager:
|
||||
@patch("app.services.socket.JWTUtils.decode_access_token")
|
||||
async def test_connect_handler_missing_user_id(
|
||||
self, mock_decode, mock_extract_token, socket_manager, mock_sio,
|
||||
):
|
||||
) -> None:
|
||||
"""Test connection with token missing user ID."""
|
||||
# Setup mocks
|
||||
mock_extract_token.return_value = "token_without_user_id"
|
||||
@@ -214,7 +212,6 @@ class TestSocketManager:
|
||||
|
||||
# Access the connect handler directly
|
||||
handlers = {}
|
||||
original_event = socket_manager.sio.event
|
||||
|
||||
def mock_event(func):
|
||||
handlers[func.__name__] = func
|
||||
@@ -234,7 +231,7 @@ class TestSocketManager:
|
||||
assert len(socket_manager.user_rooms) == 0
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_disconnect_handler(self, socket_manager, mock_sio):
|
||||
async def test_disconnect_handler(self, socket_manager, mock_sio) -> None:
|
||||
"""Test disconnect handler."""
|
||||
# Setup initial state
|
||||
socket_manager.socket_users["test_sid"] = "123"
|
||||
@@ -242,7 +239,6 @@ class TestSocketManager:
|
||||
|
||||
# Access the disconnect handler directly
|
||||
handlers = {}
|
||||
original_event = socket_manager.sio.event
|
||||
|
||||
def mock_event(func):
|
||||
handlers[func.__name__] = func
|
||||
@@ -259,11 +255,10 @@ class TestSocketManager:
|
||||
assert "123" not in socket_manager.user_rooms
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_disconnect_handler_unknown_socket(self, socket_manager, mock_sio):
|
||||
async def test_disconnect_handler_unknown_socket(self, socket_manager, mock_sio) -> None:
|
||||
"""Test disconnect handler with unknown socket."""
|
||||
# Access the disconnect handler directly
|
||||
handlers = {}
|
||||
original_event = socket_manager.sio.event
|
||||
|
||||
def mock_event(func):
|
||||
handlers[func.__name__] = func
|
||||
|
||||
Reference in New Issue
Block a user