Pytest-набор: валидаторы, БД, интеграционные флоу
tests/ — 19 тестов: validators (телефон/имя/формат), database (услуги, FAQ, вакансии, отклики, админы, лиды, подписчики), интеграция (полный флоу заявки, карьера игрока, анти-флуд не роняет бота, доступ к админке). Работают на временной БД, реальную не трогают. Запуск: python -m pytest tests/ -q Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
# Корень проекта в путь импорта
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
if ROOT not in sys.path:
|
||||
sys.path.insert(0, ROOT)
|
||||
|
||||
from database import DatabaseManager
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def tmp_db(tmp_path):
|
||||
"""Чистая БД во временном файле."""
|
||||
return DatabaseManager(str(tmp_path / "test.db"))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def app(tmp_path, monkeypatch):
|
||||
"""Экземпляр бота в режиме эмуляции с временной БД и перехватом отправки."""
|
||||
import bot
|
||||
bot.config.VK_TOKEN = "your_vk_community_token_here" # эмулятор, без сети
|
||||
test_db = bot.DatabaseManager(str(tmp_path / "bot.db"))
|
||||
monkeypatch.setattr(bot, "db", test_db)
|
||||
application = bot.VKBotApplication()
|
||||
sent = []
|
||||
application.send_message = (
|
||||
lambda peer_id, message, keyboard=None, attachment=None, template=None:
|
||||
sent.append({"to": peer_id, "msg": message, "kb": keyboard})
|
||||
)
|
||||
application._sent = sent
|
||||
return application
|
||||
Reference in New Issue
Block a user