fix linter, fix ci, fix tests
This commit is contained in:
@@ -3,17 +3,9 @@ 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,
|
||||
process_ban_user,
|
||||
process_unlock_user,
|
||||
return_to_main_menu,
|
||||
|
||||
save_voice_message,
|
||||
,
|
||||
)
|
||||
change_page, delete_voice_message, process_ban_user, process_unlock_user,
|
||||
return_to_main_menu, save_voice_message)
|
||||
from helper_bot.handlers.voice.constants import CALLBACK_DELETE, CALLBACK_SAVE
|
||||
|
||||
|
||||
@@ -407,7 +399,9 @@ class TestReturnToMainMenu:
|
||||
return call
|
||||
|
||||
@patch("helper_bot.handlers.callback.callback_handlers.get_reply_keyboard_admin")
|
||||
async def test_return_to_main_menu_deletes_and_answers(self, mock_keyboard, mock_call):
|
||||
async def test_return_to_main_menu_deletes_and_answers(
|
||||
self, mock_keyboard, mock_call
|
||||
):
|
||||
"""return_to_main_menu удаляет сообщение и отправляет приветствие."""
|
||||
mock_keyboard.return_value = MagicMock()
|
||||
|
||||
@@ -415,7 +409,10 @@ class TestReturnToMainMenu:
|
||||
|
||||
mock_call.message.delete.assert_called_once()
|
||||
mock_call.message.answer.assert_called_once()
|
||||
assert "админк" in mock_call.message.answer.call_args[0][0].lower() or "добро" in mock_call.message.answer.call_args[0][0].lower()
|
||||
assert (
|
||||
"админк" in mock_call.message.answer.call_args[0][0].lower()
|
||||
or "добро" in mock_call.message.answer.call_args[0][0].lower()
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@@ -450,7 +447,9 @@ class TestChangePage:
|
||||
db.get_last_users = AsyncMock(return_value=[("U1", 1), ("U2", 2)])
|
||||
return db
|
||||
|
||||
@patch("helper_bot.handlers.callback.callback_handlers.create_keyboard_with_pagination")
|
||||
@patch(
|
||||
"helper_bot.handlers.callback.callback_handlers.create_keyboard_with_pagination"
|
||||
)
|
||||
async def test_change_page_list_users_edits_markup(
|
||||
self, mock_keyboard, mock_call_list_users, mock_bot_db_for_page
|
||||
):
|
||||
@@ -462,9 +461,17 @@ class TestChangePage:
|
||||
mock_bot_db_for_page.get_last_users.assert_awaited_once_with(30)
|
||||
mock_call_list_users.bot.edit_message_reply_markup.assert_awaited_once()
|
||||
|
||||
@patch("helper_bot.handlers.callback.callback_handlers.get_banned_users_buttons", new_callable=AsyncMock)
|
||||
@patch("helper_bot.handlers.callback.callback_handlers.get_banned_users_list", new_callable=AsyncMock)
|
||||
@patch("helper_bot.handlers.callback.callback_handlers.create_keyboard_with_pagination")
|
||||
@patch(
|
||||
"helper_bot.handlers.callback.callback_handlers.get_banned_users_buttons",
|
||||
new_callable=AsyncMock,
|
||||
)
|
||||
@patch(
|
||||
"helper_bot.handlers.callback.callback_handlers.get_banned_users_list",
|
||||
new_callable=AsyncMock,
|
||||
)
|
||||
@patch(
|
||||
"helper_bot.handlers.callback.callback_handlers.create_keyboard_with_pagination"
|
||||
)
|
||||
async def test_change_page_banned_list_edits_text_and_markup(
|
||||
self, mock_keyboard, mock_get_list, mock_get_buttons, mock_bot_db_for_page
|
||||
):
|
||||
@@ -491,7 +498,9 @@ class TestChangePage:
|
||||
call.bot.edit_message_text.assert_awaited_once()
|
||||
call.bot.edit_message_reply_markup.assert_awaited_once()
|
||||
|
||||
async def test_change_page_invalid_page_number_answers_error(self, mock_bot_db_for_page):
|
||||
async def test_change_page_invalid_page_number_answers_error(
|
||||
self, mock_bot_db_for_page
|
||||
):
|
||||
"""change_page при некорректном номере страницы отвечает ошибкой."""
|
||||
call = Mock()
|
||||
call.data = "page_abc"
|
||||
@@ -533,11 +542,19 @@ class TestProcessBanUser:
|
||||
state.set_state = AsyncMock()
|
||||
return state
|
||||
|
||||
@patch("helper_bot.handlers.callback.callback_handlers.create_keyboard_for_ban_reason")
|
||||
@patch(
|
||||
"helper_bot.handlers.callback.callback_handlers.create_keyboard_for_ban_reason"
|
||||
)
|
||||
@patch("helper_bot.handlers.callback.callback_handlers.format_user_info")
|
||||
@patch("helper_bot.handlers.callback.callback_handlers.get_ban_service")
|
||||
async def test_process_ban_user_success_sets_state_await_details(
|
||||
self, mock_get_ban, mock_format, mock_keyboard, mock_call, mock_state, mock_bot_db_ban
|
||||
self,
|
||||
mock_get_ban,
|
||||
mock_format,
|
||||
mock_keyboard,
|
||||
mock_call,
|
||||
mock_state,
|
||||
mock_bot_db_ban,
|
||||
):
|
||||
"""process_ban_user при успехе переводит в AWAIT_BAN_DETAILS."""
|
||||
mock_ban = Mock()
|
||||
@@ -559,6 +576,7 @@ class TestProcessBanUser:
|
||||
):
|
||||
"""process_ban_user при UserNotFoundError возвращает в админ-меню."""
|
||||
from helper_bot.handlers.callback.exceptions import UserNotFoundError
|
||||
|
||||
mock_ban = Mock()
|
||||
mock_ban.ban_user = AsyncMock(side_effect=UserNotFoundError("not found"))
|
||||
mock_get_ban.return_value = mock_ban
|
||||
@@ -569,7 +587,9 @@ class TestProcessBanUser:
|
||||
mock_call.message.answer.assert_awaited_once()
|
||||
mock_state.set_state.assert_awaited_once_with("ADMIN")
|
||||
|
||||
async def test_process_ban_user_invalid_user_id_answers_error(self, mock_call, mock_state, mock_bot_db_ban):
|
||||
async def test_process_ban_user_invalid_user_id_answers_error(
|
||||
self, mock_call, mock_state, mock_bot_db_ban
|
||||
):
|
||||
"""process_ban_user при некорректном user_id отвечает ошибкой."""
|
||||
mock_call.data = "ban_abc"
|
||||
|
||||
@@ -599,12 +619,16 @@ class TestProcessUnlockUser:
|
||||
|
||||
mock_ban.unlock_user.assert_awaited_once_with("123")
|
||||
call.answer.assert_awaited_once()
|
||||
assert "username" in call.answer.call_args[0][0] or "разблокирован" in call.answer.call_args[0][0].lower()
|
||||
assert (
|
||||
"username" in call.answer.call_args[0][0]
|
||||
or "разблокирован" in call.answer.call_args[0][0].lower()
|
||||
)
|
||||
|
||||
@patch("helper_bot.handlers.callback.callback_handlers.get_ban_service")
|
||||
async def test_process_unlock_user_not_found_answers_error(self, mock_get_ban):
|
||||
"""process_unlock_user при UserNotFoundError отвечает что пользователь не найден."""
|
||||
from helper_bot.handlers.callback.exceptions import UserNotFoundError
|
||||
|
||||
call = Mock()
|
||||
call.data = "unlock_999"
|
||||
call.answer = AsyncMock()
|
||||
@@ -614,7 +638,9 @@ class TestProcessUnlockUser:
|
||||
|
||||
await process_unlock_user(call)
|
||||
|
||||
call.answer.assert_awaited_once_with(text="Пользователь не найден в базе", show_alert=True, cache_time=3)
|
||||
call.answer.assert_awaited_once_with(
|
||||
text="Пользователь не найден в базе", show_alert=True, cache_time=3
|
||||
)
|
||||
|
||||
async def test_process_unlock_user_invalid_user_id_answers_error(self):
|
||||
"""process_unlock_user при некорректном user_id отвечает ошибкой."""
|
||||
|
||||
Reference in New Issue
Block a user