Fix pagination metadata return structure and test assertions
The API pagination infrastructure was already correctly implemented with:
- PaginatedListResponse base model containing 'items' and 'pagination' fields
- PaginationMetadata object with all required fields (page, page_size, total, total_pages, has_next_page, has_prev_page)
- All services correctly calling create_pagination_metadata()
However, there were two bugs preventing tests from passing:
1. IMPORT BUG: time_utils.py was importing TIME_RANGE_SECONDS from app.models.ban
when it's actually defined in app.models._common. This caused import errors
in tests that exercise time-range filtering.
2. TEST BUG: Test assertions were using outdated API structure, accessing
.total, .page, .page_size directly on paginated responses instead of
through the .pagination object.
Fixed locations:
- test_mappers/test_ban_mappers.py: 3 assertions updated to use .pagination.*
- test_services/test_blocklist_service.py: 6 assertions updated
- test_services/test_history_service.py: 14 assertions updated
All paginated API endpoints now correctly return pagination metadata:
- GET /api/history
- GET /api/history/archive
- GET /api/dashboard/bans
- GET /api/jails/{name}/banned
- GET /api/blocklists/log
Verified with 24 passing pagination tests demonstrating correct behavior.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -625,9 +625,9 @@ class TestImportLogPagination:
|
||||
db, source_id=None, page=1, page_size=10
|
||||
)
|
||||
assert resp.items == []
|
||||
assert resp.total == 0
|
||||
assert resp.page == 1
|
||||
assert resp.page_size == 10
|
||||
assert resp.pagination.total == 0
|
||||
assert resp.pagination.page == 1
|
||||
assert resp.pagination.page_size == 10
|
||||
|
||||
async def test_list_import_logs_paginates(self, db: aiosqlite.Connection) -> None:
|
||||
"""list_import_logs computes total pages and returns the correct subset."""
|
||||
@@ -646,8 +646,8 @@ class TestImportLogPagination:
|
||||
resp = await blocklist_service.list_import_logs(
|
||||
db, source_id=None, page=2, page_size=2
|
||||
)
|
||||
assert resp.total == 3
|
||||
assert resp.page == 2
|
||||
assert resp.page_size == 2
|
||||
assert resp.pagination.total == 3
|
||||
assert resp.pagination.page == 2
|
||||
assert resp.pagination.page_size == 2
|
||||
assert len(resp.items) == 1
|
||||
assert resp.items[0].source_url == "https://example0.test/ips.txt"
|
||||
|
||||
Reference in New Issue
Block a user