domovoy_bot/tests/functional_sanity.py

38 lines
1.5 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.

import sys
import os
import asyncio
from pathlib import Path
# Добавляем путь к проекту
project_root = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(project_root))
from sqlalchemy import select
from database.db import AsyncSessionLocal
from database.models import User, Event
async def run_functional_tests():
print("=== 🧪 ФУНКЦИОНАЛЬНЫЕ ТЕСТЫ: ДОМОВОЙ БОТ ===")
try:
async with AsyncSessionLocal() as session:
# Тест 1: Проверка связи с БД
print("[*] Тест 1: Подключение к БД...")
result = await session.execute(select(User).limit(1))
user = result.scalar_one_or_none()
print(f"✅ Успешно. Найдено пользователей: {'1+' if user else '0'}")
# Тест 2: Проверка модели Событий
print("[*] Тест 2: Доступ к данным событий...")
result = await session.execute(select(Event).limit(1))
evt = result.scalar_one_or_none()
print(f"✅ Успешно. Пример события: {evt.title if evt else 'Нет данных'}")
print("\n🏆 ВСЕ ФУНКЦИОНАЛЬНЫЕ ТЕСТЫ ПРОЙДЕНЫ!")
return True
except Exception as e:
print(f"\n❌ ОШИБКА ТЕСТИРОВАНИЯ: {e}")
return False
if __name__ == "__main__":
asyncio.run(run_functional_tests())