]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
:white_check_mark: Add test for templates in include_router path (#349)
authorSebastián Ramírez <tiangolo@gmail.com>
Fri, 28 Jun 2019 18:15:17 +0000 (20:15 +0200)
committerGitHub <noreply@github.com>
Fri, 28 Jun 2019 18:15:17 +0000 (20:15 +0200)
tests/test_router_prefix_with_template.py [new file with mode: 0644]

diff --git a/tests/test_router_prefix_with_template.py b/tests/test_router_prefix_with_template.py
new file mode 100644 (file)
index 0000000..febd664
--- /dev/null
@@ -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"}