53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
def test_create_plant(client):
|
|
r = client.post("/api/plants", json={"nom_commun": "Tomate", "famille": "Solanacées"})
|
|
assert r.status_code == 201
|
|
assert r.json()["nom_commun"] == "Tomate"
|
|
|
|
|
|
def test_list_plants(client):
|
|
client.post("/api/plants", json={"nom_commun": "Tomate"})
|
|
client.post("/api/plants", json={"nom_commun": "Courgette"})
|
|
r = client.get("/api/plants")
|
|
assert r.status_code == 200
|
|
assert len(r.json()) == 2
|
|
|
|
|
|
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):
|
|
r = client.post("/api/plants", json={"nom_commun": "Basilic"})
|
|
id = r.json()["id"]
|
|
r2 = client.get(f"/api/plants/{id}")
|
|
assert r2.status_code == 200
|
|
|
|
|
|
def test_delete_plant(client):
|
|
r = client.post("/api/plants", json={"nom_commun": "Test"})
|
|
id = r.json()["id"]
|
|
r2 = client.delete(f"/api/plants/{id}")
|
|
assert r2.status_code == 204
|