From 16e50e991b6e8065a429bc70ea92ece075f09a29 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Fri, 1 Dec 2017 12:53:03 -0800 Subject: [PATCH] bot tests: Add StubBotTestCase.verify_reply(). --- zulip_bots/zulip_bots/test_lib.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/zulip_bots/zulip_bots/test_lib.py b/zulip_bots/zulip_bots/test_lib.py index 7b39003..80881a3 100755 --- a/zulip_bots/zulip_bots/test_lib.py +++ b/zulip_bots/zulip_bots/test_lib.py @@ -59,6 +59,17 @@ class StubBotHandler: # type: (Dict[str, Any]) -> None self.message_server.update(message) + def unique_reply(self): + # type: () -> Dict[str, Any] + responses = [ + message + for (method, message) + in self.transcript + if method == 'send_reply' + ] + self.ensure_unique_response(responses) + return responses[0] + def unique_response(self): # type: () -> Dict[str, Any] responses = [ @@ -85,6 +96,22 @@ class StubBotTestCase(TestCase): bot_name = '' + def verify_reply(self, request, response): + # type: (str, str) -> None + + # Start a new message handler for the full conversation. + bot = get_bot_message_handler(self.bot_name) + bot_handler = StubBotHandler() + + message = dict( + sender_email='foo@example.com', + content=request, + ) + bot_handler.reset_transcript() + bot.handle_message(message, bot_handler) + reply = bot_handler.unique_reply() + self.assertEqual(response, reply['content']) + def verify_dialog(self, conversation): # type: (List[Tuple[str, str]]) -> None