Files
telegram-helper-bot/tests/test_monitor.py
Andrey e17a9f9c29 Remove pytest configuration file and update test files for async compatibility
- Deleted `pytest.ini` to streamline test configuration.
- Added `pytest_asyncio` plugin support in `conftest.py`.
- Marked `test_monitor` as an async test to ensure proper execution in an asynchronous context.
2025-08-27 22:37:17 +03:00

84 lines
2.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""
Тестовый скрипт для проверки модуля мониторинга сервера
"""
import pytest
import asyncio
import sys
import os
# Добавляем путь к проекту
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from helper_bot.server_monitor import ServerMonitor
class MockBot:
"""Мок объект бота для тестирования"""
async def send_message(self, chat_id, text, parse_mode=None):
print(f"\n{'='*60}")
print(f"Отправка в чат: {chat_id}")
print(f"Текст сообщения:")
print(text)
print(f"{'='*60}\n")
@pytest.mark.asyncio
async def test_monitor():
"""Тестирование модуля мониторинга"""
print("🧪 Тестирование модуля мониторинга сервера")
print("=" * 60)
# Создаем мок бота
mock_bot = MockBot()
# Создаем монитор
monitor = ServerMonitor(
bot=mock_bot,
group_for_logs="-123456789",
important_logs="-987654321"
)
print("📊 Получение информации о системе...")
system_info = monitor.get_system_info()
if system_info:
print("✅ Информация о системе получена успешно")
print(f"CPU: {system_info['cpu_percent']}%")
print(f"RAM: {system_info['ram_percent']}%")
print(f"Disk: {system_info['disk_percent']}%")
print(f"Uptime: {system_info['system_uptime']}")
print("\n🤖 Проверка статуса процессов...")
voice_status, voice_uptime = monitor.check_process_status('voice_bot')
helper_status, helper_uptime = monitor.check_process_status('helper_bot')
print(f"Voice Bot: {voice_status} - {voice_uptime}")
print(f"Helper Bot: {helper_status} - {helper_uptime}")
print("\n📝 Тестирование отправки статуса...")
await monitor.send_status_message(system_info)
print("\n🚨 Тестирование отправки алерта...")
await monitor.send_alert_message(
"Использование CPU",
85.5,
"Нагрузка за 1 мин: 2.5"
)
print("\n✅ Тестирование отправки сообщения о восстановлении...")
await monitor.send_recovery_message(
"Использование CPU",
70.0,
85.5
)
else:
print("Не удалось получить информацию о системе")
print("\n🎯 Тестирование завершено!")
if __name__ == "__main__":
asyncio.run(test_monitor())