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:
@@ -40,7 +40,7 @@ async def get_sound_repository(
|
||||
return SoundRepository(session)
|
||||
|
||||
|
||||
@router.get("/", response_model=SoundsListResponse)
|
||||
@router.get("/")
|
||||
async def get_sounds( # noqa: PLR0913
|
||||
current_user: Annotated[User, Depends(get_current_active_user_flexible)],
|
||||
sound_repo: Annotated[SoundRepository, Depends(get_sound_repository)],
|
||||
@@ -69,7 +69,7 @@ async def get_sounds( # noqa: PLR0913
|
||||
int,
|
||||
Query(description="Number of results to skip", ge=0),
|
||||
] = 0,
|
||||
favorites_only: Annotated[
|
||||
favorites_only: Annotated[ # noqa: FBT002
|
||||
bool,
|
||||
Query(description="Show only favorited sounds"),
|
||||
] = False,
|
||||
@@ -90,9 +90,13 @@ async def get_sounds( # noqa: PLR0913
|
||||
# Add favorite indicators for each sound
|
||||
sound_responses = []
|
||||
for sound in sounds:
|
||||
is_favorited = await favorite_service.is_sound_favorited(current_user.id, sound.id)
|
||||
is_favorited = await favorite_service.is_sound_favorited(
|
||||
current_user.id, sound.id,
|
||||
)
|
||||
favorite_count = await favorite_service.get_sound_favorite_count(sound.id)
|
||||
sound_response = SoundResponse.from_sound(sound, is_favorited, favorite_count)
|
||||
sound_response = SoundResponse.from_sound(
|
||||
sound, is_favorited, favorite_count,
|
||||
)
|
||||
sound_responses.append(sound_response)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user