This repository was archived by the owner on Jul 9, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathtest_admin_functions.py
More file actions
135 lines (101 loc) · 5.26 KB
/
Copy pathtest_admin_functions.py
File metadata and controls
135 lines (101 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python3
"""
Тестовый скрипт для проверки админских функций
"""
import asyncio
import os
from dotenv import load_dotenv
from db.database import Database
from utils.credentials import CredentialGenerator
from commands.admin import AdminCommands
from pterodactyl_api import PterodactylAPI
# Загружаем переменные окружения
load_dotenv()
async def test_credentials_generator():
"""Тест генератора учетных данных"""
print("🧪 Тестирование генератора учетных данных...")
# Тестируем генерацию учетных данных
credentials = CredentialGenerator.generate_credentials(123456789, "TestUser")
print(f"✅ Сгенерированные учетные данные:")
print(f"Username: {credentials['username']}")
print(f"Password: {credentials['password']}")
print(f"Email: {credentials['email']}")
print(f"Telegram ID: {credentials['telegram_id']}")
# Проверяем хеширование пароля
hashed = CredentialGenerator.hash_password(credentials['password'])
print(f"✅ Хеш пароля: {hashed[:20]}...")
# Проверяем верификацию
is_valid = CredentialGenerator.verify_password(credentials['password'], hashed)
print(f"✅ Верификация пароля: {is_valid}")
print()
async def test_database_functions():
"""Тест функций базы данных"""
print("🧪 Тестирование функций базы данных...")
db = Database()
# Создаем тестового пользователя
user_id = 999999999
db.create_user(user_id, "testuser", "Test", "User")
# Получаем статистику
all_users = db.get_all_users()
banned_users = db.get_banned_users()
all_servers = db.get_all_servers()
print(f"✅ Всего пользователей: {len(all_users)}")
print(f"✅ Заблокированных пользователей: {len(banned_users)}")
print(f"✅ Всего серверов: {len(all_servers)}")
# Тестируем создание сервера с учетными данными
credentials = CredentialGenerator.generate_credentials(user_id, "TestUser")
success = db.create_server_with_credentials(user_id, "test_server_123", "Test Server", credentials)
print(f"✅ Создание сервера с учетными данными: {success}")
# Получаем логи
logs = db.get_recent_action_logs(5)
print(f"✅ Последние логи: {len(logs)} записей")
print()
async def test_admin_commands():
"""Тест админских команд"""
print("🧪 Тестирование админских команд...")
db = Database()
pterodactyl_api = None # Не тестируем API в этом скрипте
admin_commands = AdminCommands(db, pterodactyl_api)
# Тестируем статистику
stats = admin_commands.get_statistics()
print(f"✅ Статистика получена: {bool(stats)}")
if stats:
print(f" - Всего пользователей: {stats.get('total_users', 0)}")
print(f" - Активных пользователей: {stats.get('active_users', 0)}")
print(f" - Всего серверов: {stats.get('total_servers', 0)}")
# Тестируем логи
logs = admin_commands.get_recent_logs(5)
print(f"✅ Логи получены: {len(logs)} записей")
print()
async def test_pterodactyl_api():
"""Тест Pterodactyl API"""
print("🧪 Тестирование Pterodactyl API...")
api_url = os.getenv("PTERODACTYL_URL", "https://panel.cloudspb.ru")
api_token = os.getenv("PTERODACTYL_TOKEN")
if not api_token:
print("❌ PTERODACTYL_TOKEN не найден, пропускаем тест API")
return
try:
api = PterodactylAPI(api_url, api_token)
# Тестируем проверку пользователя
test_email = "test@example.com"
user_exists = await api.check_user_exists(test_email)
print(f"✅ Проверка пользователя {test_email}: {user_exists}")
# Тестируем генерацию учетных данных для API
credentials = CredentialGenerator.generate_credentials(123456789, "TestUser")
print(f"✅ Учетные данные для API:")
print(f" - Username: {credentials['username']}")
print(f" - Email: {credentials['email']}")
except Exception as e:
print(f"❌ Ошибка тестирования API: {e}")
print()
async def main():
"""Основная функция тестирования"""
print("🚀 Запуск тестирования админских функций...\n")
await test_credentials_generator()
await test_database_functions()
await test_admin_commands()
await test_pterodactyl_api()
print("✅ Тестирование завершено!")
if __name__ == "__main__":
asyncio.run(main())