把 Week 3-4 所有知识整合成一个完整的 Todo API。
from fastapi.testclient import TestClient
from main import app
client = TestClient(app)
def test_register():
resp = client.post("/register", json={
"name": "test", "email": "test@test.com", "password": "123456"
})
assert resp.status_code == 200
def test_login():
resp = client.post("/login", json={
"email": "test@test.com", "password": "123456"
})
assert "access_token" in resp.json()
def test_create_todo():
# 先登录拿 token
# 再创建任务
# pytest 运行测试
docker compose up --build
# 一键启动