citesting-fix1
Some checks failed
Deploy on push / deploy (push) Failing after 2m0s

This commit is contained in:
2025-08-17 11:37:55 +03:00
parent 4b88a8c449
commit bc8447a444
6 changed files with 648 additions and 227 deletions

View File

@@ -4,41 +4,72 @@
"""
import json
import time
import requests
def wait_for_server_ready(url: str, timeout: int = 60) -> bool:
"""Ждем готовности сервера"""
start_time = time.time()
while time.time() - start_time < timeout:
try:
response = requests.get(url, timeout=10)
if response.status_code == 200:
return True
except:
pass
time.sleep(2)
return False
def test_delete_new_community():
"""Тестируем удаление нового сообщества через API"""
# Проверяем готовность бэкенда
print("🌐 Проверяем готовность бэкенда...")
if not wait_for_server_ready("http://localhost:8000"):
print("❌ Бэкенд не готов в течение 60 секунд")
return False
print("✅ Бэкенд готов")
# 1. Авторизуемся как test_admin@discours.io
print("🔐 Авторизуемся как test_admin@discours.io...")
login_response = requests.post(
"http://localhost:8000/graphql",
headers={"Content-Type": "application/json"},
json={
"query": """
mutation Login($email: String!, $password: String!) {
login(email: $email, password: $password) {
success
token
author {
id
name
email
try:
login_response = requests.post(
"http://localhost:8000/graphql",
headers={"Content-Type": "application/json"},
json={
"query": """
mutation Login($email: String!, $password: String!) {
login(email: $email, password: $password) {
success
token
author {
id
name
email
}
error
}
}
error
}
}
""",
"variables": {"email": "test_admin@discours.io", "password": "password123"},
},
)
""",
"variables": {"email": "test_admin@discours.io", "password": "password123"},
},
timeout=30 # Увеличиваем таймаут
)
except requests.exceptions.Timeout:
print("❌ Таймаут при авторизации")
return False
except requests.exceptions.ConnectionError:
print("❌ Ошибка подключения к бэкенду")
return False
login_data = login_response.json()
if not login_data.get("data", {}).get("login", {}).get("success"):
print("❌ Ошибка авторизации test_admin@discours.io")
return
print(f"Ответ: {json.dumps(login_data, indent=2, ensure_ascii=False)}")
return False
token = login_data["data"]["login"]["token"]
user_id = login_data["data"]["login"]["author"]["id"]
@@ -46,26 +77,31 @@ def test_delete_new_community():
# 2. Проверяем, что сообщество существует
print("🔍 Проверяем существование сообщества...")
communities_response = requests.post(
"http://localhost:8000/graphql",
headers={"Authorization": f"Bearer {token}", "Content-Type": "application/json"},
json={
"query": """
query GetCommunities {
get_communities_all {
id
name
slug
created_by {
id
name
email
try:
communities_response = requests.post(
"http://localhost:8000/graphql",
headers={"Authorization": f"Bearer {token}", "Content-Type": "application/json"},
json={
"query": """
query GetCommunities {
get_communities_all {
id
name
slug
created_by {
id
name
email
}
}
}
}
}
"""
},
)
""",
},
timeout=30 # Увеличиваем таймаут
)
except requests.exceptions.Timeout:
print("❌ Таймаут при получении списка сообществ")
return False
communities_data = communities_response.json()
target_community = None
@@ -76,29 +112,37 @@ def test_delete_new_community():
if not target_community:
print("❌ Сообщество test-admin-community-e2e-1754005730 не найдено")
return
print("Доступные сообщества:")
for community in communities_data.get("data", {}).get("get_communities_all", []):
print(f" - {community['name']} (slug: {community['slug']})")
return False
print(f"✅ Найдено сообщество: {target_community['name']} (ID: {target_community['id']})")
print(f" Создатель: {target_community['created_by']['name']} (ID: {target_community['created_by']['id']})")
# 3. Пытаемся удалить сообщество
print("🗑️ Пытаемся удалить сообщество...")
delete_response = requests.post(
"http://localhost:8000/graphql",
headers={"Authorization": f"Bearer {token}", "Content-Type": "application/json"},
json={
"query": """
mutation DeleteCommunity($slug: String!) {
delete_community(slug: $slug) {
success
message
error
}
}
""",
"variables": {"slug": "test-admin-community-e2e-1754005730"},
},
)
try:
delete_response = requests.post(
"http://localhost:8000/graphql",
headers={"Authorization": f"Bearer {token}", "Content-Type": "application/json"},
json={
"query": """
mutation DeleteCommunity($slug: String!) {
delete_community(slug: $slug) {
success
message
error
}
}
""",
"variables": {"slug": "test-admin-community-e2e-1754005730"},
},
timeout=30 # Увеличиваем таймаут
)
except requests.exceptions.Timeout:
print("❌ Таймаут при удалении сообщества")
return False
delete_data = delete_response.json()
print(f"📡 Ответ удаления: {json.dumps(delete_data, indent=2, ensure_ascii=False)}")
@@ -108,21 +152,26 @@ def test_delete_new_community():
# 4. Проверяем, что сообщество действительно удалено
print("🔍 Проверяем, что сообщество удалено...")
check_response = requests.post(
"http://localhost:8000/graphql",
headers={"Authorization": f"Bearer {token}", "Content-Type": "application/json"},
json={
"query": """
query GetCommunities {
get_communities_all {
id
name
slug
}
}
"""
},
)
try:
check_response = requests.post(
"http://localhost:8000/graphql",
headers={"Authorization": f"Bearer {token}", "Content-Type": "application/json"},
json={
"query": """
query GetCommunities {
get_communities_all {
id
name
slug
}
}
""",
},
timeout=30 # Увеличиваем таймаут
)
except requests.exceptions.Timeout:
print("❌ Таймаут при проверке удаления")
return False
check_data = check_response.json()
still_exists = False
@@ -133,13 +182,20 @@ def test_delete_new_community():
if still_exists:
print("❌ Сообщество все еще существует после удаления")
return False
else:
print("✅ Сообщество успешно удалено из базы данных")
return True
else:
print("❌ Ошибка удаления")
error = delete_data.get("data", {}).get("delete_community", {}).get("error")
print(f"Ошибка: {error}")
return False
if __name__ == "__main__":
test_delete_new_community()
if test_delete_new_community():
print("✅ Тест завершен успешно")
else:
print("❌ Тест завершен с ошибками")
exit(1)