innercontext/backend/tests/test_inventory.py
Piotr Oleszczyk d91d06455b feat(products): improve replenishment-aware shopping suggestions
Replace product weight and repurchase intent fields with per-package remaining levels and inventory-first restock signals. Enrich shopping suggestions with usage-aware replenishment scoring so the frontend and LLM can prioritize real gaps and near-empty staples more reliably.
2026-03-09 13:37:40 +01:00

59 lines
1.6 KiB
Python

import uuid
def test_get_inventory_by_id(client, created_product):
pid = created_product["id"]
r = client.post(f"/products/{pid}/inventory", json={"is_opened": False})
assert r.status_code == 201
inv_id = r.json()["id"]
r2 = client.get(f"/inventory/{inv_id}")
assert r2.status_code == 200
assert r2.json()["id"] == inv_id
def test_get_inventory_not_found(client):
r = client.get(f"/inventory/{uuid.uuid4()}")
assert r.status_code == 404
def test_update_inventory_opened(client, created_product):
pid = created_product["id"]
r = client.post(f"/products/{pid}/inventory", json={"is_opened": False})
inv_id = r.json()["id"]
r2 = client.patch(
f"/inventory/{inv_id}",
json={
"is_opened": True,
"opened_at": "2026-01-15",
"remaining_level": "low",
},
)
assert r2.status_code == 200
data = r2.json()
assert data["is_opened"] is True
assert data["opened_at"] == "2026-01-15"
assert data["remaining_level"] == "low"
def test_update_inventory_not_found(client):
r = client.patch(f"/inventory/{uuid.uuid4()}", json={"is_opened": True})
assert r.status_code == 404
def test_delete_inventory(client, created_product):
pid = created_product["id"]
r = client.post(f"/products/{pid}/inventory", json={})
inv_id = r.json()["id"]
r2 = client.delete(f"/inventory/{inv_id}")
assert r2.status_code == 204
r3 = client.get(f"/inventory/{inv_id}")
assert r3.status_code == 404
def test_delete_inventory_not_found(client):
r = client.delete(f"/inventory/{uuid.uuid4()}")
assert r.status_code == 404