diff --git a/zulip_bots/zulip_bots/zulip_bot_output.py b/zulip_bots/zulip_bots/zulip_bot_output.py index c9a5796..064a762 100644 --- a/zulip_bots/zulip_bots/zulip_bot_output.py +++ b/zulip_bots/zulip_bots/zulip_bot_output.py @@ -80,7 +80,7 @@ def main(): provision_bot(bot_dir, options.force) lib_module = import_module('zulip_bots.bots.{bot}.{bot}'.format(bot=bot_name)) - message = {'content': options.message} + message = {'content': options.message, 'sender_email': 'foo_sender@zulip.com'} message_handler = lib_module.handler_class() with patch('zulip_bots.lib.ExternalBotHandler') as mock_bot_handler: @@ -100,17 +100,28 @@ def main(): return dict(config.items(section)) mock_bot_handler.get_config_info = get_config_info - if (hasattr(message_handler, 'initialize') and callable(message_handler.initialize)): + if hasattr(message_handler, 'initialize') and callable(message_handler.initialize): message_handler.initialize(mock_bot_handler) mock_bot_handler.send_reply = MagicMock() + mock_bot_handler.send_message = MagicMock() message_handler.handle_message( message=message, bot_handler=mock_bot_handler, state_handler=StateHandler() ) print("On sending ", options.name, " bot the following message:\n\"", options.message, "\"") - print("\nThe bot gives the following output message:\n\"", list(mock_bot_handler.send_reply.call_args)[0][1], "\"") + + # send_reply and send_message have slightly arguments; the + # following takes that into account. + # send_reply(original_message, response) + # send_message(response_message) + if mock_bot_handler.send_reply.called: + print("\nThe bot gives the following output message:\n\"", list(mock_bot_handler.send_reply.call_args)[0][1], "\"") + elif mock_bot_handler.send_message.called: + print("\nThe bot sends the following output to zulip:\n\"", list(mock_bot_handler.send_message.call_args)[0][0], "\"") + else: + print("\nThe bot sent no reply.") if __name__ == '__main__': main()