Refactor user endpoint tests to include pagination and response structure validation
- Updated tests for listing users to validate pagination and response format. - Changed mock return values to include total count and pagination details. - Refactored user creation mocks for clarity and consistency. - Enhanced assertions to check for presence of pagination fields in responses. - Adjusted test cases for user retrieval and updates to ensure proper handling of user data. - Improved readability by restructuring mock definitions and assertions across various test files.
This commit is contained in:
@@ -539,21 +539,35 @@ class TestPlaylistRepository:
|
||||
sound_ids = [s.id for s in sounds]
|
||||
|
||||
# Add first two sounds sequentially (positions 0, 1)
|
||||
await playlist_repository.add_sound_to_playlist(playlist_id, sound_ids[0]) # position 0
|
||||
await playlist_repository.add_sound_to_playlist(playlist_id, sound_ids[1]) # position 1
|
||||
await playlist_repository.add_sound_to_playlist(
|
||||
playlist_id, sound_ids[0],
|
||||
) # position 0
|
||||
await playlist_repository.add_sound_to_playlist(
|
||||
playlist_id, sound_ids[1],
|
||||
) # position 1
|
||||
|
||||
# Now insert third sound at position 1 - should shift existing sound at position 1 to position 2
|
||||
await playlist_repository.add_sound_to_playlist(playlist_id, sound_ids[2], position=1)
|
||||
await playlist_repository.add_sound_to_playlist(
|
||||
playlist_id, sound_ids[2], position=1,
|
||||
)
|
||||
|
||||
# Verify the final positions
|
||||
playlist_sounds = await playlist_repository.get_playlist_sound_entries(playlist_id)
|
||||
playlist_sounds = await playlist_repository.get_playlist_sound_entries(
|
||||
playlist_id,
|
||||
)
|
||||
|
||||
assert len(playlist_sounds) == 3
|
||||
assert playlist_sounds[0].sound_id == sound_ids[0] # Original sound 0 stays at position 0
|
||||
assert (
|
||||
playlist_sounds[0].sound_id == sound_ids[0]
|
||||
) # Original sound 0 stays at position 0
|
||||
assert playlist_sounds[0].position == 0
|
||||
assert playlist_sounds[1].sound_id == sound_ids[2] # New sound 2 inserted at position 1
|
||||
assert (
|
||||
playlist_sounds[1].sound_id == sound_ids[2]
|
||||
) # New sound 2 inserted at position 1
|
||||
assert playlist_sounds[1].position == 1
|
||||
assert playlist_sounds[2].sound_id == sound_ids[1] # Original sound 1 shifted to position 2
|
||||
assert (
|
||||
playlist_sounds[2].sound_id == sound_ids[1]
|
||||
) # Original sound 1 shifted to position 2
|
||||
assert playlist_sounds[2].position == 2
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -615,21 +629,35 @@ class TestPlaylistRepository:
|
||||
sound_ids = [s.id for s in sounds]
|
||||
|
||||
# Add first two sounds sequentially (positions 0, 1)
|
||||
await playlist_repository.add_sound_to_playlist(playlist_id, sound_ids[0]) # position 0
|
||||
await playlist_repository.add_sound_to_playlist(playlist_id, sound_ids[1]) # position 1
|
||||
await playlist_repository.add_sound_to_playlist(
|
||||
playlist_id, sound_ids[0],
|
||||
) # position 0
|
||||
await playlist_repository.add_sound_to_playlist(
|
||||
playlist_id, sound_ids[1],
|
||||
) # position 1
|
||||
|
||||
# Now insert third sound at position 0 - should shift existing sounds to positions 1, 2
|
||||
await playlist_repository.add_sound_to_playlist(playlist_id, sound_ids[2], position=0)
|
||||
await playlist_repository.add_sound_to_playlist(
|
||||
playlist_id, sound_ids[2], position=0,
|
||||
)
|
||||
|
||||
# Verify the final positions
|
||||
playlist_sounds = await playlist_repository.get_playlist_sound_entries(playlist_id)
|
||||
playlist_sounds = await playlist_repository.get_playlist_sound_entries(
|
||||
playlist_id,
|
||||
)
|
||||
|
||||
assert len(playlist_sounds) == 3
|
||||
assert playlist_sounds[0].sound_id == sound_ids[2] # New sound 2 inserted at position 0
|
||||
assert (
|
||||
playlist_sounds[0].sound_id == sound_ids[2]
|
||||
) # New sound 2 inserted at position 0
|
||||
assert playlist_sounds[0].position == 0
|
||||
assert playlist_sounds[1].sound_id == sound_ids[0] # Original sound 0 shifted to position 1
|
||||
assert (
|
||||
playlist_sounds[1].sound_id == sound_ids[0]
|
||||
) # Original sound 0 shifted to position 1
|
||||
assert playlist_sounds[1].position == 1
|
||||
assert playlist_sounds[2].sound_id == sound_ids[1] # Original sound 1 shifted to position 2
|
||||
assert (
|
||||
playlist_sounds[2].sound_id == sound_ids[1]
|
||||
) # Original sound 1 shifted to position 2
|
||||
assert playlist_sounds[2].position == 2
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user