fix(todos): Literal types pour status/priority/days, Field default_factory pour tags
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import uuid
|
import uuid
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pydantic import BaseModel, ConfigDict
|
from typing import Literal
|
||||||
|
from pydantic import BaseModel, ConfigDict, Field
|
||||||
|
|
||||||
|
|
||||||
class TodoCreate(BaseModel):
|
class TodoCreate(BaseModel):
|
||||||
@@ -9,9 +10,9 @@ class TodoCreate(BaseModel):
|
|||||||
url: str | None = None
|
url: str | None = None
|
||||||
domain: str | None = None
|
domain: str | None = None
|
||||||
category: str | None = None
|
category: str | None = None
|
||||||
tags: list[str] = []
|
tags: list[str] = Field(default_factory=list)
|
||||||
status: str = "pending"
|
status: Literal["pending", "done", "cancelled"] = "pending"
|
||||||
priority: str = "medium"
|
priority: Literal["low", "medium", "high"] = "medium"
|
||||||
due_date: datetime | None = None
|
due_date: datetime | None = None
|
||||||
|
|
||||||
|
|
||||||
@@ -22,13 +23,13 @@ class TodoUpdate(BaseModel):
|
|||||||
domain: str | None = None
|
domain: str | None = None
|
||||||
category: str | None = None
|
category: str | None = None
|
||||||
tags: list[str] | None = None
|
tags: list[str] | None = None
|
||||||
status: str | None = None
|
status: Literal["pending", "done", "cancelled"] | None = None
|
||||||
priority: str | None = None
|
priority: Literal["low", "medium", "high"] | None = None
|
||||||
due_date: datetime | None = None
|
due_date: datetime | None = None
|
||||||
|
|
||||||
|
|
||||||
class PostponeRequest(BaseModel):
|
class PostponeRequest(BaseModel):
|
||||||
days: int # 1 ou 7
|
days: Literal[1, 7]
|
||||||
|
|
||||||
|
|
||||||
class TodoResponse(BaseModel):
|
class TodoResponse(BaseModel):
|
||||||
|
|||||||
+10
-10
@@ -47,8 +47,8 @@ async def test_lister_todos_filtre_domaine(client):
|
|||||||
|
|
||||||
|
|
||||||
async def test_mettre_a_jour_todo(client):
|
async def test_mettre_a_jour_todo(client):
|
||||||
cr = await client.post("/api/todos/", json={"title": "TEST_avant"})
|
create_resp = await client.post("/api/todos/", json={"title": "TEST_avant"})
|
||||||
item_id = cr.json()["id"]
|
item_id = create_resp.json()["id"]
|
||||||
|
|
||||||
resp = await client.patch(f"/api/todos/{item_id}", json={"title": "TEST_après", "status": "done"})
|
resp = await client.patch(f"/api/todos/{item_id}", json={"title": "TEST_après", "status": "done"})
|
||||||
assert resp.status_code == 200
|
assert resp.status_code == 200
|
||||||
@@ -66,8 +66,8 @@ async def test_mettre_a_jour_todo_inexistant(client):
|
|||||||
|
|
||||||
|
|
||||||
async def test_supprimer_todo(client):
|
async def test_supprimer_todo(client):
|
||||||
cr = await client.post("/api/todos/", json={"title": "TEST_à supprimer"})
|
create_resp = await client.post("/api/todos/", json={"title": "TEST_à supprimer"})
|
||||||
item_id = cr.json()["id"]
|
item_id = create_resp.json()["id"]
|
||||||
|
|
||||||
resp = await client.delete(f"/api/todos/{item_id}")
|
resp = await client.delete(f"/api/todos/{item_id}")
|
||||||
assert resp.status_code == 204
|
assert resp.status_code == 204
|
||||||
@@ -78,8 +78,8 @@ async def test_supprimer_todo(client):
|
|||||||
|
|
||||||
async def test_reporter_todo_1_jour(client):
|
async def test_reporter_todo_1_jour(client):
|
||||||
due = "2026-06-01T10:00:00+00:00"
|
due = "2026-06-01T10:00:00+00:00"
|
||||||
cr = await client.post("/api/todos/", json={"title": "TEST_reporter", "due_date": due})
|
create_resp = await client.post("/api/todos/", json={"title": "TEST_reporter", "due_date": due})
|
||||||
item_id = cr.json()["id"]
|
item_id = create_resp.json()["id"]
|
||||||
|
|
||||||
resp = await client.post(f"/api/todos/{item_id}/postpone", json={"days": 1})
|
resp = await client.post(f"/api/todos/{item_id}/postpone", json={"days": 1})
|
||||||
assert resp.status_code == 200
|
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):
|
async def test_reporter_todo_1_semaine(client):
|
||||||
due = "2026-06-01T10:00:00+00:00"
|
due = "2026-06-01T10:00:00+00:00"
|
||||||
cr = await client.post("/api/todos/", json={"title": "TEST_reporter7", "due_date": due})
|
create_resp = await client.post("/api/todos/", json={"title": "TEST_reporter7", "due_date": due})
|
||||||
item_id = cr.json()["id"]
|
item_id = create_resp.json()["id"]
|
||||||
|
|
||||||
resp = await client.post(f"/api/todos/{item_id}/postpone", json={"days": 7})
|
resp = await client.post(f"/api/todos/{item_id}/postpone", json={"days": 7})
|
||||||
assert resp.status_code == 200
|
assert resp.status_code == 200
|
||||||
@@ -101,8 +101,8 @@ async def test_reporter_todo_1_semaine(client):
|
|||||||
|
|
||||||
|
|
||||||
async def test_reporter_jours_invalides(client):
|
async def test_reporter_jours_invalides(client):
|
||||||
cr = await client.post("/api/todos/", json={"title": "TEST_invalide"})
|
create_resp = await client.post("/api/todos/", json={"title": "TEST_invalide"})
|
||||||
item_id = cr.json()["id"]
|
item_id = create_resp.json()["id"]
|
||||||
|
|
||||||
resp = await client.post(f"/api/todos/{item_id}/postpone", json={"days": 3})
|
resp = await client.post(f"/api/todos/{item_id}/postpone", json={"days": 3})
|
||||||
assert resp.status_code == 422
|
assert resp.status_code == 422
|
||||||
|
|||||||
Reference in New Issue
Block a user