160 lines
4.7 KiB
Python
160 lines
4.7 KiB
Python
import uuid
|
|
|
|
|
|
def test_create_snapshot_minimal(client):
|
|
r = client.post("/skincare", json={"snapshot_date": "2026-02-26"})
|
|
assert r.status_code == 201
|
|
data = r.json()
|
|
assert "id" in data
|
|
assert data["snapshot_date"] == "2026-02-26"
|
|
assert data["overall_state"] is None
|
|
|
|
|
|
def test_create_snapshot_full(client):
|
|
r = client.post(
|
|
"/skincare",
|
|
json={
|
|
"snapshot_date": "2026-02-20",
|
|
"overall_state": "good",
|
|
"skin_type": "combination",
|
|
"texture": "rough",
|
|
"hydration_level": 3,
|
|
"sebum_tzone": 4,
|
|
"sebum_cheeks": 2,
|
|
"sensitivity_level": 2,
|
|
"barrier_state": "intact",
|
|
"active_concerns": ["acne", "redness"],
|
|
"risks": ["Over-exfoliation"],
|
|
"priorities": ["Maintain barrier"],
|
|
"notes": "Looking better this week",
|
|
},
|
|
)
|
|
assert r.status_code == 201
|
|
data = r.json()
|
|
assert data["overall_state"] == "good"
|
|
assert data["texture"] == "rough"
|
|
assert "acne" in data["active_concerns"]
|
|
assert data["hydration_level"] == 3
|
|
|
|
|
|
def test_create_snapshot_invalid_state(client):
|
|
r = client.post(
|
|
"/skincare",
|
|
json={"snapshot_date": "2026-02-26", "overall_state": "stellar"},
|
|
)
|
|
assert r.status_code == 422
|
|
|
|
|
|
def test_list_snapshots_empty(client):
|
|
r = client.get("/skincare")
|
|
assert r.status_code == 200
|
|
assert r.json() == []
|
|
|
|
|
|
def test_list_filter_date_range(client):
|
|
client.post("/skincare", json={"snapshot_date": "2026-01-01"})
|
|
client.post("/skincare", json={"snapshot_date": "2026-06-01"})
|
|
r = client.get("/skincare?from_date=2026-05-01&to_date=2026-12-31")
|
|
assert r.status_code == 200
|
|
data = r.json()
|
|
assert len(data) == 1
|
|
assert data[0]["snapshot_date"] == "2026-06-01"
|
|
|
|
|
|
def test_list_filter_overall_state(client):
|
|
client.post(
|
|
"/skincare",
|
|
json={"snapshot_date": "2026-02-10", "overall_state": "good"},
|
|
)
|
|
client.post(
|
|
"/skincare",
|
|
json={"snapshot_date": "2026-02-11", "overall_state": "poor"},
|
|
)
|
|
r = client.get("/skincare?overall_state=poor")
|
|
assert r.status_code == 200
|
|
data = r.json()
|
|
assert len(data) == 1
|
|
assert data[0]["overall_state"] == "poor"
|
|
|
|
|
|
def test_get_snapshot(client):
|
|
r = client.post("/skincare", json={"snapshot_date": "2026-02-26"})
|
|
sid = r.json()["id"]
|
|
r2 = client.get(f"/skincare/{sid}")
|
|
assert r2.status_code == 200
|
|
assert r2.json()["id"] == sid
|
|
|
|
|
|
def test_get_snapshot_not_found(client):
|
|
r = client.get(f"/skincare/{uuid.uuid4()}")
|
|
assert r.status_code == 404
|
|
|
|
|
|
def test_update_snapshot_state(client):
|
|
r = client.post("/skincare", json={"snapshot_date": "2026-02-26"})
|
|
sid = r.json()["id"]
|
|
r2 = client.patch(f"/skincare/{sid}", json={"overall_state": "excellent"})
|
|
assert r2.status_code == 200
|
|
assert r2.json()["overall_state"] == "excellent"
|
|
|
|
|
|
def test_update_snapshot_concerns(client):
|
|
r = client.post("/skincare", json={"snapshot_date": "2026-02-26"})
|
|
sid = r.json()["id"]
|
|
r2 = client.patch(
|
|
f"/skincare/{sid}",
|
|
json={"active_concerns": ["dehydration", "redness"]},
|
|
)
|
|
assert r2.status_code == 200
|
|
data = r2.json()
|
|
assert "dehydration" in data["active_concerns"]
|
|
assert "redness" in data["active_concerns"]
|
|
|
|
|
|
def test_update_snapshot_not_found(client):
|
|
r = client.patch(f"/skincare/{uuid.uuid4()}", json={"overall_state": "good"})
|
|
assert r.status_code == 404
|
|
|
|
|
|
def test_delete_snapshot(client):
|
|
r = client.post("/skincare", json={"snapshot_date": "2026-02-26"})
|
|
sid = r.json()["id"]
|
|
r2 = client.delete(f"/skincare/{sid}")
|
|
assert r2.status_code == 204
|
|
r3 = client.get(f"/skincare/{sid}")
|
|
assert r3.status_code == 404
|
|
|
|
|
|
def test_delete_snapshot_not_found(client):
|
|
r = client.delete(f"/skincare/{uuid.uuid4()}")
|
|
assert r.status_code == 404
|
|
|
|
|
|
def test_analyze_photos_includes_user_profile_context(client, monkeypatch):
|
|
from innercontext.api import skincare as skincare_api
|
|
|
|
captured: dict[str, object] = {}
|
|
|
|
class _FakeResponse:
|
|
text = "{}"
|
|
|
|
def _fake_call_gemini(**kwargs):
|
|
captured.update(kwargs)
|
|
return _FakeResponse()
|
|
|
|
monkeypatch.setattr(skincare_api, "call_gemini", _fake_call_gemini)
|
|
|
|
profile = client.patch(
|
|
"/profile", json={"birth_date": "1991-02-10", "sex_at_birth": "female"}
|
|
)
|
|
assert profile.status_code == 200
|
|
|
|
r = client.post(
|
|
"/skincare/analyze-photos",
|
|
files={"photos": ("face.jpg", b"fake-bytes", "image/jpeg")},
|
|
)
|
|
assert r.status_code == 200
|
|
|
|
parts = captured["contents"]
|
|
assert isinstance(parts, list)
|
|
assert any("USER PROFILE:" in str(part) for part in parts)
|