feat: add context-aware VK keyboards
This commit is contained in:
1 parent
4dab6e8624
commit
dfc5e2826a
6 files changed
+91
-8
No files matched your search
@@ -1,9 +1,11 @@
|
||||
import unittest
|
||||
import json
|
||||
|
||||
from app.belki.vk_bot import (
|
||||
HELP_TEXT,
|
||||
build_message_request,
|
||||
parse_text_command,
|
||||
BelkiBot,
|
||||
)
|
||||
|
||||
|
||||
@@ -28,6 +30,15 @@ class VkBotTests(unittest.TestCase):
|
||||
self.assertEqual(request["access_token"], "secret")
|
||||
self.assertEqual(request["v"], "5.199")
|
||||
|
||||
def test_message_request_serializes_vk_keyboard(self):
|
||||
keyboard = {"one_time": False, "buttons": []}
|
||||
request = build_message_request(123, "Меню", "secret", "5.199", random_id=77, keyboard=keyboard)
|
||||
self.assertEqual(json.loads(request["keyboard"]), keyboard)
|
||||
|
||||
def test_button_payload_maps_to_command(self):
|
||||
self.assertEqual(BelkiBot._button_text({"payload": "menu:lu"}), "/лу")
|
||||
self.assertEqual(BelkiBot._button_text({"payload": '{"command":"confirm:yes"}'}), "да")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -143,6 +143,17 @@ class VkConversationTests(unittest.TestCase):
|
||||
dialog.handle(502, answer)
|
||||
self.assertIn("несамостоятельно", dialog.handle(502, "несам").lower())
|
||||
|
||||
def test_keyboard_changes_with_dialog_state(self):
|
||||
dialog = BelkiDialog()
|
||||
menu = dialog.keyboard_for(503)
|
||||
labels = [button["action"]["label"] for row in menu["buttons"] for button in row]
|
||||
self.assertIn("Прокачка ЛУ", labels)
|
||||
dialog.handle(503, "/лу")
|
||||
for answer in ("15.08", "11:00", "11:20", "Дикая Вишня [1604614]", "Серолап [1617140]"):
|
||||
dialog.handle(503, answer)
|
||||
labels = [button["action"]["label"] for row in dialog.keyboard_for(503)["buttons"] for button in row]
|
||||
self.assertEqual(labels[:2], ["Сам", "Несам"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user