/
Soldier327
/
LLM_AI
Обзор
Документация
Войти
/
Soldier327
/
LLM_AI
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
tests/test_api.py
53 строки
1 KB
Soldier-327
Initial commit
24 май 2026, 17:24
24 май 2026, 17:24
dae6bc3
Код
Авторство
О чём код?
import pytest from fastapi.testclient import TestClient from main import app client = TestClient(app) def test_chat_endpoint_valid(): """Тест валидного запроса""" response = client.post( "/api/chat", json={"message": "Привет, как дела?"} ) assert response.status_code == 200 data = response.json() assert "response" in data assert data["status"] == "success" assert "from_cache" in data def test_chat_endpoint_empty_message(): """Тест пустого сообщения""" response = client.post( "/api/chat", json={"message": ""} ) assert response.status_code == 400 def test_chat_endpoint_long_message(): """Тест слишком длинного сообщения""" long_message = "x" * 2000 response = client.post( "/api/chat", json={"message": long_message} ) assert response.status_code == 400 def test_health_endpoint(): """Тест health check""" response = client.get("/api/health") assert response.status_code == 200 data = response.json() assert data["status"] == "healthy" def test_cache_clear(): """Тест очистки кеша""" response = client.post("/api/cache/clear") assert response.status_code == 200 assert response.json()["status"] == "cache_cleared"