add demo data for Swagger

This commit is contained in:
Meghdad committed 2026-07-23 07:40:44 +03:30
1 parent f6714f07cd
commit a353b80a15
4 files changed
+132 -2

No files matched your search

+23
View File
@@ -1,5 +1,6 @@
import httpx
from warehouse_allocation.api_examples import DEMO_SKU, DEMO_WAREHOUSE_IDS
from warehouse_allocation.infrastructure.inventory import InMemoryInventoryRepository
@@ -83,3 +84,25 @@ async def test_validation_error_is_structured(
assert response.status_code == 422
assert response.json()["detail"]
async def test_openapi_demo_example_is_runnable_and_non_reserving(
client: httpx.AsyncClient,
inventory: InMemoryInventoryRepository,
) -> None:
for warehouse_id in DEMO_WAREHOUSE_IDS:
await inventory.set_levels(warehouse_id, {DEMO_SKU: 10})
openapi = (await client.get("/openapi.json")).json()
media_type = openapi["paths"]["/v1/allocations"]["post"]["requestBody"]["content"][
"application/json"
]
example = media_type["examples"]["demoQuote"]["value"]
first = await client.post("/v1/allocations", json=example)
second = await client.post("/v1/allocations", json=example)
assert first.status_code == 200
assert second.status_code == 200
assert first.json()["inventoryReserved"] is False
assert first.json()["warehouseId"] in DEMO_WAREHOUSE_IDS