feat(backend): CRUD variétés, plantations, tâches + tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-21 21:22:58 +01:00
parent aa379aa1b4
commit 4787f044e5
6 changed files with 256 additions and 6 deletions

View File

@@ -0,0 +1,25 @@
def test_create_planting(client):
g = client.post("/api/gardens", json={"nom": "Potager", "type": "plein_air"}).json()
v = client.post("/api/varieties", json={"nom_commun": "Tomate"}).json()
r = client.post("/api/plantings", json={
"garden_id": g["id"], "variety_id": v["id"], "quantite": 3
})
assert r.status_code == 201
assert r.json()["statut"] == "prevu"
def test_list_plantings(client):
g = client.post("/api/gardens", json={"nom": "Potager", "type": "plein_air"}).json()
v = client.post("/api/varieties", json={"nom_commun": "Tomate"}).json()
client.post("/api/plantings", json={"garden_id": g["id"], "variety_id": v["id"]})
r = client.get("/api/plantings")
assert r.status_code == 200
assert len(r.json()) >= 1
def test_add_planting_event(client):
g = client.post("/api/gardens", json={"nom": "Potager", "type": "plein_air"}).json()
v = client.post("/api/varieties", json={"nom_commun": "Tomate"}).json()
p = client.post("/api/plantings", json={"garden_id": g["id"], "variety_id": v["id"]}).json()
r = client.post(f"/api/plantings/{p['id']}/events", json={"type": "arrosage", "note": "Bien arrosé"})
assert r.status_code == 201

View File

@@ -0,0 +1,28 @@
def test_create_task(client):
r = client.post("/api/tasks", json={"titre": "Arroser les tomates", "priorite": "haute"})
assert r.status_code == 201
assert r.json()["statut"] == "a_faire"
def test_list_tasks(client):
client.post("/api/tasks", json={"titre": "Tâche 1"})
client.post("/api/tasks", json={"titre": "Tâche 2"})
r = client.get("/api/tasks")
assert r.status_code == 200
assert len(r.json()) == 2
def test_filter_tasks_by_statut(client):
client.post("/api/tasks", json={"titre": "À faire", "statut": "a_faire"})
client.post("/api/tasks", json={"titre": "Fait", "statut": "fait"})
r = client.get("/api/tasks?statut=a_faire")
assert r.status_code == 200
assert all(t["statut"] == "a_faire" for t in r.json())
def test_update_task_statut(client):
r = client.post("/api/tasks", json={"titre": "À faire"})
id = r.json()["id"]
r2 = client.put(f"/api/tasks/{id}", json={"titre": "À faire", "statut": "fait"})
assert r2.status_code == 200
assert r2.json()["statut"] == "fait"

View File

@@ -0,0 +1,26 @@
def test_create_variety(client):
r = client.post("/api/varieties", json={"nom_commun": "Tomate", "famille": "Solanacées"})
assert r.status_code == 201
assert r.json()["nom_commun"] == "Tomate"
def test_list_varieties(client):
client.post("/api/varieties", json={"nom_commun": "Tomate"})
client.post("/api/varieties", json={"nom_commun": "Courgette"})
r = client.get("/api/varieties")
assert r.status_code == 200
assert len(r.json()) == 2
def test_get_variety(client):
r = client.post("/api/varieties", json={"nom_commun": "Basilic"})
id = r.json()["id"]
r2 = client.get(f"/api/varieties/{id}")
assert r2.status_code == 200
def test_delete_variety(client):
r = client.post("/api/varieties", json={"nom_commun": "Test"})
id = r.json()["id"]
r2 = client.delete(f"/api/varieties/{id}")
assert r2.status_code == 204