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:
@@ -36,7 +36,9 @@ class TestApiTokenDependencies:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_current_user_api_token_success(
|
||||
self, mock_auth_service, test_user,
|
||||
self,
|
||||
mock_auth_service,
|
||||
test_user,
|
||||
):
|
||||
"""Test successful API token authentication."""
|
||||
mock_auth_service.get_user_by_api_token.return_value = test_user
|
||||
@@ -46,7 +48,9 @@ class TestApiTokenDependencies:
|
||||
result = await get_current_user_api_token(mock_auth_service, api_token_header)
|
||||
|
||||
assert result == test_user
|
||||
mock_auth_service.get_user_by_api_token.assert_called_once_with("test_api_token_123")
|
||||
mock_auth_service.get_user_by_api_token.assert_called_once_with(
|
||||
"test_api_token_123"
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_current_user_api_token_no_header(self, mock_auth_service):
|
||||
@@ -94,7 +98,9 @@ class TestApiTokenDependencies:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_current_user_api_token_expired_token(
|
||||
self, mock_auth_service, test_user,
|
||||
self,
|
||||
mock_auth_service,
|
||||
test_user,
|
||||
):
|
||||
"""Test API token authentication with expired token."""
|
||||
# Set expired token
|
||||
@@ -111,7 +117,9 @@ class TestApiTokenDependencies:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_current_user_api_token_inactive_user(
|
||||
self, mock_auth_service, test_user,
|
||||
self,
|
||||
mock_auth_service,
|
||||
test_user,
|
||||
):
|
||||
"""Test API token authentication with inactive user."""
|
||||
test_user.is_active = False
|
||||
@@ -126,9 +134,13 @@ class TestApiTokenDependencies:
|
||||
assert "Account is deactivated" in exc_info.value.detail
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_current_user_api_token_service_exception(self, mock_auth_service):
|
||||
async def test_get_current_user_api_token_service_exception(
|
||||
self, mock_auth_service
|
||||
):
|
||||
"""Test API token authentication with service exception."""
|
||||
mock_auth_service.get_user_by_api_token.side_effect = Exception("Database error")
|
||||
mock_auth_service.get_user_by_api_token.side_effect = Exception(
|
||||
"Database error"
|
||||
)
|
||||
|
||||
api_token_header = "test_token"
|
||||
|
||||
@@ -140,7 +152,9 @@ class TestApiTokenDependencies:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_current_user_flexible_uses_api_token(
|
||||
self, mock_auth_service, test_user,
|
||||
self,
|
||||
mock_auth_service,
|
||||
test_user,
|
||||
):
|
||||
"""Test flexible authentication uses API token when available."""
|
||||
mock_auth_service.get_user_by_api_token.return_value = test_user
|
||||
@@ -149,11 +163,15 @@ class TestApiTokenDependencies:
|
||||
access_token = "jwt_token"
|
||||
|
||||
result = await get_current_user_flexible(
|
||||
mock_auth_service, access_token, api_token_header,
|
||||
mock_auth_service,
|
||||
access_token,
|
||||
api_token_header,
|
||||
)
|
||||
|
||||
assert result == test_user
|
||||
mock_auth_service.get_user_by_api_token.assert_called_once_with("test_api_token_123")
|
||||
mock_auth_service.get_user_by_api_token.assert_called_once_with(
|
||||
"test_api_token_123"
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_current_user_flexible_falls_back_to_jwt(self, mock_auth_service):
|
||||
@@ -165,7 +183,9 @@ class TestApiTokenDependencies:
|
||||
await get_current_user_flexible(mock_auth_service, "jwt_token", None)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_api_token_no_expiry_never_expires(self, mock_auth_service, test_user):
|
||||
async def test_api_token_no_expiry_never_expires(
|
||||
self, mock_auth_service, test_user
|
||||
):
|
||||
"""Test API token with no expiry date never expires."""
|
||||
test_user.api_token_expires_at = None
|
||||
mock_auth_service.get_user_by_api_token.return_value = test_user
|
||||
|
||||
Reference in New Issue
Block a user