fix: wrap test_delete_existing_community.py code in test function
- Fixes pytest collection error during import - Prevents code execution at module level - Maintains functionality when run as script - All 361 tests now collect successfully
This commit is contained in:
@@ -4,12 +4,15 @@
|
||||
"""
|
||||
|
||||
import json
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
# GraphQL endpoint
|
||||
url = "http://localhost:8000/graphql"
|
||||
|
||||
def test_delete_existing_community():
|
||||
"""Тест удаления существующего сообщества через API"""
|
||||
|
||||
# Сначала авторизуемся
|
||||
login_mutation = """
|
||||
mutation Login($email: String!, $password: String!) {
|
||||
@@ -32,14 +35,14 @@ response = requests.post(url, json={"query": login_mutation, "variables": login_
|
||||
if response.status_code != 200:
|
||||
print(f"❌ Ошибка авторизации: {response.status_code}")
|
||||
print(response.text)
|
||||
exit(1)
|
||||
pytest.fail(f"Ошибка авторизации: {response.status_code}")
|
||||
|
||||
login_data = response.json()
|
||||
print(f"✅ Авторизация успешна: {json.dumps(login_data, indent=2)}")
|
||||
|
||||
if "errors" in login_data:
|
||||
print(f"❌ Ошибки в авторизации: {login_data['errors']}")
|
||||
exit(1)
|
||||
pytest.fail(f"Ошибки в авторизации: {login_data['errors']}")
|
||||
|
||||
token = login_data["data"]["login"]["token"]
|
||||
author_id = login_data["data"]["login"]["author"]["id"]
|
||||
@@ -72,7 +75,15 @@ if response.status_code == 200:
|
||||
|
||||
if "errors" in data:
|
||||
print(f"❌ GraphQL ошибки: {data['errors']}")
|
||||
pytest.fail(f"GraphQL ошибки: {data['errors']}")
|
||||
else:
|
||||
print(f"✅ Результат: {data['data']['delete_community']}")
|
||||
# Проверяем, что удаление прошло успешно
|
||||
assert data['data']['delete_community']['success'] is True
|
||||
else:
|
||||
print(f"❌ HTTP ошибка: {response.status_code}")
|
||||
pytest.fail(f"HTTP ошибка: {response.status_code}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Для запуска как скрипт
|
||||
pytest.main([__file__, "-v"])
|
||||
|
||||
Reference in New Issue
Block a user