From e847a4b390005f31fe94bb76b17c1b2211293028 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 9 Oct 2026 19:42:35 +0200 Subject: [PATCH] feat: add generate-post button --- VERSION | 2 +- keyboards.py | 4 ++++ tests/test_keyboards.py | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index efd7ed4..376299e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.0+42 +0.1.0+43 diff --git a/keyboards.py b/keyboards.py index 755b921..c401c89 100644 --- a/keyboards.py +++ b/keyboards.py @@ -18,12 +18,14 @@ MAIN_MENU_BUTTON = "🏠 Главное меню" MAIN_MENU_VALUE = "__main_menu__" TRAINING_RESET_BUTTON = "🗑 Сбросить данные" TRAINING_RESET_VALUE = "__training_reset__" +POST_GENERATE_BUTTON = "✍️ Придумать пост" BUTTON_TEXT_MAP: dict[str, str] = { **MODE_BUTTONS, MAIN_MENU_BUTTON: MAIN_MENU_VALUE, "Главное меню": MAIN_MENU_VALUE, TRAINING_RESET_BUTTON: TRAINING_RESET_VALUE, + POST_GENERATE_BUTTON: "/post", } @@ -44,6 +46,8 @@ def mode_keyboard(mode: str) -> ReplyKeyboardMarkup: rows = [[KeyboardButton(text=MAIN_MENU_BUTTON)]] if mode == "training": rows.append([KeyboardButton(text=TRAINING_RESET_BUTTON)]) + elif mode == "generation": + rows.insert(0, [KeyboardButton(text=POST_GENERATE_BUTTON)]) return ReplyKeyboardMarkup( keyboard=rows, resize_keyboard=True, diff --git a/tests/test_keyboards.py b/tests/test_keyboards.py index 33ac5c3..da657d7 100644 --- a/tests/test_keyboards.py +++ b/tests/test_keyboards.py @@ -46,6 +46,9 @@ class ButtonTextTests(unittest.TestCase): keyboards.MAIN_MENU_VALUE, ) + def test_generate_post_button_maps_to_post_command(self): + self.assertEqual(keyboards.resolve_button_text(keyboards.POST_GENERATE_BUTTON), "/post") + def test_regular_text_is_not_treated_as_button(self): self.assertIsNone(keyboards.resolve_button_text("Напиши пост про запуск")) self.assertIsNone(keyboards.resolve_button_text("привет")) @@ -67,6 +70,8 @@ class KeyboardLayoutTests(unittest.TestCase): expected = [keyboards.MAIN_MENU_BUTTON] if mode == "training": expected.append(keyboards.TRAINING_RESET_BUTTON) + elif mode == "generation": + expected.insert(0, keyboards.POST_GENERATE_BUTTON) self.assertEqual(labels, expected, mode) def test_mode_entry_copy_uses_short_paragraphs(self): @@ -238,6 +243,16 @@ class ModeRoutingTests(unittest.IsolatedAsyncioTestCase): await bot.handle_command_text(message, state) classify.assert_awaited_once_with(message, "Напиши пост", state=state) + async def test_generate_post_button_runs_post_command(self): + message = _StubMessage(keyboards.POST_GENERATE_BUTTON) + state = _StubState("generation") + with ( + patch.object(bot, "notify_development_deploy", new=AsyncMock()), + patch.object(bot, "_classify_and_respond", new=AsyncMock()) as classify, + ): + await bot.handle_text(message, state) + classify.assert_awaited_once_with(message, "Напиши пост", state=state) + async def test_training_text_is_saved_as_note_without_entering_generation(self): message = _StubMessage("Кофейня в Калининграде для семей с детьми") with patch.object(bot, "_rebuild_account_profile", new=AsyncMock()) as rebuild: