fix(api): encode untyped datetime responses
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
from uuid import uuid4
|
||||
|
||||
@@ -281,3 +282,35 @@ def test_rest_runtime_wraps_handler_paginated_list() -> None:
|
||||
"limit": 2,
|
||||
"offset": 1,
|
||||
}
|
||||
|
||||
|
||||
def test_rest_runtime_json_encodes_untyped_datetime_response() -> None:
|
||||
source_router = APIRouter()
|
||||
|
||||
@source_router.get("/simulation-result")
|
||||
async def simulation_result():
|
||||
return {
|
||||
"result": [
|
||||
{
|
||||
"time": datetime(2026, 7, 30, 4, tzinfo=timezone.utc),
|
||||
"id": "4277",
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
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/simulation-result"
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {
|
||||
"result": [
|
||||
{
|
||||
"time": "2026-07-30T04:00:00+00:00",
|
||||
"id": "4277",
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user