Add comprehensive tests for playlist service and refactor socket service tests
- Introduced a new test suite for the PlaylistService covering various functionalities including creation, retrieval, updating, and deletion of playlists. - Added tests for handling sounds within playlists, ensuring correct behavior when adding/removing sounds and managing current playlists. - Refactored socket service tests for improved readability by adjusting function signatures. - Cleaned up unnecessary whitespace in sound normalizer and sound scanner tests for consistency. - Enhanced audio utility tests to ensure accurate hash and size calculations, including edge cases for nonexistent files. - Removed redundant blank lines in cookie utility tests for cleaner code.
This commit is contained in:
@@ -22,7 +22,12 @@ class TestSocketEndpoints:
|
||||
"""Test socket API endpoints."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_socket_status_authenticated(self, authenticated_client: AsyncClient, authenticated_user: User, mock_socket_manager):
|
||||
async def test_get_socket_status_authenticated(
|
||||
self,
|
||||
authenticated_client: AsyncClient,
|
||||
authenticated_user: User,
|
||||
mock_socket_manager,
|
||||
):
|
||||
"""Test getting socket status for authenticated user."""
|
||||
response = await authenticated_client.get("/api/v1/socket/status")
|
||||
|
||||
@@ -43,7 +48,12 @@ class TestSocketEndpoints:
|
||||
assert response.status_code == 401
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_message_to_user_success(self, authenticated_client: AsyncClient, authenticated_user: User, mock_socket_manager):
|
||||
async def test_send_message_to_user_success(
|
||||
self,
|
||||
authenticated_client: AsyncClient,
|
||||
authenticated_user: User,
|
||||
mock_socket_manager,
|
||||
):
|
||||
"""Test sending message to specific user successfully."""
|
||||
target_user_id = 2
|
||||
message = "Hello there!"
|
||||
@@ -72,7 +82,12 @@ class TestSocketEndpoints:
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_message_to_user_not_connected(self, authenticated_client: AsyncClient, authenticated_user: User, mock_socket_manager):
|
||||
async def test_send_message_to_user_not_connected(
|
||||
self,
|
||||
authenticated_client: AsyncClient,
|
||||
authenticated_user: User,
|
||||
mock_socket_manager,
|
||||
):
|
||||
"""Test sending message to user who is not connected."""
|
||||
target_user_id = 999
|
||||
message = "Hello there!"
|
||||
@@ -102,7 +117,12 @@ class TestSocketEndpoints:
|
||||
assert response.status_code == 401
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_broadcast_message_success(self, authenticated_client: AsyncClient, authenticated_user: User, mock_socket_manager):
|
||||
async def test_broadcast_message_success(
|
||||
self,
|
||||
authenticated_client: AsyncClient,
|
||||
authenticated_user: User,
|
||||
mock_socket_manager,
|
||||
):
|
||||
"""Test broadcasting message to all users successfully."""
|
||||
message = "Important announcement!"
|
||||
|
||||
@@ -137,7 +157,9 @@ class TestSocketEndpoints:
|
||||
assert response.status_code == 401
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_message_missing_parameters(self, authenticated_client: AsyncClient, authenticated_user: User):
|
||||
async def test_send_message_missing_parameters(
|
||||
self, authenticated_client: AsyncClient, authenticated_user: User
|
||||
):
|
||||
"""Test sending message with missing parameters."""
|
||||
# Missing target_user_id
|
||||
response = await authenticated_client.post(
|
||||
@@ -154,13 +176,17 @@ class TestSocketEndpoints:
|
||||
assert response.status_code == 422
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_broadcast_message_missing_parameters(self, authenticated_client: AsyncClient, authenticated_user: User):
|
||||
async def test_broadcast_message_missing_parameters(
|
||||
self, authenticated_client: AsyncClient, authenticated_user: User
|
||||
):
|
||||
"""Test broadcasting message with missing parameters."""
|
||||
response = await authenticated_client.post("/api/v1/socket/broadcast")
|
||||
assert response.status_code == 422
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_message_invalid_user_id(self, authenticated_client: AsyncClient, authenticated_user: User):
|
||||
async def test_send_message_invalid_user_id(
|
||||
self, authenticated_client: AsyncClient, authenticated_user: User
|
||||
):
|
||||
"""Test sending message with invalid user ID."""
|
||||
response = await authenticated_client.post(
|
||||
"/api/v1/socket/send-message",
|
||||
@@ -169,10 +195,19 @@ class TestSocketEndpoints:
|
||||
assert response.status_code == 422
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_socket_status_shows_user_connection(self, authenticated_client: AsyncClient, authenticated_user: User, mock_socket_manager):
|
||||
async def test_socket_status_shows_user_connection(
|
||||
self,
|
||||
authenticated_client: AsyncClient,
|
||||
authenticated_user: User,
|
||||
mock_socket_manager,
|
||||
):
|
||||
"""Test that socket status correctly shows if user is connected."""
|
||||
# Test when user is connected
|
||||
mock_socket_manager.get_connected_users.return_value = [str(authenticated_user.id), "2", "3"]
|
||||
mock_socket_manager.get_connected_users.return_value = [
|
||||
str(authenticated_user.id),
|
||||
"2",
|
||||
"3",
|
||||
]
|
||||
|
||||
response = await authenticated_client.get("/api/v1/socket/status")
|
||||
data = response.json()
|
||||
|
||||
Reference in New Issue
Block a user