From: Sebastián Ramírez Date: Fri, 28 Jun 2019 18:15:17 +0000 (+0200) Subject: :white_check_mark: Add test for templates in include_router path (#349) X-Git-Tag: 0.32.0~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=62df41780706161c4e25f854de0b6cc5d2664a39;p=thirdparty%2Ffastapi%2Ffastapi.git :white_check_mark: Add test for templates in include_router path (#349) --- diff --git a/tests/test_router_prefix_with_template.py b/tests/test_router_prefix_with_template.py new file mode 100644 index 0000000000..febd664c2b --- /dev/null +++ b/tests/test_router_prefix_with_template.py @@ -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"}