fix(plantes): test plant_variety + seed PlantVariety + formatPlantLabel + migrate.py nettoyage
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -15,12 +15,6 @@ EXPECTED_COLUMNS: dict[str, list[tuple[str, str, str | None]]] = {
|
||||
("url_reference", "TEXT", None),
|
||||
("associations_favorables", "TEXT", None), # JSON list[str]
|
||||
("associations_defavorables", "TEXT", None), # JSON list[str]
|
||||
("boutique_nom", "TEXT", None),
|
||||
("boutique_url", "TEXT", None),
|
||||
("prix_achat", "REAL", None),
|
||||
("date_achat", "TEXT", None),
|
||||
("poids", "TEXT", None),
|
||||
("dluo", "TEXT", None),
|
||||
("temp_germination", "TEXT", None),
|
||||
("temps_levee_j", "TEXT", None),
|
||||
],
|
||||
|
||||
@@ -6,7 +6,7 @@ import app.models # noqa
|
||||
|
||||
def run_seed():
|
||||
from app.models.garden import Garden, GardenCell, Measurement
|
||||
from app.models.plant import Plant
|
||||
from app.models.plant import Plant, PlantVariety
|
||||
from app.models.planting import Planting, PlantingEvent
|
||||
from app.models.task import Task
|
||||
from app.models.tool import Tool
|
||||
@@ -131,11 +131,24 @@ def run_seed():
|
||||
|
||||
plantes = []
|
||||
for data in plantes_data:
|
||||
variete = data.pop('variete', None)
|
||||
p = Plant(**data)
|
||||
session.add(p)
|
||||
plantes.append(p)
|
||||
session.flush()
|
||||
|
||||
# Créer les variétés pour les plantes qui en avaient une
|
||||
plantes_varietes = [
|
||||
("Andine Cornue", 0), # Tomate
|
||||
("Verte", 1), # Courgette
|
||||
("Batavia", 3), # Laitue
|
||||
("Nain", 6), # Haricot
|
||||
("Mange-tout", 7), # Pois
|
||||
("Milan", 15), # Chou
|
||||
]
|
||||
for variete_nom, idx in plantes_varietes:
|
||||
session.add(PlantVariety(plant_id=plantes[idx].id, variete=variete_nom))
|
||||
|
||||
tomate = plantes[0]
|
||||
courgette = plantes[1]
|
||||
|
||||
|
||||
@@ -12,14 +12,30 @@ def test_list_plants(client):
|
||||
assert len(r.json()) == 2
|
||||
|
||||
|
||||
def test_allow_same_common_name_with_different_varieties(client):
|
||||
client.post("/api/plants", json={"nom_commun": "Tomate", "variete": "Roma"})
|
||||
client.post("/api/plants", json={"nom_commun": "Tomate", "variete": "Andine Cornue"})
|
||||
r = client.get("/api/plants")
|
||||
assert r.status_code == 200
|
||||
tomates = [p for p in r.json() if p["nom_commun"] == "Tomate"]
|
||||
assert len(tomates) == 2
|
||||
assert {p.get("variete") for p in tomates} == {"Roma", "Andine Cornue"}
|
||||
def test_plant_variety_crud(client):
|
||||
# Créer une plante
|
||||
r = client.post("/api/plants", json={"nom_commun": "Tomate"})
|
||||
assert r.status_code == 201
|
||||
plant_id = r.json()["id"]
|
||||
|
||||
# Créer deux variétés
|
||||
r1 = client.post(f"/api/plants/{plant_id}/varieties", json={"variete": "Roma"})
|
||||
assert r1.status_code == 201
|
||||
vid1 = r1.json()["id"]
|
||||
|
||||
r2 = client.post(f"/api/plants/{plant_id}/varieties", json={"variete": "Andine Cornue"})
|
||||
assert r2.status_code == 201
|
||||
|
||||
# GET /plants/{id} doit retourner les 2 variétés
|
||||
r = client.get(f"/api/plants/{plant_id}")
|
||||
varieties = r.json().get("varieties", [])
|
||||
assert len(varieties) == 2
|
||||
assert {v["variete"] for v in varieties} == {"Roma", "Andine Cornue"}
|
||||
|
||||
# Supprimer une variété
|
||||
client.delete(f"/api/plants/{plant_id}/varieties/{vid1}")
|
||||
r = client.get(f"/api/plants/{plant_id}")
|
||||
assert len(r.json()["varieties"]) == 1
|
||||
|
||||
|
||||
def test_get_plant(client):
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
export function formatPlantLabel(plant) {
|
||||
if (plant.variete && plant.variete.trim()) {
|
||||
return `${plant.nom_commun} — ${plant.variete.trim()}`;
|
||||
const variete = plant.variete ?? plant.varieties?.[0]?.variete;
|
||||
if (variete && variete.trim()) {
|
||||
return `${plant.nom_commun} — ${variete.trim()}`;
|
||||
}
|
||||
return plant.nom_commun;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
export interface PlantVarietyData {
|
||||
variete?: string | null
|
||||
}
|
||||
|
||||
export interface PlantLabelData {
|
||||
id?: number
|
||||
nom_commun: string
|
||||
variete?: string | null
|
||||
varieties?: PlantVarietyData[] | null
|
||||
}
|
||||
|
||||
export function formatPlantLabel(plant: PlantLabelData): string {
|
||||
if (plant.variete && plant.variete.trim()) {
|
||||
return `${plant.nom_commun} — ${plant.variete.trim()}`
|
||||
const variete = plant.variete ?? plant.varieties?.[0]?.variete
|
||||
if (variete && variete.trim()) {
|
||||
return `${plant.nom_commun} — ${variete.trim()}`
|
||||
}
|
||||
return plant.nom_commun
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user