This commit is contained in:
jze9
2026-07-21 16:11:09 +05:00
commit 78862296c4
94 changed files with 6090 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
from httpx import AsyncClient
async def test_nested_box_restrict_delete_and_cycle_prevention(
client: AsyncClient, auth_headers: dict[str, str]
) -> None:
parent_res = await client.post("/api/v1/boxes", headers=auth_headers, json={"name": "Parent"})
parent_id = parent_res.json()["id"]
child_res = await client.post(
"/api/v1/boxes", headers=auth_headers, json={"name": "Child", "parent_box_id": parent_id}
)
child_id = child_res.json()["id"]
# Cannot delete a box that still has children.
delete_res = await client.delete(f"/api/v1/boxes/{parent_id}", headers=auth_headers)
assert delete_res.status_code == 409
# Cannot move a box into its own descendant.
cycle_res = await client.put(
f"/api/v1/boxes/{parent_id}", headers=auth_headers, json={"parent_box_id": child_id}
)
assert cycle_res.status_code == 409
box_detail = await client.get(f"/api/v1/boxes/{child_id}")
assert box_detail.json()["ancestors"] == [{"id": parent_id, "name": "Parent"}]
await client.delete(f"/api/v1/boxes/{child_id}", headers=auth_headers)
await client.delete(f"/api/v1/boxes/{parent_id}", headers=auth_headers)
async def test_deleting_box_unassigns_objects(client: AsyncClient, auth_headers: dict[str, str]) -> None:
box_res = await client.post("/api/v1/boxes", headers=auth_headers, json={"name": "Temp box"})
box_id = box_res.json()["id"]
obj_res = await client.post(
"/api/v1/objects",
headers=auth_headers,
json={"inventory_number": "BOX-TEST-1", "name": "In a box", "box_id": box_id},
)
object_id = obj_res.json()["id"]
assert obj_res.json()["box_id"] == box_id
await client.delete(f"/api/v1/boxes/{box_id}", headers=auth_headers)
obj_after = await client.get(f"/api/v1/objects/{object_id}")
assert obj_after.json()["box_id"] is None
await client.delete(f"/api/v1/objects/{object_id}", headers=auth_headers)