Skip to content

Commit

Permalink
Add tests with case of {id} in fastapi path (#1100)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantetemplar authored Jan 5, 2025
1 parent 687b4a7 commit 8892aac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/fastapi/routes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from fastapi import APIRouter, Body, status
from pydantic import BaseModel

Expand Down Expand Up @@ -28,6 +30,11 @@ async def create_window_2(window: WindowAPI):
return await window.save()


@house_router.get("/windows/{id}", response_model=Optional[WindowAPI])
async def get_window(id: PydanticObjectId):
return await WindowAPI.get(id)


@house_router.post("/houses/", response_model=HouseAPI)
async def create_house(window: WindowAPI):
house = HouseAPI(name="test_name", windows=[window])
Expand Down
16 changes: 16 additions & 0 deletions tests/fastapi/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ async def test_create_window(api_client):
assert resp_json["y"] == 20


async def test_get_window(api_client):
payload = {"x": 10, "y": 20}
data1 = (
(await api_client.post("/v1/windows/", json=payload))
.raise_for_status()
.json()
)
window_id = data1["_id"]
data2 = (
(await api_client.get(f"/v1/windows/{window_id}"))
.raise_for_status()
.json()
)
assert data2 == data1


async def test_create_house(api_client):
payload = {"x": 10, "y": 20}
resp = await api_client.post("/v1/houses/", json=payload)
Expand Down

0 comments on commit 8892aac

Please sign in to comment.