fix(api): wrap pre-paginated list responses
This commit is contained in:
@@ -4,7 +4,7 @@ from pathlib import Path
|
||||
from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
from fastapi import FastAPI
|
||||
from fastapi import APIRouter, FastAPI, Query
|
||||
from fastapi.routing import APIRoute
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
@@ -254,3 +254,31 @@ def test_rest_runtime_consumes_injected_project_context(monkeypatch) -> None:
|
||||
assert response.json()["items"] == [
|
||||
{"scheme_name": "burst_case", "scheme_type": "burst_analysis"}
|
||||
]
|
||||
|
||||
|
||||
def test_rest_runtime_wraps_handler_paginated_list() -> None:
|
||||
source_router = APIRouter()
|
||||
|
||||
@source_router.get("/records", response_model=list[int])
|
||||
async def list_records(
|
||||
skip: int = Query(0, ge=0),
|
||||
limit: int = Query(2, ge=1, le=10),
|
||||
) -> list[int]:
|
||||
records = [10, 20, 30, 40]
|
||||
return records[skip : skip + limit]
|
||||
|
||||
app = FastAPI(redirect_slashes=False)
|
||||
app.include_router(build_rest_router(source_router.routes), prefix="/api/v1")
|
||||
|
||||
response = TestClient(app, raise_server_exceptions=False).get(
|
||||
"/api/v1/records",
|
||||
params={"skip": 1, "limit": 2},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {
|
||||
"items": [20, 30],
|
||||
"total": 3,
|
||||
"limit": 2,
|
||||
"offset": 1,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user