feat: add generate-post button

This commit is contained in:
admin committed 2026-10-09 19:42:35 +02:00
1 parent 6f8741cf3c
commit e847a4b390
3 files changed
+20 -1

No files matched your search

+1 -1
View File
@@ -1 +1 @@
0.1.0+42
0.1.0+43
+4
View File
@@ -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,
+15
View File
@@ -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: