Files
telegram-helper-bot/tests/mocks.py
Andrey 8f338196b7 Refactor Docker and configuration files for improved structure and functionality
- Updated `.dockerignore` to include additional development and temporary files, enhancing build efficiency.
- Modified `.gitignore` to remove unnecessary entries and streamline ignored files.
- Enhanced `docker-compose.yml` with health checks, resource limits, and improved environment variable handling for better service management.
- Refactored `Dockerfile.bot` to utilize a multi-stage build for optimized image size and security.
- Improved `Makefile` with new commands for deployment, migration, and backup, along with enhanced help documentation.
- Updated `requirements.txt` to include new dependencies for environment variable management.
- Refactored metrics handling in the bot to ensure proper initialization and collection.
2025-08-29 23:15:06 +03:00

42 lines
1.3 KiB
Python

"""
Моки для тестового окружения
"""
import sys
import os
from unittest.mock import Mock, patch
# Патчим загрузку настроек до импорта модулей
def setup_test_mocks():
"""Настройка моков для тестов"""
# Мокаем os.getenv
mock_env_vars = {
'BOT_TOKEN': 'test_token_123',
'LISTEN_BOT_TOKEN': '',
'TEST_BOT_TOKEN': '',
'PREVIEW_LINK': 'False',
'MAIN_PUBLIC': '@test',
'GROUP_FOR_POSTS': '-1001234567890',
'GROUP_FOR_MESSAGE': '-1001234567891',
'GROUP_FOR_LOGS': '-1001234567893',
'IMPORTANT_LOGS': '-1001234567894',
'TEST_GROUP': '-1001234567895',
'LOGS': 'True',
'TEST': 'False',
'DATABASE_PATH': 'database/test.db'
}
def mock_getenv(key, default=None):
return mock_env_vars.get(key, default)
env_patcher = patch('os.getenv', side_effect=mock_getenv)
env_patcher.start()
# Мокаем BotDB
mock_db = Mock()
db_patcher = patch('helper_bot.utils.base_dependency_factory.BotDB', mock_db)
db_patcher.start()
return env_patcher, db_patcher
# Настраиваем моки при импорте модуля
env_patcher, db_patcher = setup_test_mocks()