refactor: split table models into Base/Table/Public for proper FastAPI serialization
Add ProductBase, ProductPublic, ProductWithInventory and SkinConditionSnapshotBase, SkinConditionSnapshotPublic. Table models now inherit from their Base counterpart and override JSON fields with sa_column. All field_serializer hacks removed; FastAPI response models use the non-table Public classes so Pydantic coerces raw DB dicts → typed models cleanly. ProductCreate and SnapshotCreate now simply inherit their respective Base classes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
479be25112
commit
c09acc7c81
15 changed files with 225 additions and 198 deletions
|
|
@ -1,6 +1,5 @@
|
|||
import uuid
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Medications
|
||||
# ---------------------------------------------------------------------------
|
||||
|
|
@ -32,9 +31,7 @@ def test_list_filter_kind(client):
|
|||
client.post(
|
||||
"/health/medications", json={"kind": "prescription", "product_name": "A"}
|
||||
)
|
||||
client.post(
|
||||
"/health/medications", json={"kind": "supplement", "product_name": "B"}
|
||||
)
|
||||
client.post("/health/medications", json={"kind": "supplement", "product_name": "B"})
|
||||
r = client.get("/health/medications?kind=supplement")
|
||||
assert r.status_code == 200
|
||||
data = r.json()
|
||||
|
|
@ -46,9 +43,7 @@ def test_list_filter_product_name(client):
|
|||
client.post(
|
||||
"/health/medications", json={"kind": "otc", "product_name": "Epiduo Forte"}
|
||||
)
|
||||
client.post(
|
||||
"/health/medications", json={"kind": "otc", "product_name": "Panoxyl"}
|
||||
)
|
||||
client.post("/health/medications", json={"kind": "otc", "product_name": "Panoxyl"})
|
||||
r = client.get("/health/medications?product_name=epid")
|
||||
assert r.status_code == 200
|
||||
data = r.json()
|
||||
|
|
@ -113,7 +108,11 @@ def test_create_usage(client, created_medication):
|
|||
mid = created_medication["record_id"]
|
||||
r = client.post(
|
||||
f"/health/medications/{mid}/usages",
|
||||
json={"valid_from": "2026-01-01T08:00:00", "dose_value": 1.0, "dose_unit": "pea"},
|
||||
json={
|
||||
"valid_from": "2026-01-01T08:00:00",
|
||||
"dose_value": 1.0,
|
||||
"dose_unit": "pea",
|
||||
},
|
||||
)
|
||||
assert r.status_code == 201
|
||||
data = r.json()
|
||||
|
|
@ -156,7 +155,9 @@ def test_update_usage(client, created_medication):
|
|||
)
|
||||
uid = r.json()["record_id"]
|
||||
|
||||
r2 = client.patch(f"/health/usages/{uid}", json={"dose_value": 2.5, "dose_unit": "mg"})
|
||||
r2 = client.patch(
|
||||
f"/health/usages/{uid}", json={"dose_value": 2.5, "dose_unit": "mg"}
|
||||
)
|
||||
assert r2.status_code == 200
|
||||
assert r2.json()["dose_value"] == 2.5
|
||||
assert r2.json()["dose_unit"] == "mg"
|
||||
|
|
@ -247,8 +248,14 @@ def test_list_filter_flag(client):
|
|||
|
||||
|
||||
def test_list_filter_date_range(client):
|
||||
client.post("/health/lab-results", json={**LAB_RESULT_DATA, "collected_at": "2026-01-01T00:00:00"})
|
||||
client.post("/health/lab-results", json={**LAB_RESULT_DATA, "collected_at": "2026-06-01T00:00:00"})
|
||||
client.post(
|
||||
"/health/lab-results",
|
||||
json={**LAB_RESULT_DATA, "collected_at": "2026-01-01T00:00:00"},
|
||||
)
|
||||
client.post(
|
||||
"/health/lab-results",
|
||||
json={**LAB_RESULT_DATA, "collected_at": "2026-06-01T00:00:00"},
|
||||
)
|
||||
r = client.get("/health/lab-results?from_date=2026-05-01T00:00:00")
|
||||
assert r.status_code == 200
|
||||
data = r.json()
|
||||
|
|
@ -271,7 +278,9 @@ def test_get_lab_result_not_found(client):
|
|||
def test_update_lab_result(client):
|
||||
r = client.post("/health/lab-results", json=LAB_RESULT_DATA)
|
||||
rid = r.json()["record_id"]
|
||||
r2 = client.patch(f"/health/lab-results/{rid}", json={"notes": "Recheck in 3 months"})
|
||||
r2 = client.patch(
|
||||
f"/health/lab-results/{rid}", json={"notes": "Recheck in 3 months"}
|
||||
)
|
||||
assert r2.status_code == 200
|
||||
assert r2.json()["notes"] == "Recheck in 3 months"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue