Adding ability to update / patch by sku, adding uniqueness constraint violation checks

This commit is contained in:
Ian Roddis committed 2026-09-21 10:43:36 -03:00
1 parent af5343da0c
commit d8db87c13e
13 files changed
+541 -13

No files matched your search

+80
View File
@@ -210,6 +210,86 @@ async def test_patch_can_unarchive_an_augmented_part(
assert ap_id in [p["id"] for p in default_list.json()]
@pytest.mark.asyncio
async def test_patch_and_delete_accept_sku_as_identifier(
client, seeded, make_user, db_sessionmaker
):
async with db_sessionmaker() as db:
manufacturer, colour, part_type = await _seed_reference_data(db)
ap = AugmentedPart(
description="Sku addressed part",
sku="SKU-123",
colour_id=colour.id,
manufacturer_id=manufacturer.id,
part_type_id=part_type.id,
)
db.add(ap)
await db.commit()
ap_id = ap.id
await make_user("root3@example.com", is_superuser=True)
headers = {"Authorization": f"Bearer {await _token(client, 'root3@example.com')}"}
resp = await client.patch(
"/api/augmented-parts/SKU-123",
json={"description": "Renamed via sku"},
headers=headers,
)
assert resp.status_code == 200
assert resp.json()["id"] == ap_id
assert resp.json()["description"] == "Renamed via sku"
resp = await client.delete("/api/augmented-parts/SKU-123", headers=headers)
assert resp.status_code == 204
assert (
await client.get(f"/api/augmented-parts/{ap_id}", headers=headers)
).status_code == 404
@pytest.mark.asyncio
async def test_delete_by_id_still_works(client, seeded, make_user, db_sessionmaker):
async with db_sessionmaker() as db:
manufacturer, colour, part_type = await _seed_reference_data(db)
ap = AugmentedPart(
description="Delete me by id",
colour_id=colour.id,
manufacturer_id=manufacturer.id,
part_type_id=part_type.id,
)
db.add(ap)
await db.commit()
ap_id = ap.id
await make_user("root4@example.com", is_superuser=True)
headers = {"Authorization": f"Bearer {await _token(client, 'root4@example.com')}"}
resp = await client.delete(f"/api/augmented-parts/{ap_id}", headers=headers)
assert resp.status_code == 204
assert (
await client.get(f"/api/augmented-parts/{ap_id}", headers=headers)
).status_code == 404
@pytest.mark.asyncio
async def test_update_and_delete_by_unknown_sku_404s(
client, seeded, make_user, db_sessionmaker
):
await make_user("root5@example.com", is_superuser=True)
headers = {"Authorization": f"Bearer {await _token(client, 'root5@example.com')}"}
resp = await client.patch(
"/api/augmented-parts/NO-SUCH-SKU",
json={"description": "won't happen"},
headers=headers,
)
assert resp.status_code == 404
resp = await client.delete("/api/augmented-parts/NO-SUCH-SKU", headers=headers)
assert resp.status_code == 404
async def _web_login(client, email, password="secret123"):
resp = await client.post("/login", data={"email": email, "password": password})
assert resp.status_code == 303