/
deniss_shu
/
SE_FastAPI_Example
Обзор
Документация
Войти
/
deniss_shu
/
SE_FastAPI_Example
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
tests/test_main.py
37 строк
1 KB
SlavikPuz
fix: use TestClient as context manager to trigger lifespan
#2
16 май 2026, 20:28
Верифицирован
16 май 2026, 20:28
5dc292c
Код
Авторство
О чём код?
from fastapi.testclient import TestClient from main import app def test_root(): with TestClient(app) as client: response = client.get("/") assert response.status_code == 200 def test_predict_positive(): with TestClient(app) as client: response = client.post("/predict/", json={"text": "I love this product!"}) assert response.status_code == 200 result = response.json() assert result[0]["label"] == "POSITIVE" assert result[0]["score"] > 0.5 def test_predict_negative(): with TestClient(app) as client: response = client.post("/predict/", json={"text": "This is terrible!"}) assert response.status_code == 200 result = response.json() assert result[0]["label"] == "NEGATIVE" def test_predict_empty_text(): with TestClient(app) as client: response = client.post("/predict/", json={"text": " "}) assert response.status_code == 400 def test_get_params(): with TestClient(app) as client: response = client.get("/I love FastAPI") assert response.status_code == 200