diff --git a/backend/app/schemas/todos.py b/backend/app/schemas/todos.py index 138a7f3..6666bd9 100644 --- a/backend/app/schemas/todos.py +++ b/backend/app/schemas/todos.py @@ -1,6 +1,7 @@ import uuid from datetime import datetime -from pydantic import BaseModel, ConfigDict +from typing import Literal +from pydantic import BaseModel, ConfigDict, Field class TodoCreate(BaseModel): @@ -9,9 +10,9 @@ class TodoCreate(BaseModel): url: str | None = None domain: str | None = None category: str | None = None - tags: list[str] = [] - status: str = "pending" - priority: str = "medium" + tags: list[str] = Field(default_factory=list) + status: Literal["pending", "done", "cancelled"] = "pending" + priority: Literal["low", "medium", "high"] = "medium" due_date: datetime | None = None @@ -22,13 +23,13 @@ class TodoUpdate(BaseModel): domain: str | None = None category: str | None = None tags: list[str] | None = None - status: str | None = None - priority: str | None = None + status: Literal["pending", "done", "cancelled"] | None = None + priority: Literal["low", "medium", "high"] | None = None due_date: datetime | None = None class PostponeRequest(BaseModel): - days: int # 1 ou 7 + days: Literal[1, 7] class TodoResponse(BaseModel): diff --git a/backend/tests/test_todos.py b/backend/tests/test_todos.py index 177ffdf..83bf50d 100644 --- a/backend/tests/test_todos.py +++ b/backend/tests/test_todos.py @@ -47,8 +47,8 @@ async def test_lister_todos_filtre_domaine(client): async def test_mettre_a_jour_todo(client): - cr = await client.post("/api/todos/", json={"title": "TEST_avant"}) - item_id = cr.json()["id"] + create_resp = await client.post("/api/todos/", json={"title": "TEST_avant"}) + item_id = create_resp.json()["id"] resp = await client.patch(f"/api/todos/{item_id}", json={"title": "TEST_après", "status": "done"}) assert resp.status_code == 200 @@ -66,8 +66,8 @@ async def test_mettre_a_jour_todo_inexistant(client): async def test_supprimer_todo(client): - cr = await client.post("/api/todos/", json={"title": "TEST_à supprimer"}) - item_id = cr.json()["id"] + create_resp = await client.post("/api/todos/", json={"title": "TEST_à supprimer"}) + item_id = create_resp.json()["id"] resp = await client.delete(f"/api/todos/{item_id}") assert resp.status_code == 204 @@ -78,8 +78,8 @@ async def test_supprimer_todo(client): async def test_reporter_todo_1_jour(client): due = "2026-06-01T10:00:00+00:00" - cr = await client.post("/api/todos/", json={"title": "TEST_reporter", "due_date": due}) - item_id = cr.json()["id"] + create_resp = await client.post("/api/todos/", json={"title": "TEST_reporter", "due_date": due}) + item_id = create_resp.json()["id"] resp = await client.post(f"/api/todos/{item_id}/postpone", json={"days": 1}) assert resp.status_code == 200 @@ -90,8 +90,8 @@ async def test_reporter_todo_1_jour(client): async def test_reporter_todo_1_semaine(client): due = "2026-06-01T10:00:00+00:00" - cr = await client.post("/api/todos/", json={"title": "TEST_reporter7", "due_date": due}) - item_id = cr.json()["id"] + create_resp = await client.post("/api/todos/", json={"title": "TEST_reporter7", "due_date": due}) + item_id = create_resp.json()["id"] resp = await client.post(f"/api/todos/{item_id}/postpone", json={"days": 7}) assert resp.status_code == 200 @@ -101,8 +101,8 @@ async def test_reporter_todo_1_semaine(client): async def test_reporter_jours_invalides(client): - cr = await client.post("/api/todos/", json={"title": "TEST_invalide"}) - item_id = cr.json()["id"] + create_resp = await client.post("/api/todos/", json={"title": "TEST_invalide"}) + item_id = create_resp.json()["id"] resp = await client.post(f"/api/todos/{item_id}/postpone", json={"days": 3}) assert resp.status_code == 422