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:
@@ -48,11 +48,15 @@ class TestAuthService:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_register_duplicate_email(
|
||||
self, auth_service: AuthService, test_user: User,
|
||||
self,
|
||||
auth_service: AuthService,
|
||||
test_user: User,
|
||||
) -> None:
|
||||
"""Test registration with duplicate email."""
|
||||
request = UserRegisterRequest(
|
||||
email=test_user.email, password="password123", name="Another User",
|
||||
email=test_user.email,
|
||||
password="password123",
|
||||
name="Another User",
|
||||
)
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
@@ -89,7 +93,8 @@ class TestAuthService:
|
||||
async def test_login_invalid_email(self, auth_service: AuthService) -> None:
|
||||
"""Test login with invalid email."""
|
||||
request = UserLoginRequest(
|
||||
email="nonexistent@example.com", password="password123",
|
||||
email="nonexistent@example.com",
|
||||
password="password123",
|
||||
)
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
@@ -100,7 +105,9 @@ class TestAuthService:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_login_invalid_password(
|
||||
self, auth_service: AuthService, test_user: User,
|
||||
self,
|
||||
auth_service: AuthService,
|
||||
test_user: User,
|
||||
) -> None:
|
||||
"""Test login with invalid password."""
|
||||
request = UserLoginRequest(email=test_user.email, password="wrongpassword")
|
||||
@@ -113,7 +120,10 @@ class TestAuthService:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_login_inactive_user(
|
||||
self, auth_service: AuthService, test_user: User, test_session: AsyncSession,
|
||||
self,
|
||||
auth_service: AuthService,
|
||||
test_user: User,
|
||||
test_session: AsyncSession,
|
||||
) -> None:
|
||||
"""Test login with inactive user."""
|
||||
# Store the email before deactivating
|
||||
@@ -133,7 +143,10 @@ class TestAuthService:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_login_user_without_password(
|
||||
self, auth_service: AuthService, test_user: User, test_session: AsyncSession,
|
||||
self,
|
||||
auth_service: AuthService,
|
||||
test_user: User,
|
||||
test_session: AsyncSession,
|
||||
) -> None:
|
||||
"""Test login with user that has no password hash."""
|
||||
# Store the email before removing password
|
||||
@@ -153,7 +166,9 @@ class TestAuthService:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_current_user_success(
|
||||
self, auth_service: AuthService, test_user: User,
|
||||
self,
|
||||
auth_service: AuthService,
|
||||
test_user: User,
|
||||
) -> None:
|
||||
"""Test getting current user successfully."""
|
||||
user = await auth_service.get_current_user(test_user.id)
|
||||
@@ -174,7 +189,10 @@ class TestAuthService:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_current_user_inactive(
|
||||
self, auth_service: AuthService, test_user: User, test_session: AsyncSession,
|
||||
self,
|
||||
auth_service: AuthService,
|
||||
test_user: User,
|
||||
test_session: AsyncSession,
|
||||
) -> None:
|
||||
"""Test getting current user when user is inactive."""
|
||||
# Store the user ID before deactivating
|
||||
@@ -192,7 +210,9 @@ class TestAuthService:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_access_token(
|
||||
self, auth_service: AuthService, test_user: User,
|
||||
self,
|
||||
auth_service: AuthService,
|
||||
test_user: User,
|
||||
) -> None:
|
||||
"""Test access token creation."""
|
||||
token_response = auth_service._create_access_token(test_user)
|
||||
@@ -211,7 +231,10 @@ class TestAuthService:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_user_response(
|
||||
self, auth_service: AuthService, test_user: User, test_session: AsyncSession,
|
||||
self,
|
||||
auth_service: AuthService,
|
||||
test_user: User,
|
||||
test_session: AsyncSession,
|
||||
) -> None:
|
||||
"""Test user response creation."""
|
||||
# Ensure plan relationship is loaded
|
||||
|
||||
Reference in New Issue
Block a user