Refactor test cases for improved readability and consistency
- Adjusted function signatures in various test files to enhance clarity by aligning parameters. - Updated patching syntax for better readability across test cases. - Improved formatting and spacing in test assertions and mock setups. - Ensured consistent use of async/await patterns in async test functions. - Enhanced comments for better understanding of test intentions.
This commit is contained in:
@@ -98,7 +98,11 @@ class TestSocketManager:
|
||||
@patch("app.services.socket.extract_access_token_from_cookies")
|
||||
@patch("app.services.socket.JWTUtils.decode_access_token")
|
||||
async def test_connect_handler_success(
|
||||
self, mock_decode, mock_extract_token, socket_manager, mock_sio,
|
||||
self,
|
||||
mock_decode,
|
||||
mock_extract_token,
|
||||
socket_manager,
|
||||
mock_sio,
|
||||
) -> None:
|
||||
"""Test successful connection with valid token."""
|
||||
# Setup mocks
|
||||
@@ -132,7 +136,10 @@ class TestSocketManager:
|
||||
@pytest.mark.asyncio
|
||||
@patch("app.services.socket.extract_access_token_from_cookies")
|
||||
async def test_connect_handler_no_token(
|
||||
self, mock_extract_token, socket_manager, mock_sio,
|
||||
self,
|
||||
mock_extract_token,
|
||||
socket_manager,
|
||||
mock_sio,
|
||||
) -> None:
|
||||
"""Test connection with no access token."""
|
||||
# Setup mocks
|
||||
@@ -165,7 +172,11 @@ class TestSocketManager:
|
||||
@patch("app.services.socket.extract_access_token_from_cookies")
|
||||
@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,
|
||||
self,
|
||||
mock_decode,
|
||||
mock_extract_token,
|
||||
socket_manager,
|
||||
mock_sio,
|
||||
) -> None:
|
||||
"""Test connection with invalid token."""
|
||||
# Setup mocks
|
||||
@@ -199,7 +210,11 @@ class TestSocketManager:
|
||||
@patch("app.services.socket.extract_access_token_from_cookies")
|
||||
@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,
|
||||
self,
|
||||
mock_decode,
|
||||
mock_extract_token,
|
||||
socket_manager,
|
||||
mock_sio,
|
||||
) -> None:
|
||||
"""Test connection with token missing user ID."""
|
||||
# Setup mocks
|
||||
@@ -254,7 +269,9 @@ 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) -> None:
|
||||
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 = {}
|
||||
|
||||
Reference in New Issue
Block a user