92 lines
2.6 KiB
Python
92 lines
2.6 KiB
Python
from __future__ import annotations
|
|
|
|
from telegram import BotCommand, MenuButtonCommands, MenuButtonDefault
|
|
|
|
from bot import BOT_COMMANDS, MpakoBot, commands_need_update
|
|
from config import Settings
|
|
|
|
|
|
class FakeCommandsBot:
|
|
def __init__(self) -> None:
|
|
self.commands: tuple[BotCommand, ...] = ()
|
|
self.menu = MenuButtonDefault()
|
|
self.set_commands_calls = 0
|
|
|
|
async def get_my_commands(self):
|
|
return self.commands
|
|
|
|
async def set_my_commands(self, commands, **kwargs):
|
|
self.commands = tuple(commands)
|
|
self.set_commands_calls += 1
|
|
return True
|
|
|
|
async def get_chat_menu_button(self):
|
|
return self.menu
|
|
|
|
async def set_chat_menu_button(self, menu_button=None, **kwargs):
|
|
self.menu = menu_button
|
|
return True
|
|
|
|
|
|
def test_commands_need_update() -> None:
|
|
assert commands_need_update(BOT_COMMANDS, BOT_COMMANDS) is False
|
|
assert commands_need_update((), BOT_COMMANDS) is True
|
|
|
|
|
|
async def test_setup_commands_sets_commands_and_menu_once() -> None:
|
|
bot = MpakoBot(Settings(bot_token=""))
|
|
fake = FakeCommandsBot()
|
|
bot._bot = fake # type: ignore[assignment]
|
|
|
|
await bot._setup_commands()
|
|
assert fake.commands == BOT_COMMANDS
|
|
assert isinstance(fake.menu, MenuButtonCommands)
|
|
assert fake.set_commands_calls == 1
|
|
|
|
await bot._setup_commands()
|
|
assert fake.set_commands_calls == 1
|
|
|
|
|
|
def test_settings_command_is_not_shadowed_by_settings_attribute() -> None:
|
|
bot = MpakoBot(Settings(bot_token=""))
|
|
assert callable(bot._settings_command)
|
|
|
|
|
|
def test_quality_keyboard_marks_standard() -> None:
|
|
keyboard = MpakoBot._settings_keyboard("standard", 12)
|
|
rows = keyboard.inline_keyboard
|
|
|
|
assert [row[0].text for row in rows[:2]] == [
|
|
"Стандартная ✅",
|
|
"Улучшенная",
|
|
]
|
|
assert [row[0].callback_data for row in rows[:2]] == [
|
|
"quality:standard",
|
|
"quality:improved",
|
|
]
|
|
assert [button.text for button in rows[2]] == [
|
|
"8 шагов",
|
|
"10 шагов",
|
|
"12 шагов ✅",
|
|
]
|
|
assert [button.callback_data for button in rows[2]] == [
|
|
"steps:8",
|
|
"steps:10",
|
|
"steps:12",
|
|
]
|
|
|
|
|
|
def test_quality_keyboard_marks_improved_and_steps() -> None:
|
|
keyboard = MpakoBot._settings_keyboard("improved", 10)
|
|
rows = keyboard.inline_keyboard
|
|
|
|
assert [row[0].text for row in rows[:2]] == [
|
|
"Стандартная",
|
|
"Улучшенная ✅",
|
|
]
|
|
assert [button.text for button in rows[2]] == [
|
|
"8 шагов",
|
|
"10 шагов ✅",
|
|
"12 шагов",
|
|
]
|