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:
@@ -57,7 +57,8 @@ class PlaylistRepository(BaseRepository[Playlist]):
|
||||
# management
|
||||
except Exception:
|
||||
logger.exception(
|
||||
"Failed to update playlist timestamp for playlist: %s", playlist_id,
|
||||
"Failed to update playlist timestamp for playlist: %s",
|
||||
playlist_id,
|
||||
)
|
||||
raise
|
||||
|
||||
@@ -341,7 +342,7 @@ class PlaylistRepository(BaseRepository[Playlist]):
|
||||
include_stats: bool = False, # noqa: FBT001, FBT002
|
||||
limit: int | None = None,
|
||||
offset: int = 0,
|
||||
favorites_only: bool = False,
|
||||
favorites_only: bool = False, # noqa: FBT001, FBT002
|
||||
current_user_id: int | None = None,
|
||||
*,
|
||||
return_count: bool = False,
|
||||
@@ -395,9 +396,13 @@ class PlaylistRepository(BaseRepository[Playlist]):
|
||||
# Apply favorites filter
|
||||
if favorites_only and current_user_id is not None:
|
||||
# Use EXISTS subquery to avoid JOIN conflicts with GROUP BY
|
||||
favorites_subquery = select(1).select_from(Favorite).where(
|
||||
Favorite.user_id == current_user_id,
|
||||
Favorite.playlist_id == Playlist.id,
|
||||
favorites_subquery = (
|
||||
select(1)
|
||||
.select_from(Favorite)
|
||||
.where(
|
||||
Favorite.user_id == current_user_id,
|
||||
Favorite.playlist_id == Playlist.id,
|
||||
)
|
||||
)
|
||||
subquery = subquery.where(favorites_subquery.exists())
|
||||
|
||||
@@ -466,9 +471,13 @@ class PlaylistRepository(BaseRepository[Playlist]):
|
||||
# Apply favorites filter
|
||||
if favorites_only and current_user_id is not None:
|
||||
# Use EXISTS subquery to avoid JOIN conflicts with GROUP BY
|
||||
favorites_subquery = select(1).select_from(Favorite).where(
|
||||
Favorite.user_id == current_user_id,
|
||||
Favorite.playlist_id == Playlist.id,
|
||||
favorites_subquery = (
|
||||
select(1)
|
||||
.select_from(Favorite)
|
||||
.where(
|
||||
Favorite.user_id == current_user_id,
|
||||
Favorite.playlist_id == Playlist.id,
|
||||
)
|
||||
)
|
||||
subquery = subquery.where(favorites_subquery.exists())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user