Lesson 6 of 8 · 2 min
Tests
# run locally: pytest
from fastapi.testclient import TestClient
from app.main import app, LIMIT
def test_answers_then_limits():
client = TestClient(app)
assert client.post("/predict", json={"text": "hi"}).json()["answer"] == "HI"
codes = [client.post("/predict", json={"text": "hi"}).status_code for _ in range(LIMIT)]
assert codes[-1] == 429
def test_rejects_empty():
assert TestClient(app).post("/predict", json={"text": ""}).status_code == 422