Files
core/tests/test_server_health.py

66 lines
2.5 KiB
Python
Raw Normal View History

2025-08-17 11:37:55 +03:00
#!/usr/bin/env python3
"""
Тест здоровья серверов для CI
"""
import time
import requests
import pytest
2025-08-27 18:31:51 +03:00
def test_backend_health(backend_server):
2025-08-17 11:37:55 +03:00
"""Проверяем здоровье бэкенда"""
2025-08-27 18:31:51 +03:00
assert backend_server, "Бэкенд сервер должен быть запущен"
response = requests.get("http://localhost:8000/", timeout=10)
assert response.status_code == 200, f"Бэкенд вернул статус {response.status_code}"
print("✅ Бэкенд здоров")
2025-08-17 11:37:55 +03:00
2025-08-27 18:31:51 +03:00
def test_frontend_health(frontend_server):
2025-08-17 11:37:55 +03:00
"""Проверяем здоровье фронтенда"""
2025-08-27 18:31:51 +03:00
if not frontend_server:
pytest.skip("Фронтенд сервер не удалось запустить (возможно отсутствует npm или зависимости)")
response = requests.get("http://localhost:3000/", timeout=10)
assert response.status_code == 200, f"Фронтенд вернул статус {response.status_code}"
print("✅ Фронтенд здоров")
2025-08-17 11:37:55 +03:00
2025-08-27 18:31:51 +03:00
def test_graphql_endpoint(backend_server):
2025-08-17 11:37:55 +03:00
"""Проверяем доступность GraphQL endpoint"""
2025-08-27 18:31:51 +03:00
assert backend_server, "Бэкенд сервер должен быть запущен"
response = requests.post(
"http://localhost:8000/graphql",
headers={"Content-Type": "application/json"},
json={"query": "{ __schema { types { name } } }"},
timeout=15
)
assert response.status_code == 200, f"GraphQL endpoint вернул статус {response.status_code}"
print("✅ GraphQL endpoint доступен")
2025-08-17 11:37:55 +03:00
2025-08-27 18:31:51 +03:00
def test_admin_panel_access(frontend_server):
2025-08-17 11:37:55 +03:00
"""Проверяем доступность админ-панели"""
2025-08-27 18:31:51 +03:00
if not frontend_server:
pytest.skip("Фронтенд сервер не запущен - админ-панель недоступна")
response = requests.get("http://localhost:3000/admin", timeout=15)
assert response.status_code == 200, f"Админ-панель вернула статус {response.status_code}"
print("✅ Админ-панель доступна")
2025-08-17 11:37:55 +03:00
if __name__ == "__main__":
print("🧪 Проверяем здоровье серверов...")
try:
test_backend_health()
test_frontend_health()
test_graphql_endpoint()
test_admin_panel_access()
print("Все серверы здоровы!")
except Exception as e:
print(f"❌ Ошибка проверки здоровья: {e}")
exit(1)