before gemiin
This commit is contained in:
26
backend/tests/test_media_aliases.py
Normal file
26
backend/tests/test_media_aliases.py
Normal file
@@ -0,0 +1,26 @@
|
||||
def test_create_media_normalizes_english_entity_type(client):
|
||||
r = client.post(
|
||||
"/api/media",
|
||||
json={
|
||||
"entity_type": "plant",
|
||||
"entity_id": 12,
|
||||
"url": "/uploads/test.webp",
|
||||
},
|
||||
)
|
||||
assert r.status_code == 201
|
||||
assert r.json()["entity_type"] == "plante"
|
||||
|
||||
|
||||
def test_list_media_accepts_alias_entity_type_filter(client):
|
||||
client.post(
|
||||
"/api/media",
|
||||
json={
|
||||
"entity_type": "plante",
|
||||
"entity_id": 99,
|
||||
"url": "/uploads/test2.webp",
|
||||
},
|
||||
)
|
||||
r = client.get("/api/media", params={"entity_type": "plant", "entity_id": 99})
|
||||
assert r.status_code == 200
|
||||
assert len(r.json()) == 1
|
||||
assert r.json()[0]["entity_type"] == "plante"
|
||||
@@ -12,6 +12,16 @@ 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_get_plant(client):
|
||||
r = client.post("/api/plants", json={"nom_commun": "Basilic"})
|
||||
id = r.json()["id"]
|
||||
|
||||
@@ -26,3 +26,13 @@ def test_update_task_statut(client):
|
||||
r2 = client.put(f"/api/tasks/{id}", json={"titre": "À faire", "statut": "fait"})
|
||||
assert r2.status_code == 200
|
||||
assert r2.json()["statut"] == "fait"
|
||||
|
||||
|
||||
def test_filter_tasks_by_planting_id(client):
|
||||
client.post("/api/tasks", json={"titre": "Template arrosage", "statut": "template"})
|
||||
client.post("/api/tasks", json={"titre": "Arroser rang 1", "statut": "a_faire", "planting_id": 10})
|
||||
client.post("/api/tasks", json={"titre": "Arroser rang 2", "statut": "a_faire", "planting_id": 11})
|
||||
r = client.get("/api/tasks?planting_id=10")
|
||||
assert r.status_code == 200
|
||||
assert len(r.json()) == 1
|
||||
assert r.json()[0]["planting_id"] == 10
|
||||
|
||||
@@ -28,3 +28,15 @@ def test_tool_with_video_url(client):
|
||||
)
|
||||
assert r.status_code == 201
|
||||
assert r.json()["video_url"] == "/uploads/demo-outil.mp4"
|
||||
|
||||
|
||||
def test_tool_with_notice_texte(client):
|
||||
r = client.post(
|
||||
"/api/tools",
|
||||
json={
|
||||
"nom": "Sécateur",
|
||||
"notice_texte": "Aiguiser la lame tous les 3 mois.",
|
||||
},
|
||||
)
|
||||
assert r.status_code == 201
|
||||
assert r.json()["notice_texte"] == "Aiguiser la lame tous les 3 mois."
|
||||
|
||||
Reference in New Issue
Block a user