66 lines
2.5 KiB
Python
66 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
Тест здоровья серверов для CI
|
||
"""
|
||
|
||
import time
|
||
import requests
|
||
import pytest
|
||
|
||
|
||
def test_backend_health(backend_server):
|
||
"""Проверяем здоровье бэкенда"""
|
||
assert backend_server, "Бэкенд сервер должен быть запущен"
|
||
|
||
response = requests.get("http://localhost:8000/", timeout=10)
|
||
assert response.status_code == 200, f"Бэкенд вернул статус {response.status_code}"
|
||
print("✅ Бэкенд здоров")
|
||
|
||
|
||
def test_frontend_health(frontend_server):
|
||
"""Проверяем здоровье фронтенда"""
|
||
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("✅ Фронтенд здоров")
|
||
|
||
|
||
def test_graphql_endpoint(backend_server):
|
||
"""Проверяем доступность GraphQL endpoint"""
|
||
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 доступен")
|
||
|
||
|
||
def test_admin_panel_access(frontend_server):
|
||
"""Проверяем доступность админ-панели"""
|
||
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("✅ Админ-панель доступна")
|
||
|
||
|
||
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)
|