Refactor imports across multiple files to improve code organization and readability.
All checks were successful
CI pipeline / Test & Code Quality (push) Successful in 34s
All checks were successful
CI pipeline / Test & Code Quality (push) Successful in 34s
This commit is contained in:
@@ -13,10 +13,10 @@ if str(_project_root) not in sys.path:
|
||||
import pytest
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from aiogram.types import Chat, Message, User
|
||||
from database.async_db import AsyncBotDB
|
||||
|
||||
# Импортируем моки в самом начале
|
||||
import tests.mocks
|
||||
from database.async_db import AsyncBotDB
|
||||
|
||||
# Настройка pytest-asyncio
|
||||
pytest_plugins = ("pytest_asyncio",)
|
||||
|
||||
@@ -3,6 +3,7 @@ import tempfile
|
||||
from datetime import datetime
|
||||
|
||||
import pytest
|
||||
|
||||
from database.models import UserMessage
|
||||
from database.repositories.message_repository import MessageRepository
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ from datetime import datetime
|
||||
from unittest.mock import AsyncMock, Mock
|
||||
|
||||
import pytest
|
||||
|
||||
from database.models import MessageContentLink, PostContent, TelegramPost
|
||||
from database.repositories.post_repository import PostRepository
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from helper_bot.handlers.admin.dependencies import (
|
||||
AdminAccessMiddleware,
|
||||
get_bot_db,
|
||||
|
||||
@@ -7,6 +7,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||
import pytest
|
||||
from aiogram import types
|
||||
from aiogram.fsm.context import FSMContext
|
||||
|
||||
from helper_bot.handlers.admin.admin_handlers import (
|
||||
admin_panel,
|
||||
cancel_ban_process,
|
||||
|
||||
@@ -3,6 +3,7 @@ from datetime import datetime
|
||||
from unittest.mock import AsyncMock, MagicMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from database.models import Admin
|
||||
from database.repositories.admin_repository import AdminRepository
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from helper_bot.handlers.admin.exceptions import AdminError
|
||||
from helper_bot.handlers.admin.utils import (
|
||||
escape_html,
|
||||
|
||||
@@ -6,6 +6,7 @@ import asyncio
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from helper_bot.middlewares.album_middleware import AlbumGetter, AlbumMiddleware
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from database.async_db import AsyncBotDB
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ from datetime import datetime
|
||||
from unittest.mock import AsyncMock, MagicMock, Mock, mock_open, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from helper_bot.handlers.voice.exceptions import DatabaseError, FileOperationError
|
||||
from helper_bot.handlers.voice.services import AudioFileService
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ from datetime import datetime, timezone
|
||||
from unittest.mock import AsyncMock, MagicMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from database.models import AudioListenRecord, AudioMessage, AudioModerate
|
||||
from database.repositories.audio_repository import AudioRepository
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ from datetime import datetime, timezone
|
||||
from unittest.mock import AsyncMock, MagicMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from database.repositories.audio_repository import AudioRepository
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from helper_bot.handlers.private.services import AutoModerationService, BotSettings
|
||||
|
||||
|
||||
@@ -108,9 +109,7 @@ class TestAutoModerationService:
|
||||
assert result == "manual"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_check_auto_action_publish_at_exact_threshold(
|
||||
self, service, mock_db
|
||||
):
|
||||
async def test_check_auto_action_publish_at_exact_threshold(self, service, mock_db):
|
||||
"""Тест: возвращает publish когда score равен порогу."""
|
||||
mock_db.get_auto_moderation_settings.return_value = {
|
||||
"auto_publish_enabled": True,
|
||||
@@ -124,9 +123,7 @@ class TestAutoModerationService:
|
||||
assert result == "publish"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_check_auto_action_decline_at_exact_threshold(
|
||||
self, service, mock_db
|
||||
):
|
||||
async def test_check_auto_action_decline_at_exact_threshold(self, service, mock_db):
|
||||
"""Тест: возвращает decline когда score равен порогу."""
|
||||
mock_db.get_auto_moderation_settings.return_value = {
|
||||
"auto_publish_enabled": False,
|
||||
|
||||
@@ -4,6 +4,7 @@ from datetime import datetime, timedelta, timezone
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from helper_bot.utils.auto_unban_scheduler import AutoUnbanScheduler
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ from datetime import datetime, timedelta, timezone
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from helper_bot.utils.auto_unban_scheduler import (
|
||||
AutoUnbanScheduler,
|
||||
get_auto_unban_scheduler,
|
||||
|
||||
@@ -3,6 +3,7 @@ from datetime import datetime
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from database.models import BlacklistHistoryRecord
|
||||
from database.repositories.blacklist_history_repository import (
|
||||
BlacklistHistoryRepository,
|
||||
|
||||
@@ -6,6 +6,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from aiogram.types import CallbackQuery, Message
|
||||
|
||||
from helper_bot.middlewares.blacklist_middleware import BlacklistMiddleware
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ from datetime import datetime
|
||||
from unittest.mock import AsyncMock, MagicMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from database.models import BlacklistUser
|
||||
from database.repositories.blacklist_repository import BlacklistRepository
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from database.repositories.bot_settings_repository import BotSettingsRepository
|
||||
|
||||
|
||||
@@ -115,11 +116,14 @@ class TestBotSettingsRepository:
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_auto_moderation_settings(self, repository):
|
||||
"""Тест получения всех настроек авто-модерации."""
|
||||
with patch.object(
|
||||
repository, "get_bool_setting", new_callable=AsyncMock
|
||||
) as mock_bool, patch.object(
|
||||
repository, "get_float_setting", new_callable=AsyncMock
|
||||
) as mock_float:
|
||||
with (
|
||||
patch.object(
|
||||
repository, "get_bool_setting", new_callable=AsyncMock
|
||||
) as mock_bool,
|
||||
patch.object(
|
||||
repository, "get_float_setting", new_callable=AsyncMock
|
||||
) as mock_float,
|
||||
):
|
||||
mock_bool.side_effect = [True, False]
|
||||
mock_float.side_effect = [0.8, 0.4]
|
||||
|
||||
@@ -133,11 +137,14 @@ class TestBotSettingsRepository:
|
||||
@pytest.mark.asyncio
|
||||
async def test_toggle_auto_publish(self, repository):
|
||||
"""Тест переключения авто-публикации."""
|
||||
with patch.object(
|
||||
repository, "get_bool_setting", new_callable=AsyncMock
|
||||
) as mock_get, patch.object(
|
||||
repository, "set_bool_setting", new_callable=AsyncMock
|
||||
) as mock_set:
|
||||
with (
|
||||
patch.object(
|
||||
repository, "get_bool_setting", new_callable=AsyncMock
|
||||
) as mock_get,
|
||||
patch.object(
|
||||
repository, "set_bool_setting", new_callable=AsyncMock
|
||||
) as mock_set,
|
||||
):
|
||||
mock_get.return_value = False
|
||||
|
||||
result = await repository.toggle_auto_publish()
|
||||
@@ -148,11 +155,14 @@ class TestBotSettingsRepository:
|
||||
@pytest.mark.asyncio
|
||||
async def test_toggle_auto_decline(self, repository):
|
||||
"""Тест переключения авто-отклонения."""
|
||||
with patch.object(
|
||||
repository, "get_bool_setting", new_callable=AsyncMock
|
||||
) as mock_get, patch.object(
|
||||
repository, "set_bool_setting", new_callable=AsyncMock
|
||||
) as mock_set:
|
||||
with (
|
||||
patch.object(
|
||||
repository, "get_bool_setting", new_callable=AsyncMock
|
||||
) as mock_get,
|
||||
patch.object(
|
||||
repository, "set_bool_setting", new_callable=AsyncMock
|
||||
) as mock_set,
|
||||
):
|
||||
mock_get.return_value = True
|
||||
|
||||
result = await repository.toggle_auto_decline()
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from helper_bot.handlers.callback.dependency_factory import (
|
||||
get_ban_service,
|
||||
get_post_publish_service,
|
||||
|
||||
@@ -3,6 +3,7 @@ from datetime import datetime
|
||||
from unittest.mock import AsyncMock, MagicMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from helper_bot.handlers.callback.callback_handlers import (
|
||||
change_page,
|
||||
delete_voice_message,
|
||||
|
||||
@@ -6,6 +6,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from aiogram.types import CallbackQuery, Message
|
||||
|
||||
from helper_bot.handlers.callback.constants import CONTENT_TYPE_MEDIA_GROUP
|
||||
from helper_bot.handlers.callback.exceptions import (
|
||||
PostNotFoundError,
|
||||
|
||||
@@ -6,6 +6,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from aiogram import types
|
||||
|
||||
from helper_bot.handlers.group.decorators import error_handler as group_error_handler
|
||||
from helper_bot.handlers.private.decorators import (
|
||||
error_handler as private_error_handler,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from helper_bot.services.scoring.deepseek_service import DeepSeekService
|
||||
from helper_bot.services.scoring.exceptions import (
|
||||
DeepSeekAPIError,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from helper_bot.middlewares.dependencies_middleware import DependenciesMiddleware
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ from unittest.mock import AsyncMock, MagicMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
from aiogram import types
|
||||
|
||||
from helper_bot.utils.helper_func import (
|
||||
add_in_db_media,
|
||||
add_in_db_media_mediagroup,
|
||||
|
||||
@@ -7,6 +7,7 @@ from aiogram.types import (
|
||||
KeyboardButton,
|
||||
ReplyKeyboardMarkup,
|
||||
)
|
||||
|
||||
from database.async_db import AsyncBotDB
|
||||
from helper_bot.filters.main import ChatTypeFilter
|
||||
from helper_bot.keyboards.keyboards import (
|
||||
|
||||
@@ -6,6 +6,7 @@ import asyncio
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from helper_bot.main import start_bot, start_bot_with_retry
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ from datetime import datetime
|
||||
from unittest.mock import AsyncMock, MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from database.models import UserMessage
|
||||
from database.repositories.message_repository import MessageRepository
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import tempfile
|
||||
from datetime import datetime
|
||||
|
||||
import pytest
|
||||
|
||||
from database.models import UserMessage
|
||||
from database.repositories.message_repository import MessageRepository
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from aiogram.types import Message
|
||||
|
||||
from helper_bot.middlewares.metrics_middleware import (
|
||||
DatabaseMetricsMiddleware,
|
||||
ErrorMetricsMiddleware,
|
||||
|
||||
@@ -3,6 +3,7 @@ from datetime import datetime
|
||||
from unittest.mock import AsyncMock, MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from database.models import MessageContentLink, PostContent, TelegramPost
|
||||
from database.repositories.post_repository import PostRepository
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import tempfile
|
||||
from datetime import datetime
|
||||
|
||||
import pytest
|
||||
|
||||
from database.models import MessageContentLink, PostContent, TelegramPost
|
||||
from database.repositories.post_repository import PostRepository
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ from unittest.mock import AsyncMock, MagicMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
from aiogram import types
|
||||
|
||||
from database.models import TelegramPost, User
|
||||
from helper_bot.handlers.private.services import BotSettings, PostService
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from helper_bot.services.scoring.exceptions import (
|
||||
InsufficientExamplesError,
|
||||
ScoringError,
|
||||
|
||||
@@ -6,6 +6,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from aiogram.types import CallbackQuery, Message, Update
|
||||
|
||||
from helper_bot.middlewares.rate_limit_middleware import RateLimitMiddleware
|
||||
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ from collections import deque
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from helper_bot.utils.rate_limit_monitor import (
|
||||
RateLimitMonitor,
|
||||
RateLimitStats,
|
||||
|
||||
@@ -7,6 +7,7 @@ import time
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from helper_bot.config.rate_limit_config import RateLimitSettings, get_rate_limit_config
|
||||
from helper_bot.utils.rate_limit_monitor import (
|
||||
RateLimitMonitor,
|
||||
|
||||
@@ -3,6 +3,7 @@ from unittest.mock import AsyncMock, Mock, patch
|
||||
import pytest
|
||||
from aiogram import types
|
||||
from aiogram.fsm.context import FSMContext
|
||||
|
||||
from helper_bot.handlers.admin.exceptions import (
|
||||
InvalidInputError,
|
||||
UserAlreadyBannedError,
|
||||
|
||||
@@ -5,6 +5,7 @@ from unittest.mock import AsyncMock, MagicMock, Mock
|
||||
import pytest
|
||||
from aiogram import types
|
||||
from aiogram.fsm.context import FSMContext
|
||||
|
||||
from helper_bot.handlers.group.constants import ERROR_MESSAGES, FSM_STATES
|
||||
from helper_bot.handlers.group.exceptions import (
|
||||
NoReplyToMessageError,
|
||||
|
||||
@@ -5,6 +5,7 @@ from unittest.mock import AsyncMock, MagicMock, Mock, patch
|
||||
import pytest
|
||||
from aiogram import types
|
||||
from aiogram.fsm.context import FSMContext
|
||||
|
||||
from helper_bot.handlers.private.constants import BUTTON_TEXTS, FSM_STATES
|
||||
from helper_bot.handlers.private.private_handlers import (
|
||||
PrivateHandlers,
|
||||
|
||||
@@ -7,6 +7,7 @@ from pathlib import Path
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from helper_bot.utils.s3_storage import S3StorageService
|
||||
|
||||
|
||||
|
||||
@@ -137,6 +137,7 @@ class TestVectorStore:
|
||||
"""Создает VectorStore для тестов."""
|
||||
try:
|
||||
import numpy as np
|
||||
|
||||
from helper_bot.services.scoring.vector_store import VectorStore
|
||||
|
||||
return VectorStore(vector_dim=768, max_examples=100)
|
||||
|
||||
@@ -6,6 +6,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from aiohttp import web
|
||||
|
||||
from helper_bot.server_prometheus import (
|
||||
MetricsServer,
|
||||
start_metrics_server,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from helper_bot.middlewares.text_middleware import BulkTextMiddleware
|
||||
|
||||
|
||||
|
||||
@@ -2,8 +2,9 @@ import os
|
||||
from datetime import datetime
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
import helper_bot.utils.messages as messages # Import for patching constants
|
||||
import pytest
|
||||
|
||||
import helper_bot.utils.messages as messages # Import for patching constants
|
||||
from database.async_db import AsyncBotDB
|
||||
from helper_bot.utils.base_dependency_factory import (
|
||||
BaseDependencyFactory,
|
||||
|
||||
@@ -3,6 +3,7 @@ from pathlib import Path
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from helper_bot.handlers.voice.exceptions import AudioProcessingError, VoiceMessageError
|
||||
from helper_bot.handlers.voice.services import VoiceBotService
|
||||
from helper_bot.handlers.voice.utils import (
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from helper_bot.handlers.voice.constants import (
|
||||
BTN_LISTEN,
|
||||
BTN_SPEAK,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from helper_bot.handlers.voice.exceptions import (
|
||||
AudioProcessingError,
|
||||
VoiceBotError,
|
||||
|
||||
@@ -3,6 +3,7 @@ from unittest.mock import AsyncMock, MagicMock, Mock, patch
|
||||
import pytest
|
||||
from aiogram import types
|
||||
from aiogram.fsm.context import FSMContext
|
||||
|
||||
from helper_bot.handlers.voice.constants import STATE_STANDUP_WRITE, STATE_START
|
||||
from helper_bot.handlers.voice.voice_handler import VoiceHandlers
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ from pathlib import Path
|
||||
from unittest.mock import AsyncMock, MagicMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from helper_bot.handlers.voice.exceptions import AudioProcessingError, VoiceMessageError
|
||||
from helper_bot.handlers.voice.services import VoiceBotService
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
from aiogram import types
|
||||
|
||||
from helper_bot.handlers.voice.utils import (
|
||||
format_time_ago,
|
||||
get_last_message_text,
|
||||
|
||||
Reference in New Issue
Block a user