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.
This commit is contained in:
Robert Hönig 2018-05-29 09:52:14 +02:00
parent 5c062cee0d
commit f1bcf3b9a4
2 changed files with 11 additions and 7 deletions

View file

@ -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')

View file

@ -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("")