From f1bcf3b9a4c6f9956616888437b9f641c0a09fcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20H=C3=B6nig?= Date: Tue, 29 May 2018 09:52:14 +0200 Subject: [PATCH] botserver: Remove redundant message check. Previously, the botserver `handle_bot` routine did two checks on an incoming message: * First, it checked if the bot email matches an email in the flaskbotrc. * Second, it checked if the bot name that corresponds to an email has a lib module loaded. However, this must be the case, because all lib modules for all emails are loaded on initialization. Thus, this commit removes the second check. --- zulip_botserver/tests/test_server.py | 14 +++++++++++--- zulip_botserver/zulip_botserver/server.py | 4 ---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/zulip_botserver/tests/test_server.py b/zulip_botserver/tests/test_server.py index 3ce2b42..558f201 100644 --- a/zulip_botserver/tests/test_server.py +++ b/zulip_botserver/tests/test_server.py @@ -56,10 +56,18 @@ class BotServerTests(BotServerTestCase): bots_config=bots_config, check_success=True) - def test_bot_module_not_exists(self) -> None: - self.assert_bot_server_response(available_bots=[], + def test_request_for_unkown_bot(self) -> None: + bots_config = { + 'helloworld': { + 'email': 'helloworld-bot@zulip.com', + 'key': '123456789qwertyuiop', + 'site': 'http://localhost', + }, + } + self.assert_bot_server_response(available_bots=['helloworld'], event=dict(message={'content': "test message"}, - bot_email='nonexistent-bot@zulip.com'), + bot_email='unknown-bot@zulip.com'), + bots_config=bots_config, check_success=False) @mock.patch('logging.error') diff --git a/zulip_botserver/zulip_botserver/server.py b/zulip_botserver/zulip_botserver/server.py index d192393..0c3634c 100644 --- a/zulip_botserver/zulip_botserver/server.py +++ b/zulip_botserver/zulip_botserver/server.py @@ -116,10 +116,6 @@ def handle_bot() -> Union[str, BadRequest]: lib_module = app.config.get("BOTS_LIB_MODULES", {}).get(bot) bot_handler = app.config.get("BOT_HANDLERS", {}).get(bot) message_handler = app.config.get("MESSAGE_HANDLERS", {}).get(bot) - if lib_module is None: - return BadRequest("Can't find the configuration or Bot Handler code for bot {}. " - "Make sure that the `zulip_bots` package is installed, and " - "that your flaskbotrc is set up correctly".format(bot)) message_handler.handle_message(message=event["message"], bot_handler=bot_handler) return json.dumps("")