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:
@@ -151,10 +151,10 @@ class TestPlaylistRepository:
|
||||
test_session.add(user)
|
||||
await test_session.commit()
|
||||
await test_session.refresh(user)
|
||||
|
||||
|
||||
# Extract user ID immediately after refresh
|
||||
user_id = user.id
|
||||
|
||||
|
||||
# Create test playlist for this user
|
||||
playlist = Playlist(
|
||||
user_id=user_id,
|
||||
@@ -167,10 +167,10 @@ class TestPlaylistRepository:
|
||||
)
|
||||
test_session.add(playlist)
|
||||
await test_session.commit()
|
||||
|
||||
|
||||
# Test the repository method
|
||||
playlists = await playlist_repository.get_by_user_id(user_id)
|
||||
|
||||
|
||||
# Should only return user's playlists, not the main playlist (user_id=None)
|
||||
assert len(playlists) == 1
|
||||
assert playlists[0].name == "Test Playlist"
|
||||
@@ -194,13 +194,13 @@ class TestPlaylistRepository:
|
||||
test_session.add(main_playlist)
|
||||
await test_session.commit()
|
||||
await test_session.refresh(main_playlist)
|
||||
|
||||
|
||||
# Extract ID before async call
|
||||
main_playlist_id = main_playlist.id
|
||||
|
||||
|
||||
# Test the repository method
|
||||
playlist = await playlist_repository.get_main_playlist()
|
||||
|
||||
|
||||
assert playlist is not None
|
||||
assert playlist.id == main_playlist_id
|
||||
assert playlist.is_main is True
|
||||
@@ -227,13 +227,13 @@ class TestPlaylistRepository:
|
||||
test_session.add(user)
|
||||
await test_session.commit()
|
||||
await test_session.refresh(user)
|
||||
|
||||
|
||||
# Extract user ID immediately after refresh
|
||||
user_id = user.id
|
||||
|
||||
|
||||
# Test the repository method - should return None when no current playlist
|
||||
playlist = await playlist_repository.get_current_playlist(user_id)
|
||||
|
||||
|
||||
# Should return None since no user playlist is marked as current
|
||||
assert playlist is None
|
||||
|
||||
@@ -319,10 +319,10 @@ class TestPlaylistRepository:
|
||||
test_session.add(user)
|
||||
await test_session.commit()
|
||||
await test_session.refresh(user)
|
||||
|
||||
|
||||
# Extract user ID immediately after refresh
|
||||
user_id = user.id
|
||||
|
||||
|
||||
# Create test playlist
|
||||
test_playlist = Playlist(
|
||||
user_id=user_id,
|
||||
@@ -334,7 +334,7 @@ class TestPlaylistRepository:
|
||||
is_deletable=True,
|
||||
)
|
||||
test_session.add(test_playlist)
|
||||
|
||||
|
||||
# Create main playlist
|
||||
main_playlist = Playlist(
|
||||
user_id=None,
|
||||
@@ -346,7 +346,7 @@ class TestPlaylistRepository:
|
||||
)
|
||||
test_session.add(main_playlist)
|
||||
await test_session.commit()
|
||||
|
||||
|
||||
# Search for all playlists (no user filter)
|
||||
all_results = await playlist_repository.search_by_name("playlist")
|
||||
assert len(all_results) >= 2 # Should include both user and main playlists
|
||||
@@ -382,7 +382,7 @@ class TestPlaylistRepository:
|
||||
test_session.add(user)
|
||||
await test_session.commit()
|
||||
await test_session.refresh(user)
|
||||
|
||||
|
||||
# Create test playlist
|
||||
playlist = Playlist(
|
||||
user_id=user.id,
|
||||
@@ -394,7 +394,7 @@ class TestPlaylistRepository:
|
||||
is_deletable=True,
|
||||
)
|
||||
test_session.add(playlist)
|
||||
|
||||
|
||||
# Create test sound
|
||||
sound = Sound(
|
||||
name="Test Sound",
|
||||
@@ -409,14 +409,14 @@ class TestPlaylistRepository:
|
||||
await test_session.commit()
|
||||
await test_session.refresh(playlist)
|
||||
await test_session.refresh(sound)
|
||||
|
||||
|
||||
# Extract IDs before async call
|
||||
playlist_id = playlist.id
|
||||
sound_id = sound.id
|
||||
|
||||
|
||||
# Test the repository method
|
||||
playlist_sound = await playlist_repository.add_sound_to_playlist(
|
||||
playlist_id, sound_id
|
||||
playlist_id, sound_id,
|
||||
)
|
||||
|
||||
assert playlist_sound.playlist_id == playlist_id
|
||||
@@ -445,10 +445,10 @@ class TestPlaylistRepository:
|
||||
test_session.add(user)
|
||||
await test_session.commit()
|
||||
await test_session.refresh(user)
|
||||
|
||||
|
||||
# Extract user ID immediately after refresh
|
||||
user_id = user.id
|
||||
|
||||
|
||||
# Create test playlist
|
||||
playlist = Playlist(
|
||||
user_id=user_id,
|
||||
@@ -460,7 +460,7 @@ class TestPlaylistRepository:
|
||||
is_deletable=True,
|
||||
)
|
||||
test_session.add(playlist)
|
||||
|
||||
|
||||
# Create test sound
|
||||
sound = Sound(
|
||||
name="Test Sound",
|
||||
@@ -475,14 +475,14 @@ class TestPlaylistRepository:
|
||||
await test_session.commit()
|
||||
await test_session.refresh(playlist)
|
||||
await test_session.refresh(sound)
|
||||
|
||||
|
||||
# Extract IDs before async call
|
||||
playlist_id = playlist.id
|
||||
sound_id = sound.id
|
||||
|
||||
|
||||
# Test the repository method
|
||||
playlist_sound = await playlist_repository.add_sound_to_playlist(
|
||||
playlist_id, sound_id, position=5
|
||||
playlist_id, sound_id, position=5,
|
||||
)
|
||||
|
||||
assert playlist_sound.position == 5
|
||||
@@ -509,9 +509,9 @@ class TestPlaylistRepository:
|
||||
test_session.add(user)
|
||||
await test_session.commit()
|
||||
await test_session.refresh(user)
|
||||
|
||||
|
||||
user_id = user.id
|
||||
|
||||
|
||||
playlist = Playlist(
|
||||
user_id=user_id,
|
||||
name="Test Playlist",
|
||||
@@ -522,7 +522,7 @@ class TestPlaylistRepository:
|
||||
is_deletable=True,
|
||||
)
|
||||
test_session.add(playlist)
|
||||
|
||||
|
||||
sound = Sound(
|
||||
name="Test Sound",
|
||||
filename="test.mp3",
|
||||
@@ -536,7 +536,7 @@ class TestPlaylistRepository:
|
||||
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
|
||||
@@ -546,17 +546,17 @@ class TestPlaylistRepository:
|
||||
|
||||
# Verify it was added
|
||||
assert await playlist_repository.is_sound_in_playlist(
|
||||
playlist_id, sound_id
|
||||
playlist_id, sound_id,
|
||||
)
|
||||
|
||||
# Remove the sound
|
||||
await playlist_repository.remove_sound_from_playlist(
|
||||
playlist_id, sound_id
|
||||
playlist_id, sound_id,
|
||||
)
|
||||
|
||||
# Verify it was removed
|
||||
assert not await playlist_repository.is_sound_in_playlist(
|
||||
playlist_id, sound_id
|
||||
playlist_id, sound_id,
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -581,9 +581,9 @@ class TestPlaylistRepository:
|
||||
test_session.add(user)
|
||||
await test_session.commit()
|
||||
await test_session.refresh(user)
|
||||
|
||||
|
||||
user_id = user.id
|
||||
|
||||
|
||||
playlist = Playlist(
|
||||
user_id=user_id,
|
||||
name="Test Playlist",
|
||||
@@ -594,7 +594,7 @@ class TestPlaylistRepository:
|
||||
is_deletable=True,
|
||||
)
|
||||
test_session.add(playlist)
|
||||
|
||||
|
||||
sound = Sound(
|
||||
name="Test Sound",
|
||||
filename="test.mp3",
|
||||
@@ -608,7 +608,7 @@ class TestPlaylistRepository:
|
||||
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
|
||||
@@ -647,9 +647,9 @@ class TestPlaylistRepository:
|
||||
test_session.add(user)
|
||||
await test_session.commit()
|
||||
await test_session.refresh(user)
|
||||
|
||||
|
||||
user_id = user.id
|
||||
|
||||
|
||||
playlist = Playlist(
|
||||
user_id=user_id,
|
||||
name="Test Playlist",
|
||||
@@ -660,7 +660,7 @@ class TestPlaylistRepository:
|
||||
is_deletable=True,
|
||||
)
|
||||
test_session.add(playlist)
|
||||
|
||||
|
||||
sound = Sound(
|
||||
name="Test Sound",
|
||||
filename="test.mp3",
|
||||
@@ -674,7 +674,7 @@ class TestPlaylistRepository:
|
||||
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
|
||||
@@ -712,9 +712,9 @@ class TestPlaylistRepository:
|
||||
test_session.add(user)
|
||||
await test_session.commit()
|
||||
await test_session.refresh(user)
|
||||
|
||||
|
||||
user_id = user.id
|
||||
|
||||
|
||||
playlist = Playlist(
|
||||
user_id=user_id,
|
||||
name="Test Playlist",
|
||||
@@ -725,7 +725,7 @@ class TestPlaylistRepository:
|
||||
is_deletable=True,
|
||||
)
|
||||
test_session.add(playlist)
|
||||
|
||||
|
||||
sound = Sound(
|
||||
name="Test Sound",
|
||||
filename="test.mp3",
|
||||
@@ -739,14 +739,14 @@ class TestPlaylistRepository:
|
||||
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
|
||||
|
||||
# Initially not in playlist
|
||||
assert not await playlist_repository.is_sound_in_playlist(
|
||||
playlist_id, sound_id
|
||||
playlist_id, sound_id,
|
||||
)
|
||||
|
||||
# Add sound
|
||||
@@ -754,7 +754,7 @@ class TestPlaylistRepository:
|
||||
|
||||
# Now in playlist
|
||||
assert await playlist_repository.is_sound_in_playlist(
|
||||
playlist_id, sound_id
|
||||
playlist_id, sound_id,
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -779,9 +779,9 @@ class TestPlaylistRepository:
|
||||
test_session.add(user)
|
||||
await test_session.commit()
|
||||
await test_session.refresh(user)
|
||||
|
||||
|
||||
user_id = user.id
|
||||
|
||||
|
||||
playlist = Playlist(
|
||||
user_id=user_id,
|
||||
name="Test Playlist",
|
||||
@@ -801,7 +801,7 @@ class TestPlaylistRepository:
|
||||
await test_session.refresh(playlist)
|
||||
await test_session.refresh(sound1)
|
||||
await test_session.refresh(sound2)
|
||||
|
||||
|
||||
# Extract IDs before async calls
|
||||
playlist_id = playlist.id
|
||||
sound1_id = sound1.id
|
||||
@@ -809,16 +809,16 @@ class TestPlaylistRepository:
|
||||
|
||||
# Add sounds to playlist
|
||||
await playlist_repository.add_sound_to_playlist(
|
||||
playlist_id, sound1_id, position=0
|
||||
playlist_id, sound1_id, position=0,
|
||||
)
|
||||
await playlist_repository.add_sound_to_playlist(
|
||||
playlist_id, sound2_id, position=1
|
||||
playlist_id, sound2_id, position=1,
|
||||
)
|
||||
|
||||
# Reorder sounds - use different positions to avoid constraint issues
|
||||
sound_positions = [(sound1_id, 10), (sound2_id, 5)]
|
||||
await playlist_repository.reorder_playlist_sounds(
|
||||
playlist_id, sound_positions
|
||||
playlist_id, sound_positions,
|
||||
)
|
||||
|
||||
# Verify new order
|
||||
|
||||
Reference in New Issue
Block a user