tests/test_callable_endpoint.py
raw| 1 | from functools import partial |
| 2 | |
| 3 | from fastapi import FastAPI |
| 4 | from fastapi.testclient import TestClient |
| 5 | |
| 6 | |
| 7 | def main(some_arg, q: str | None = None): |
| 8 | return {"some_arg": some_arg, "q": q} |
| 9 | |
| 10 | |
| 11 | endpoint = partial(main, "foo") |
| 12 | |
| 13 | app = FastAPI() |
| 14 | |
| 15 | app.get("/")(endpoint) |
| 16 | |
| 17 | |
| 18 | client = TestClient(app) |
| 19 | |
| 20 | |
| 21 | def test_partial(): |
| 22 | response = client.get("/?q=bar") |
| 23 | data = response.json() |
| 24 | assert data == {"some_arg": "foo", "q": "bar"} |