diff --git a/app/belki/vk_bot.py b/app/belki/vk_bot.py index 4c33057..22fb5df 100644 --- a/app/belki/vk_bot.py +++ b/app/belki/vk_bot.py @@ -47,6 +47,8 @@ class VkError(RuntimeError): def _person(value: str) -> tuple[str, int]: + # Users often copy the example sentence together with its final period. + value = value.strip().rstrip(".!?").strip() match = _PERSON_RE.fullmatch(value) if not match: raise ValueError("Укажите имя и ID в формате Имя [12345]") diff --git a/tests/test_vk_conversation.py b/tests/test_vk_conversation.py index 0a1874b..5117988 100644 --- a/tests/test_vk_conversation.py +++ b/tests/test_vk_conversation.py @@ -13,8 +13,8 @@ class VkConversationTests(unittest.TestCase): return dialog.handle(actor_id, "готово") def test_help_is_a_neutral_faq(self): - self.assertIn("Беличья нора — помощь", HELP_TEXT) - self.assertIn("Как отправить данные", HELP_TEXT) + self.assertIn("Беличья нора", HELP_TEXT) + self.assertIn("Два способа ввести данные", HELP_TEXT) self.assertIn("/отмена", HELP_TEXT) self.assertNotIn("Для детей", HELP_TEXT) @@ -41,6 +41,16 @@ class VkConversationTests(unittest.TestCase): self.assertIn("самостоятель", response.lower()) self.assertEqual(dialog._states[78]["extra_kittens"], [("Малыш", 123456, "самостоятельно")]) + def test_comma_separated_example_accepts_trailing_period(self): + dialog = BelkiDialog() + dialog.handle(79, "/лу") + for answer in ("15.08", "11:00", "16:41", "Дикая Вишня [1604614]"): + dialog.handle(79, answer) + response = dialog.handle(79, "Беззубик [1566767], Малыш [123456].") + self.assertIn("самостоятель", response.lower()) + self.assertEqual(dialog._states[79]["kitten_id"], 1566767) + self.assertEqual(dialog._states[79]["extra_kittens"][0][1], 123456) + def test_bulk_input_is_detected_and_confirmed(self): dialog = BelkiDialog() confirmation = dialog.handle(