Refactor test files for improved readability and consistency
- Removed unnecessary blank lines and adjusted formatting in test files. - Ensured consistent use of commas in function calls and assertions across various test cases. - Updated import statements for better organization and clarity. - Enhanced mock setups in tests for better isolation and reliability. - Improved assertions to follow a consistent style for better readability.
This commit is contained in:
@@ -153,7 +153,6 @@ class TestPlaylistService:
|
||||
test_user: User,
|
||||
) -> None:
|
||||
"""Test getting non-existent playlist."""
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
await playlist_service.get_playlist_by_id(99999)
|
||||
|
||||
@@ -168,7 +167,6 @@ class TestPlaylistService:
|
||||
test_session: AsyncSession,
|
||||
) -> None:
|
||||
"""Test getting existing main playlist."""
|
||||
|
||||
# Create main playlist manually
|
||||
main_playlist = Playlist(
|
||||
user_id=None,
|
||||
@@ -193,7 +191,6 @@ class TestPlaylistService:
|
||||
test_user: User,
|
||||
) -> None:
|
||||
"""Test that service fails if main playlist doesn't exist."""
|
||||
|
||||
# Should raise an HTTPException if no main playlist exists
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
await playlist_service.get_main_playlist()
|
||||
@@ -207,7 +204,6 @@ class TestPlaylistService:
|
||||
test_user: User,
|
||||
) -> None:
|
||||
"""Test creating a new playlist successfully."""
|
||||
|
||||
user_id = test_user.id # Extract user_id while session is available
|
||||
playlist = await playlist_service.create_playlist(
|
||||
user_id=user_id,
|
||||
@@ -246,7 +242,7 @@ class TestPlaylistService:
|
||||
test_session.add(playlist)
|
||||
await test_session.commit()
|
||||
await test_session.refresh(playlist)
|
||||
|
||||
|
||||
# Extract name before async call
|
||||
playlist_name = playlist.name
|
||||
|
||||
@@ -280,10 +276,10 @@ class TestPlaylistService:
|
||||
test_session.add(current_playlist)
|
||||
await test_session.commit()
|
||||
await test_session.refresh(current_playlist)
|
||||
|
||||
|
||||
# Verify the existing current playlist
|
||||
assert current_playlist.is_current is True
|
||||
|
||||
|
||||
# Extract ID before async call
|
||||
current_playlist_id = current_playlist.id
|
||||
|
||||
@@ -323,10 +319,10 @@ class TestPlaylistService:
|
||||
test_session.add(playlist)
|
||||
await test_session.commit()
|
||||
await test_session.refresh(playlist)
|
||||
|
||||
|
||||
# Extract IDs before async call
|
||||
playlist_id = playlist.id
|
||||
|
||||
|
||||
updated_playlist = await playlist_service.update_playlist(
|
||||
playlist_id=playlist_id,
|
||||
user_id=user_id,
|
||||
@@ -359,7 +355,7 @@ class TestPlaylistService:
|
||||
is_deletable=True,
|
||||
)
|
||||
test_session.add(test_playlist)
|
||||
|
||||
|
||||
current_playlist = Playlist(
|
||||
user_id=user_id,
|
||||
name="Current Playlist",
|
||||
@@ -372,7 +368,7 @@ class TestPlaylistService:
|
||||
await test_session.commit()
|
||||
await test_session.refresh(test_playlist)
|
||||
await test_session.refresh(current_playlist)
|
||||
|
||||
|
||||
# Extract IDs before async calls
|
||||
test_playlist_id = test_playlist.id
|
||||
current_playlist_id = current_playlist.id
|
||||
@@ -416,7 +412,7 @@ class TestPlaylistService:
|
||||
test_session.add(playlist)
|
||||
await test_session.commit()
|
||||
await test_session.refresh(playlist)
|
||||
|
||||
|
||||
# Extract ID before async call
|
||||
playlist_id = playlist.id
|
||||
|
||||
@@ -445,7 +441,7 @@ class TestPlaylistService:
|
||||
is_deletable=False,
|
||||
)
|
||||
test_session.add(main_playlist)
|
||||
|
||||
|
||||
# Create current playlist within this test
|
||||
user_id = test_user.id
|
||||
current_playlist = Playlist(
|
||||
@@ -459,7 +455,7 @@ class TestPlaylistService:
|
||||
test_session.add(current_playlist)
|
||||
await test_session.commit()
|
||||
await test_session.refresh(current_playlist)
|
||||
|
||||
|
||||
# Extract ID before async call
|
||||
current_playlist_id = current_playlist.id
|
||||
|
||||
@@ -481,7 +477,7 @@ class TestPlaylistService:
|
||||
"""Test deleting non-deletable playlist fails."""
|
||||
# Extract user ID immediately
|
||||
user_id = test_user.id
|
||||
|
||||
|
||||
# Create non-deletable playlist
|
||||
non_deletable = Playlist(
|
||||
user_id=user_id,
|
||||
@@ -491,7 +487,7 @@ class TestPlaylistService:
|
||||
test_session.add(non_deletable)
|
||||
await test_session.commit()
|
||||
await test_session.refresh(non_deletable)
|
||||
|
||||
|
||||
# Extract ID before async call
|
||||
non_deletable_id = non_deletable.id
|
||||
|
||||
@@ -521,7 +517,7 @@ class TestPlaylistService:
|
||||
is_deletable=True,
|
||||
)
|
||||
test_session.add(playlist)
|
||||
|
||||
|
||||
sound = Sound(
|
||||
name="Test Sound",
|
||||
filename="test.mp3",
|
||||
@@ -535,7 +531,7 @@ class TestPlaylistService:
|
||||
await test_session.commit()
|
||||
await test_session.refresh(playlist)
|
||||
await test_session.refresh(sound)
|
||||
|
||||
|
||||
# Extract IDs before async calls
|
||||
playlist_id = playlist.id
|
||||
sound_id = sound.id
|
||||
@@ -571,7 +567,7 @@ class TestPlaylistService:
|
||||
is_deletable=True,
|
||||
)
|
||||
test_session.add(playlist)
|
||||
|
||||
|
||||
sound = Sound(
|
||||
name="Test Sound",
|
||||
filename="test.mp3",
|
||||
@@ -585,7 +581,7 @@ class TestPlaylistService:
|
||||
await test_session.commit()
|
||||
await test_session.refresh(playlist)
|
||||
await test_session.refresh(sound)
|
||||
|
||||
|
||||
# Extract IDs before async calls
|
||||
playlist_id = playlist.id
|
||||
sound_id = sound.id
|
||||
@@ -628,7 +624,7 @@ class TestPlaylistService:
|
||||
is_deletable=True,
|
||||
)
|
||||
test_session.add(playlist)
|
||||
|
||||
|
||||
sound = Sound(
|
||||
name="Test Sound",
|
||||
filename="test.mp3",
|
||||
@@ -642,7 +638,7 @@ class TestPlaylistService:
|
||||
await test_session.commit()
|
||||
await test_session.refresh(playlist)
|
||||
await test_session.refresh(sound)
|
||||
|
||||
|
||||
# Extract IDs before async calls
|
||||
playlist_id = playlist.id
|
||||
sound_id = sound.id
|
||||
@@ -685,7 +681,7 @@ class TestPlaylistService:
|
||||
is_deletable=True,
|
||||
)
|
||||
test_session.add(playlist)
|
||||
|
||||
|
||||
sound = Sound(
|
||||
name="Test Sound",
|
||||
filename="test.mp3",
|
||||
@@ -699,7 +695,7 @@ class TestPlaylistService:
|
||||
await test_session.commit()
|
||||
await test_session.refresh(playlist)
|
||||
await test_session.refresh(sound)
|
||||
|
||||
|
||||
# Extract IDs before async calls
|
||||
playlist_id = playlist.id
|
||||
sound_id = sound.id
|
||||
@@ -734,7 +730,7 @@ class TestPlaylistService:
|
||||
is_deletable=True,
|
||||
)
|
||||
test_session.add(test_playlist)
|
||||
|
||||
|
||||
current_playlist = Playlist(
|
||||
user_id=user_id,
|
||||
name="Current Playlist",
|
||||
@@ -747,7 +743,7 @@ class TestPlaylistService:
|
||||
await test_session.commit()
|
||||
await test_session.refresh(test_playlist)
|
||||
await test_session.refresh(current_playlist)
|
||||
|
||||
|
||||
# Extract IDs before async calls
|
||||
test_playlist_id = test_playlist.id
|
||||
current_playlist_id = current_playlist.id
|
||||
@@ -758,7 +754,7 @@ class TestPlaylistService:
|
||||
|
||||
# Set test_playlist as current
|
||||
updated_playlist = await playlist_service.set_current_playlist(
|
||||
test_playlist_id, user_id
|
||||
test_playlist_id, user_id,
|
||||
)
|
||||
|
||||
assert updated_playlist.is_current is True
|
||||
@@ -786,7 +782,7 @@ class TestPlaylistService:
|
||||
is_deletable=True,
|
||||
)
|
||||
test_session.add(current_playlist)
|
||||
|
||||
|
||||
main_playlist = Playlist(
|
||||
user_id=None,
|
||||
name="Main Playlist",
|
||||
@@ -799,7 +795,7 @@ class TestPlaylistService:
|
||||
await test_session.commit()
|
||||
await test_session.refresh(current_playlist)
|
||||
await test_session.refresh(main_playlist)
|
||||
|
||||
|
||||
# Extract IDs before async calls
|
||||
current_playlist_id = current_playlist.id
|
||||
main_playlist_id = main_playlist.id
|
||||
@@ -839,7 +835,7 @@ class TestPlaylistService:
|
||||
is_deletable=True,
|
||||
)
|
||||
test_session.add(playlist)
|
||||
|
||||
|
||||
sound = Sound(
|
||||
name="Test Sound",
|
||||
filename="test.mp3",
|
||||
@@ -853,7 +849,7 @@ class TestPlaylistService:
|
||||
await test_session.commit()
|
||||
await test_session.refresh(playlist)
|
||||
await test_session.refresh(sound)
|
||||
|
||||
|
||||
# Extract IDs before async calls
|
||||
playlist_id = playlist.id
|
||||
sound_id = sound.id
|
||||
@@ -897,7 +893,7 @@ class TestPlaylistService:
|
||||
play_count=10,
|
||||
)
|
||||
test_session.add(sound)
|
||||
|
||||
|
||||
main_playlist = Playlist(
|
||||
user_id=None,
|
||||
name="Main Playlist",
|
||||
@@ -910,7 +906,7 @@ class TestPlaylistService:
|
||||
await test_session.commit()
|
||||
await test_session.refresh(sound)
|
||||
await test_session.refresh(main_playlist)
|
||||
|
||||
|
||||
# Extract IDs before async calls
|
||||
sound_id = sound.id
|
||||
main_playlist_id = main_playlist.id
|
||||
@@ -943,7 +939,7 @@ class TestPlaylistService:
|
||||
play_count=10,
|
||||
)
|
||||
test_session.add(sound)
|
||||
|
||||
|
||||
main_playlist = Playlist(
|
||||
user_id=None,
|
||||
name="Main Playlist",
|
||||
@@ -956,7 +952,7 @@ class TestPlaylistService:
|
||||
await test_session.commit()
|
||||
await test_session.refresh(sound)
|
||||
await test_session.refresh(main_playlist)
|
||||
|
||||
|
||||
# Extract IDs before async calls
|
||||
sound_id = sound.id
|
||||
main_playlist_id = main_playlist.id
|
||||
|
||||
Reference in New Issue
Block a user