/
Frogog
/
SE_FastAPI_Example
Обзор
Документация
Войти
/
Frogog
/
SE_FastAPI_Example
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
test_main.py
50 строк
1 KB
BremeCanell
Fix flake8 linting errors and code style issues
15 май 2026, 12:42
15 май 2026, 12:42
f0942d4
Код
Авторство
О чём код?
from fastapi.testclient import TestClient from main import app client = TestClient(app) def test_root_endpoint(): response = client.get("/") assert response.status_code == 200 response_data = response.json() if isinstance(response_data, dict): assert any("FastApi service started" in str(v) for v in response_data.values()) elif isinstance(response_data, str): assert "FastApi service started" in response_data else: assert any("FastApi service started" in str(item) for item in response_data) def test_get_prediction(): test_text = "I love this product!" response = client.get(f"/{test_text}") assert response.status_code == 200 assert isinstance(response.json(), list) or isinstance(response.json(), dict) def test_post_prediction(): test_data = {"text": "This is amazing!"} response = client.post("/predict/", json=test_data) assert response.status_code == 200 assert response.json() is not None def test_post_batch_prediction(): test_data = {"texts": ["Good movie", "Bad plot"]} response = client.post("/predict_multiple/", json=test_data) assert response.status_code == 200 assert "results" in response.json() def test_invalid_text(): test_data = {"text": ""} response = client.post("/predict/", json=test_data) assert response.status_code == 422 def test_text_too_long(): test_data = {"text": "a" * 1001} response = client.post("/predict/", json=test_data) assert response.status_code == 422