From 02d2fc91828a7ef90273f01cb66cd6a6b35c538e Mon Sep 17 00:00:00 2001 From: venkatasaikumarguntupalli Date: Tue, 17 Mar 2026 16:11:32 -0700 Subject: [PATCH] Added test file (test_tutorial006.py for tutorial006.py. --- .../test_path_params/test_tutorial006.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/test_tutorial/test_path_params/test_tutorial006.py diff --git a/tests/test_tutorial/test_path_params/test_tutorial006.py b/tests/test_tutorial/test_path_params/test_tutorial006.py new file mode 100644 index 0000000000..7bee367558 --- /dev/null +++ b/tests/test_tutorial/test_path_params/test_tutorial006.py @@ -0,0 +1,31 @@ +from fastapi import FastAPI, Path +from fastapi.testclient import TestClient + +app = FastAPI() + +@app.get("/items/{item_id}") +def read_item(item_id: int = Path(..., ge=1, le=1000)): + return {"item_id": item_id} + +client = TestClient(app) + + +def test_valid_item_id(): + response = client.get("/items/100") + assert response.status_code == 200 + assert response.json() == {"item_id": 100} + + +def test_item_id_below_range(): + response = client.get("/items/0") + assert response.status_code == 422 # validation error + + +def test_item_id_above_range(): + response = client.get("/items/1001") + assert response.status_code == 422 # validation error + + +def test_invalid_type(): + response = client.get("/items/abc") + assert response.status_code == 422 # type validation error \ No newline at end of file