Plant registry, grow event calendar, and gardening knowledge base populated via cf-harvest ingest endpoint. All 23 tests passing. Stack: - FastAPI + SQLite (cf-core migrations) on port 8522 - Vue 3 + Vite + Pinia SPA on port 8521 - 5 SQL migrations: locations → plants → grow_events, knowledge_sources → knowledge_facts - Earthy green theme (--color-primary: #4a7c59) matching CF theme system Knowledge ingest contract: - POST /api/v1/knowledge/ingest — idempotent on fact_hash (sha256 of type+payload+video_path) - 8 fact types: companion_planting, soil_amendment, propagation, pest_diagnosis, harvest_timing, instruction, medicinal, history_context - Partial batch failure: malformed facts collected in rejected[], valid facts inserted - Re-ingesting same video batch: facts_skipped_duplicate > 0, no duplicates Wired views: RegistryView (plant CRUD), KnowledgeView (facts + type filter chips) Stub views: CalendarView, SettingsView
88 lines
3 KiB
Python
88 lines
3 KiB
Python
"""Plant registry CRUD tests — covers the full create/read/update/delete cycle."""
|
|
import pytest
|
|
|
|
|
|
def test_create_plant_minimal(client):
|
|
resp = client.post("/api/v1/plants", json={"common_name": "Tomato"})
|
|
assert resp.status_code == 201
|
|
data = resp.json()
|
|
assert data["common_name"] == "Tomato"
|
|
assert data["id"] is not None
|
|
assert data["variety"] is None
|
|
|
|
|
|
def test_create_plant_with_all_fields(client):
|
|
resp = client.post("/api/v1/plants", json={
|
|
"common_name": "Tomato",
|
|
"latin_binomial": "Solanum lycopersicum",
|
|
"variety": "Brandywine",
|
|
"planting_date": "2026-05-01",
|
|
"days_to_maturity": 85,
|
|
"notes": "Heirloom, beefsteak type",
|
|
})
|
|
assert resp.status_code == 201
|
|
data = resp.json()
|
|
assert data["latin_binomial"] == "Solanum lycopersicum"
|
|
assert data["variety"] == "Brandywine"
|
|
assert data["days_to_maturity"] == 85
|
|
|
|
|
|
def test_list_plants_empty(client):
|
|
resp = client.get("/api/v1/plants")
|
|
assert resp.status_code == 200
|
|
assert resp.json() == []
|
|
|
|
|
|
def test_list_plants_returns_created(client):
|
|
client.post("/api/v1/plants", json={"common_name": "Basil"})
|
|
client.post("/api/v1/plants", json={"common_name": "Rosemary"})
|
|
resp = client.get("/api/v1/plants")
|
|
assert resp.status_code == 200
|
|
names = {p["common_name"] for p in resp.json()}
|
|
assert "Basil" in names
|
|
assert "Rosemary" in names
|
|
|
|
|
|
def test_get_plant_by_id(client):
|
|
create_resp = client.post("/api/v1/plants", json={"common_name": "Courgette"})
|
|
plant_id = create_resp.json()["id"]
|
|
resp = client.get(f"/api/v1/plants/{plant_id}")
|
|
assert resp.status_code == 200
|
|
assert resp.json()["common_name"] == "Courgette"
|
|
|
|
|
|
def test_get_plant_not_found(client):
|
|
resp = client.get("/api/v1/plants/9999")
|
|
assert resp.status_code == 404
|
|
|
|
|
|
def test_update_plant_partial(client):
|
|
create_resp = client.post("/api/v1/plants", json={"common_name": "Pepper"})
|
|
plant_id = create_resp.json()["id"]
|
|
resp = client.patch(f"/api/v1/plants/{plant_id}", json={"variety": "Padron"})
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert data["common_name"] == "Pepper"
|
|
assert data["variety"] == "Padron"
|
|
|
|
|
|
def test_delete_plant(client):
|
|
create_resp = client.post("/api/v1/plants", json={"common_name": "Mint"})
|
|
plant_id = create_resp.json()["id"]
|
|
resp = client.delete(f"/api/v1/plants/{plant_id}")
|
|
assert resp.status_code == 204
|
|
assert client.get(f"/api/v1/plants/{plant_id}").status_code == 404
|
|
|
|
|
|
def test_plant_with_location(client):
|
|
loc = client.post("/api/v1/locations", json={"name": "Raised Bed 1"}).json()
|
|
resp = client.post("/api/v1/plants", json={
|
|
"common_name": "Carrot",
|
|
"location_id": loc["id"],
|
|
})
|
|
assert resp.status_code == 201
|
|
assert resp.json()["location_id"] == loc["id"]
|
|
|
|
filtered = client.get(f"/api/v1/plants?location_id={loc['id']}").json()
|
|
assert len(filtered) == 1
|
|
assert filtered[0]["common_name"] == "Carrot"
|