mirror of https://github.com/tiangolo/fastapi.git
✅ Add test for templates in include_router path (#349)
This commit is contained in:
parent
09d2747a70
commit
62df417807
|
|
@ -0,0 +1,23 @@
|
||||||
|
from fastapi import APIRouter, FastAPI
|
||||||
|
from starlette.testclient import TestClient
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/users/{id}")
|
||||||
|
def read_user(segment: str, id: str):
|
||||||
|
return {"segment": segment, "id": id}
|
||||||
|
|
||||||
|
|
||||||
|
app.include_router(router, prefix="/{segment}")
|
||||||
|
|
||||||
|
|
||||||
|
client = TestClient(app)
|
||||||
|
|
||||||
|
|
||||||
|
def test_get():
|
||||||
|
response = client.get("/seg/users/foo")
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json() == {"segment": "seg", "id": "foo"}
|
||||||
Loading…
Reference in New Issue