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:
@@ -58,7 +58,7 @@ class ExtractionRepository(BaseRepository[Extraction]):
|
||||
)
|
||||
return list(result.all())
|
||||
|
||||
async def get_user_extractions_filtered(
|
||||
async def get_user_extractions_filtered( # noqa: PLR0913
|
||||
self,
|
||||
user_id: int,
|
||||
search: str | None = None,
|
||||
@@ -92,7 +92,7 @@ class ExtractionRepository(BaseRepository[Extraction]):
|
||||
|
||||
# Get total count before pagination
|
||||
count_query = select(func.count()).select_from(
|
||||
base_query.subquery()
|
||||
base_query.subquery(),
|
||||
)
|
||||
count_result = await self.session.exec(count_query)
|
||||
total_count = count_result.one()
|
||||
@@ -106,10 +106,10 @@ class ExtractionRepository(BaseRepository[Extraction]):
|
||||
|
||||
paginated_query = base_query.limit(limit).offset(offset)
|
||||
result = await self.session.exec(paginated_query)
|
||||
|
||||
|
||||
return list(result.all()), total_count
|
||||
|
||||
async def get_all_extractions_filtered(
|
||||
async def get_all_extractions_filtered( # noqa: PLR0913
|
||||
self,
|
||||
search: str | None = None,
|
||||
sort_by: str = "created_at",
|
||||
@@ -138,7 +138,7 @@ class ExtractionRepository(BaseRepository[Extraction]):
|
||||
|
||||
# Get total count before pagination
|
||||
count_query = select(func.count()).select_from(
|
||||
base_query.subquery()
|
||||
base_query.subquery(),
|
||||
)
|
||||
count_result = await self.session.exec(count_query)
|
||||
total_count = count_result.one()
|
||||
@@ -152,5 +152,5 @@ class ExtractionRepository(BaseRepository[Extraction]):
|
||||
|
||||
paginated_query = base_query.limit(limit).offset(offset)
|
||||
result = await self.session.exec(paginated_query)
|
||||
|
||||
|
||||
return list(result.all()), total_count
|
||||
|
||||
Reference in New Issue
Block a user