This commit is contained in:
108
tests/test_delete_api_debug.py
Normal file
108
tests/test_delete_api_debug.py
Normal file
@@ -0,0 +1,108 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Тест для отладки удаления сообщества через API
|
||||
"""
|
||||
|
||||
import json
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
def test_delete_community_api():
|
||||
# 1. Авторизуемся
|
||||
print("🔐 Авторизуемся...")
|
||||
login_response = requests.post(
|
||||
"http://localhost:8000/graphql",
|
||||
json={
|
||||
"query": """
|
||||
mutation Login($email: String!, $password: String!) {
|
||||
login(email: $email, password: $password) {
|
||||
success
|
||||
token
|
||||
author {
|
||||
id
|
||||
email
|
||||
}
|
||||
error
|
||||
}
|
||||
}
|
||||
""",
|
||||
"variables": {"email": "test_admin@discours.io", "password": "password123"},
|
||||
},
|
||||
)
|
||||
|
||||
login_data = login_response.json()
|
||||
print(f"📡 Ответ авторизации: {json.dumps(login_data, indent=2)}")
|
||||
|
||||
if not login_data.get("data", {}).get("login", {}).get("success"):
|
||||
print("❌ Авторизация не удалась")
|
||||
return
|
||||
|
||||
token = login_data["data"]["login"]["token"]
|
||||
print(f"✅ Авторизация успешна, токен: {token[:20]}...")
|
||||
|
||||
# 2. Удаляем сообщество
|
||||
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-community-test-995f4965"},
|
||||
},
|
||||
)
|
||||
|
||||
delete_data = delete_response.json()
|
||||
print(f"📡 Ответ удаления: {json.dumps(delete_data, indent=2)}")
|
||||
|
||||
if delete_data.get("data", {}).get("delete_community", {}).get("success"):
|
||||
print("✅ Удаление прошло успешно")
|
||||
else:
|
||||
print("❌ Удаление не удалось")
|
||||
error = delete_data.get("data", {}).get("delete_community", {}).get("error")
|
||||
print(f"Ошибка: {error}")
|
||||
|
||||
# 3. Проверяем что сообщество удалено
|
||||
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
|
||||
slug
|
||||
name
|
||||
}
|
||||
}
|
||||
"""
|
||||
},
|
||||
)
|
||||
|
||||
check_data = check_response.json()
|
||||
communities = check_data.get("data", {}).get("get_communities_all", [])
|
||||
|
||||
# Ищем наше сообщество
|
||||
target_community = None
|
||||
for community in communities:
|
||||
if community["slug"] == "test-community-test-995f4965":
|
||||
target_community = community
|
||||
break
|
||||
|
||||
if target_community:
|
||||
print(f"❌ Сообщество все еще существует: {target_community}")
|
||||
else:
|
||||
print("✅ Сообщество успешно удалено")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_delete_community_api()
|
121
tests/test_delete_button_debug.py
Normal file
121
tests/test_delete_button_debug.py
Normal file
@@ -0,0 +1,121 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Тест для отладки поиска кнопки удаления
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import time
|
||||
|
||||
from playwright.async_api import async_playwright
|
||||
|
||||
|
||||
async def test_delete_button():
|
||||
async with async_playwright() as p:
|
||||
browser = await p.chromium.launch(headless=False)
|
||||
page = await browser.new_page()
|
||||
|
||||
try:
|
||||
print("🌐 Открываем админ-панель...")
|
||||
await page.goto("http://localhost:3000/login")
|
||||
await page.wait_for_load_state("networkidle")
|
||||
|
||||
print("🔐 Авторизуемся...")
|
||||
await page.fill('input[type="email"]', "test_admin@discours.io")
|
||||
await page.fill('input[type="password"]', "password123")
|
||||
await page.click('button[type="submit"]')
|
||||
|
||||
# Ждем авторизации
|
||||
await page.wait_for_url("http://localhost:3000/admin/**", timeout=10000)
|
||||
print("✅ Авторизация успешна")
|
||||
|
||||
print("📋 Переходим на страницу сообществ...")
|
||||
await page.goto("http://localhost:3000/admin/communities")
|
||||
await page.wait_for_load_state("networkidle")
|
||||
|
||||
print("🔍 Ищем таблицу сообществ...")
|
||||
await page.wait_for_selector("table", timeout=10000)
|
||||
await page.wait_for_selector("table tbody tr", timeout=10000)
|
||||
|
||||
print("📸 Делаем скриншот таблицы...")
|
||||
await page.screenshot(path="test-results/communities_table_debug.png")
|
||||
|
||||
# Получаем информацию о всех строках таблицы
|
||||
table_info = await page.evaluate("""
|
||||
() => {
|
||||
const rows = document.querySelectorAll('table tbody tr');
|
||||
return Array.from(rows).map((row, index) => {
|
||||
const cells = row.querySelectorAll('td');
|
||||
const buttons = row.querySelectorAll('button');
|
||||
return {
|
||||
rowIndex: index,
|
||||
id: cells[0]?.textContent?.trim(),
|
||||
name: cells[1]?.textContent?.trim(),
|
||||
slug: cells[2]?.textContent?.trim(),
|
||||
buttons: Array.from(buttons).map(btn => ({
|
||||
text: btn.textContent?.trim(),
|
||||
className: btn.className,
|
||||
title: btn.title,
|
||||
ariaLabel: btn.getAttribute('aria-label')
|
||||
}))
|
||||
};
|
||||
});
|
||||
}
|
||||
""")
|
||||
|
||||
print("📋 Информация о таблице:")
|
||||
for row in table_info:
|
||||
print(f" Строка {row['rowIndex']}: ID={row['id']}, Name='{row['name']}', Slug='{row['slug']}'")
|
||||
print(f" Кнопки: {row['buttons']}")
|
||||
|
||||
# Ищем строку с "Test Community"
|
||||
test_community_row = None
|
||||
for row in table_info:
|
||||
if "Test Community" in row["name"]:
|
||||
test_community_row = row
|
||||
break
|
||||
|
||||
if test_community_row:
|
||||
print(f"✅ Найдена строка с Test Community: {test_community_row}")
|
||||
|
||||
# Пробуем найти кнопку удаления
|
||||
row_index = test_community_row["rowIndex"]
|
||||
|
||||
# Способ 1: по классу
|
||||
delete_button = await page.query_selector(
|
||||
f"table tbody tr:nth-child({row_index + 1}) button.delete-button"
|
||||
)
|
||||
print(f"Кнопка по классу delete-button: {'✅' if delete_button else '❌'}")
|
||||
|
||||
# Способ 2: по символу ×
|
||||
delete_button = await page.query_selector(
|
||||
f'table tbody tr:nth-child({row_index + 1}) button:has-text("×")'
|
||||
)
|
||||
print(f"Кнопка по символу ×: {'✅' if delete_button else '❌'}")
|
||||
|
||||
# Способ 3: в последней ячейке
|
||||
delete_button = await page.query_selector(
|
||||
f"table tbody tr:nth-child({row_index + 1}) td:last-child button"
|
||||
)
|
||||
print(f"Кнопка в последней ячейке: {'✅' if delete_button else '❌'}")
|
||||
|
||||
# Способ 4: все кнопки в строке
|
||||
buttons = await page.query_selector_all(f"table tbody tr:nth-child({row_index + 1}) button")
|
||||
print(f"Всего кнопок в строке: {len(buttons)}")
|
||||
|
||||
for i, btn in enumerate(buttons):
|
||||
text = await btn.text_content()
|
||||
class_name = await btn.get_attribute("class")
|
||||
print(f" Кнопка {i}: текст='{text}', класс='{class_name}'")
|
||||
|
||||
else:
|
||||
print("❌ Строка с Test Community не найдена")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Ошибка: {e}")
|
||||
await page.screenshot(path=f"test-results/error_{int(time.time())}.png")
|
||||
finally:
|
||||
await browser.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(test_delete_button())
|
78
tests/test_delete_existing_community.py
Normal file
78
tests/test_delete_existing_community.py
Normal file
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Тестовый скрипт для проверки удаления существующего сообщества через API
|
||||
"""
|
||||
|
||||
import json
|
||||
|
||||
import requests
|
||||
|
||||
# GraphQL endpoint
|
||||
url = "http://localhost:8000/graphql"
|
||||
|
||||
# Сначала авторизуемся
|
||||
login_mutation = """
|
||||
mutation Login($email: String!, $password: String!) {
|
||||
login(email: $email, password: $password) {
|
||||
token
|
||||
author {
|
||||
id
|
||||
name
|
||||
email
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
login_variables = {"email": "test_admin@discours.io", "password": "password123"}
|
||||
|
||||
print("🔐 Авторизуемся...")
|
||||
response = requests.post(url, json={"query": login_mutation, "variables": login_variables})
|
||||
|
||||
if response.status_code != 200:
|
||||
print(f"❌ Ошибка авторизации: {response.status_code}")
|
||||
print(response.text)
|
||||
exit(1)
|
||||
|
||||
login_data = response.json()
|
||||
print(f"✅ Авторизация успешна: {json.dumps(login_data, indent=2)}")
|
||||
|
||||
if "errors" in login_data:
|
||||
print(f"❌ Ошибки в авторизации: {login_data['errors']}")
|
||||
exit(1)
|
||||
|
||||
token = login_data["data"]["login"]["token"]
|
||||
author_id = login_data["data"]["login"]["author"]["id"]
|
||||
print(f"🔑 Токен получен: {token[:50]}...")
|
||||
print(f"👤 Author ID: {author_id}")
|
||||
|
||||
# Теперь попробуем удалить существующее сообщество
|
||||
delete_mutation = """
|
||||
mutation DeleteCommunity($slug: String!) {
|
||||
delete_community(slug: $slug) {
|
||||
success
|
||||
error
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
delete_variables = {"slug": "test-admin-community-test-26b67fa4"}
|
||||
|
||||
headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
|
||||
|
||||
print(f"\n🗑️ Пытаемся удалить сообщество {delete_variables['slug']}...")
|
||||
response = requests.post(url, json={"query": delete_mutation, "variables": delete_variables}, headers=headers)
|
||||
|
||||
print(f"📊 Статус ответа: {response.status_code}")
|
||||
print(f"📄 Ответ: {response.text}")
|
||||
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
print(f"📋 JSON ответ: {json.dumps(data, indent=2)}")
|
||||
|
||||
if "errors" in data:
|
||||
print(f"❌ GraphQL ошибки: {data['errors']}")
|
||||
else:
|
||||
print(f"✅ Результат: {data['data']['delete_community']}")
|
||||
else:
|
||||
print(f"❌ HTTP ошибка: {response.status_code}")
|
145
tests/test_delete_new_community.py
Normal file
145
tests/test_delete_new_community.py
Normal file
@@ -0,0 +1,145 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Тестирование удаления нового сообщества через API
|
||||
"""
|
||||
|
||||
import json
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
def test_delete_new_community():
|
||||
"""Тестируем удаление нового сообщества через API"""
|
||||
|
||||
# 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
|
||||
}
|
||||
error
|
||||
}
|
||||
}
|
||||
""",
|
||||
"variables": {"email": "test_admin@discours.io", "password": "password123"},
|
||||
},
|
||||
)
|
||||
|
||||
login_data = login_response.json()
|
||||
if not login_data.get("data", {}).get("login", {}).get("success"):
|
||||
print("❌ Ошибка авторизации test_admin@discours.io")
|
||||
return
|
||||
|
||||
token = login_data["data"]["login"]["token"]
|
||||
user_id = login_data["data"]["login"]["author"]["id"]
|
||||
print(f"✅ Авторизация успешна, пользователь ID: {user_id}")
|
||||
|
||||
# 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
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
},
|
||||
)
|
||||
|
||||
communities_data = communities_response.json()
|
||||
target_community = None
|
||||
for community in communities_data.get("data", {}).get("get_communities_all", []):
|
||||
if community["slug"] == "test-admin-community-e2e-1754005730":
|
||||
target_community = community
|
||||
break
|
||||
|
||||
if not target_community:
|
||||
print("❌ Сообщество test-admin-community-e2e-1754005730 не найдено")
|
||||
return
|
||||
|
||||
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"},
|
||||
},
|
||||
)
|
||||
|
||||
delete_data = delete_response.json()
|
||||
print(f"📡 Ответ удаления: {json.dumps(delete_data, indent=2, ensure_ascii=False)}")
|
||||
|
||||
if delete_data.get("data", {}).get("delete_community", {}).get("success"):
|
||||
print("✅ Удаление прошло успешно")
|
||||
|
||||
# 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
|
||||
}
|
||||
}
|
||||
"""
|
||||
},
|
||||
)
|
||||
|
||||
check_data = check_response.json()
|
||||
still_exists = False
|
||||
for community in check_data.get("data", {}).get("get_communities_all", []):
|
||||
if community["slug"] == "test-admin-community-e2e-1754005730":
|
||||
still_exists = True
|
||||
break
|
||||
|
||||
if still_exists:
|
||||
print("❌ Сообщество все еще существует после удаления")
|
||||
else:
|
||||
print("✅ Сообщество успешно удалено из базы данных")
|
||||
else:
|
||||
print("❌ Ошибка удаления")
|
||||
error = delete_data.get("data", {}).get("delete_community", {}).get("error")
|
||||
print(f"Ошибка: {error}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_delete_new_community()
|
130
tests/test_e2e_simple.py
Normal file
130
tests/test_e2e_simple.py
Normal file
@@ -0,0 +1,130 @@
|
||||
import json
|
||||
import time
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
def test_e2e_community_delete_workflow():
|
||||
"""Упрощенный E2E тест удаления сообщества без браузера"""
|
||||
|
||||
url = "http://localhost:8000/graphql"
|
||||
headers = {"Content-Type": "application/json"}
|
||||
|
||||
print("🔐 E2E тест удаления сообщества...\n")
|
||||
|
||||
# 1. Авторизация
|
||||
print("1️⃣ Авторизуемся...")
|
||||
login_query = """
|
||||
mutation Login($email: String!, $password: String!) {
|
||||
login(email: $email, password: $password) {
|
||||
success
|
||||
token
|
||||
author {
|
||||
id
|
||||
email
|
||||
}
|
||||
error
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
variables = {"email": "test_admin@discours.io", "password": "password123"}
|
||||
|
||||
data = {"query": login_query, "variables": variables}
|
||||
|
||||
response = requests.post(url, headers=headers, json=data)
|
||||
result = response.json()
|
||||
|
||||
if not result.get("data", {}).get("login", {}).get("success"):
|
||||
print(f"❌ Авторизация не удалась: {result}")
|
||||
return False
|
||||
|
||||
token = result["data"]["login"]["token"]
|
||||
print(f"✅ Авторизация успешна, токен: {token[:50]}...")
|
||||
|
||||
# 2. Получаем список сообществ
|
||||
print("\n2️⃣ Получаем список сообществ...")
|
||||
headers_with_auth = {"Content-Type": "application/json", "Authorization": f"Bearer {token}"}
|
||||
|
||||
communities_query = """
|
||||
query {
|
||||
get_communities_all {
|
||||
id
|
||||
name
|
||||
slug
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
data = {"query": communities_query}
|
||||
response = requests.post(url, headers=headers_with_auth, json=data)
|
||||
result = response.json()
|
||||
|
||||
communities = result.get("data", {}).get("get_communities_all", [])
|
||||
test_community = None
|
||||
|
||||
for community in communities:
|
||||
if community["name"] == "Test Community":
|
||||
test_community = community
|
||||
break
|
||||
|
||||
if not test_community:
|
||||
print("❌ Сообщество Test Community не найдено")
|
||||
return False
|
||||
|
||||
print(
|
||||
f"✅ Найдено сообщество: {test_community['name']} (ID: {test_community['id']}, slug: {test_community['slug']})"
|
||||
)
|
||||
|
||||
# 3. Удаляем сообщество
|
||||
print("\n3️⃣ Удаляем сообщество...")
|
||||
delete_query = """
|
||||
mutation DeleteCommunity($slug: String!) {
|
||||
delete_community(slug: $slug) {
|
||||
success
|
||||
message
|
||||
error
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
variables = {"slug": test_community["slug"]}
|
||||
data = {"query": delete_query, "variables": variables}
|
||||
|
||||
response = requests.post(url, headers=headers_with_auth, json=data)
|
||||
result = response.json()
|
||||
|
||||
print("Ответ сервера:")
|
||||
print(json.dumps(result, indent=2, ensure_ascii=False))
|
||||
|
||||
if not result.get("data", {}).get("delete_community", {}).get("success"):
|
||||
print("❌ Ошибка удаления сообщества")
|
||||
return False
|
||||
|
||||
print("✅ Сообщество успешно удалено!")
|
||||
|
||||
# 4. Проверяем что сообщество удалено
|
||||
print("\n4️⃣ Проверяем что сообщество удалено...")
|
||||
time.sleep(1) # Даем время на обновление БД
|
||||
|
||||
data = {"query": communities_query}
|
||||
response = requests.post(url, headers=headers_with_auth, json=data)
|
||||
result = response.json()
|
||||
|
||||
communities_after = result.get("data", {}).get("get_communities_all", [])
|
||||
community_still_exists = any(c["slug"] == test_community["slug"] for c in communities_after)
|
||||
|
||||
if community_still_exists:
|
||||
print("❌ Сообщество все еще в списке")
|
||||
return False
|
||||
|
||||
print("✅ Сообщество действительно удалено из списка")
|
||||
|
||||
print("\n🎉 E2E тест удаления сообщества прошел успешно!")
|
||||
return True
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = test_e2e_community_delete_workflow()
|
||||
if not success:
|
||||
exit(1)
|
124
tests/test_login_debug.py
Normal file
124
tests/test_login_debug.py
Normal file
@@ -0,0 +1,124 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Простой тест для отладки авторизации через браузер
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import time
|
||||
|
||||
from playwright.async_api import async_playwright
|
||||
|
||||
|
||||
async def test_login():
|
||||
async with async_playwright() as p:
|
||||
browser = await p.chromium.launch(headless=False) # headless=False для отладки
|
||||
page = await browser.new_page()
|
||||
|
||||
# Включаем детальное логирование сетевых запросов
|
||||
page.on("request", lambda request: print(f"🌐 REQUEST: {request.method} {request.url}"))
|
||||
page.on("response", lambda response: print(f"📡 RESPONSE: {response.status} {response.url}"))
|
||||
page.on("console", lambda msg: print(f"📝 CONSOLE: {msg.text}"))
|
||||
|
||||
try:
|
||||
print("🌐 Открываем страницу входа...")
|
||||
await page.goto("http://localhost:3000/login")
|
||||
await page.wait_for_load_state("networkidle")
|
||||
|
||||
print("📸 Делаем скриншот страницы входа...")
|
||||
await page.screenshot(path="test-results/login_page.png")
|
||||
|
||||
print("🔍 Проверяем элементы формы...")
|
||||
|
||||
# Проверяем наличие полей ввода
|
||||
email_field = await page.query_selector('input[type="email"]')
|
||||
password_field = await page.query_selector('input[type="password"]')
|
||||
submit_button = await page.query_selector('button[type="submit"]')
|
||||
|
||||
print(f"Email поле: {'✅' if email_field else '❌'}")
|
||||
print(f"Password поле: {'✅' if password_field else '❌'}")
|
||||
print(f"Submit кнопка: {'✅' if submit_button else '❌'}")
|
||||
|
||||
if not all([email_field, password_field, submit_button]):
|
||||
print("❌ Не все элементы формы найдены")
|
||||
return
|
||||
|
||||
print("🔐 Заполняем форму входа...")
|
||||
await page.fill('input[type="email"]', "test_admin@discours.io")
|
||||
await page.fill('input[type="password"]', "password123")
|
||||
|
||||
print("📸 Делаем скриншот заполненной формы...")
|
||||
await page.screenshot(path="test-results/filled_form.png")
|
||||
|
||||
print("🔄 Нажимаем кнопку входа...")
|
||||
await page.click('button[type="submit"]')
|
||||
|
||||
# Ждем немного для обработки
|
||||
await asyncio.sleep(5)
|
||||
|
||||
print("📸 Делаем скриншот после нажатия кнопки...")
|
||||
await page.screenshot(path="test-results/after_submit.png")
|
||||
|
||||
# Проверяем текущий URL
|
||||
current_url = page.url
|
||||
print(f"📍 Текущий URL: {current_url}")
|
||||
|
||||
if "/login" in current_url:
|
||||
print("❌ Остались на странице входа - авторизация не удалась")
|
||||
|
||||
# Проверяем есть ли ошибка
|
||||
error_element = await page.query_selector('.fieldError, .error, [class*="error"]')
|
||||
if error_element:
|
||||
error_text = await error_element.text_content()
|
||||
print(f"❌ Ошибка авторизации: {error_text}")
|
||||
else:
|
||||
print("❌ Ошибка авторизации не найдена")
|
||||
|
||||
# Проверяем консоль браузера на наличие ошибок
|
||||
console_messages = await page.evaluate("""
|
||||
() => {
|
||||
return window.console.messages || [];
|
||||
}
|
||||
""")
|
||||
if console_messages:
|
||||
print("📝 Сообщения консоли:")
|
||||
for msg in console_messages:
|
||||
print(f" {msg}")
|
||||
else:
|
||||
print("✅ Авторизация прошла успешно!")
|
||||
|
||||
# Проверяем что мы в админ-панели
|
||||
if "/admin" in current_url:
|
||||
print("✅ Перенаправлены в админ-панель")
|
||||
|
||||
# Ждем загрузки админ-панели
|
||||
await page.wait_for_load_state("networkidle")
|
||||
|
||||
# Проверяем наличие кнопок навигации
|
||||
communities_button = await page.query_selector('button:has-text("Сообщества")')
|
||||
print(f"Кнопка 'Сообщества': {'✅' if communities_button else '❌'}")
|
||||
|
||||
if communities_button:
|
||||
print("✅ Админ-панель загружена корректно")
|
||||
else:
|
||||
print("❌ Кнопки навигации не найдены")
|
||||
|
||||
# Делаем скриншот админ-панели
|
||||
await page.screenshot(path="test-results/admin_panel.png")
|
||||
|
||||
# Получаем HTML для отладки
|
||||
html_content = await page.content()
|
||||
with open("test-results/admin_panel.html", "w", encoding="utf-8") as f:
|
||||
f.write(html_content)
|
||||
print("📄 HTML админ-панели сохранен")
|
||||
else:
|
||||
print(f"❌ Неожиданный URL после авторизации: {current_url}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Ошибка в тесте: {e}")
|
||||
await page.screenshot(path=f"test-results/error_{int(time.time())}.png")
|
||||
finally:
|
||||
await browser.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(test_login())
|
54
tests/test_rbac_debug.py
Normal file
54
tests/test_rbac_debug.py
Normal file
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Тест для проверки RBAC модуля
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
||||
def test_rbac_import():
|
||||
"""Тестируем импорт RBAC модуля"""
|
||||
try:
|
||||
from services.rbac import require_any_permission, require_permission
|
||||
|
||||
print("✅ RBAC модуль импортирован успешно")
|
||||
|
||||
# Проверяем, что функции существуют
|
||||
print(f"✅ require_permission: {require_permission}")
|
||||
print(f"✅ require_any_permission: {require_any_permission}")
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"❌ Ошибка импорта RBAC: {e}")
|
||||
return False
|
||||
|
||||
|
||||
def test_require_permission_decorator():
|
||||
"""Тестируем декоратор require_permission"""
|
||||
try:
|
||||
from services.rbac import require_permission
|
||||
|
||||
@require_permission("test:permission")
|
||||
async def test_func(*args, **kwargs):
|
||||
return "success"
|
||||
|
||||
print("✅ Декоратор require_permission создан успешно")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"❌ Ошибка создания декоратора require_permission: {e}")
|
||||
import traceback
|
||||
|
||||
traceback.print_exc()
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("🧪 Тестируем RBAC модуль...")
|
||||
|
||||
if test_rbac_import():
|
||||
test_require_permission_decorator()
|
||||
|
||||
print("🏁 Тест завершен")
|
90
tests/test_user_roles_debug.py
Normal file
90
tests/test_user_roles_debug.py
Normal file
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Тест для проверки ролей пользователя
|
||||
"""
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
def test_user_roles():
|
||||
# 1. Авторизуемся
|
||||
print("🔐 Авторизуемся...")
|
||||
login_response = requests.post(
|
||||
"http://localhost:8000/graphql",
|
||||
json={
|
||||
"query": """
|
||||
mutation Login($email: String!, $password: String!) {
|
||||
login(email: $email, password: $password) {
|
||||
success
|
||||
token
|
||||
author {
|
||||
id
|
||||
email
|
||||
}
|
||||
error
|
||||
}
|
||||
}
|
||||
""",
|
||||
"variables": {"email": "test_admin@discours.io", "password": "password123"},
|
||||
},
|
||||
)
|
||||
|
||||
login_data = login_response.json()
|
||||
if not login_data.get("data", {}).get("login", {}).get("success"):
|
||||
print("❌ Авторизация не удалась")
|
||||
return
|
||||
|
||||
token = login_data["data"]["login"]["token"]
|
||||
user_id = login_data["data"]["login"]["author"]["id"]
|
||||
print(f"✅ Авторизация успешна, пользователь ID: {user_id}")
|
||||
|
||||
# 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
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
},
|
||||
)
|
||||
|
||||
communities_data = communities_response.json()
|
||||
communities = communities_data.get("data", {}).get("get_communities_all", [])
|
||||
|
||||
# Ищем сообщества с именем "Test Community"
|
||||
test_communities = []
|
||||
for community in communities:
|
||||
if "Test Community" in community["name"]:
|
||||
test_communities.append(community)
|
||||
|
||||
print("📋 Сообщества с именем 'Test Community':")
|
||||
for community in test_communities:
|
||||
print(f" - ID: {community['id']}, Name: '{community['name']}', Slug: {community['slug']}")
|
||||
print(f" Создатель: {community['created_by']}")
|
||||
|
||||
if test_communities:
|
||||
# Берем первое сообщество для тестирования
|
||||
test_community = test_communities[0]
|
||||
print(f"✅ Будем тестировать удаление сообщества: {test_community['name']} (slug: {test_community['slug']})")
|
||||
|
||||
# Сохраняем информацию для E2E теста
|
||||
print("📝 Для E2E теста используйте:")
|
||||
print(f' test_community_name = "{test_community["name"]}"')
|
||||
print(f' test_community_slug = "{test_community["slug"]}"')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_user_roles()
|
Reference in New Issue
Block a user