zulip_botserver: Handle all requests from the root / endpoint.

Previously, the Botserver determined which bot to run by dispatching on
a unique URL endpoint /bots/<botname> for each bot.
Now, instead, the Botserver determines which bot to run by the section
header of the bot in the flaskbotrc.
This commit is contained in:
Robert Hönig 2018-05-22 13:46:40 +02:00
parent 6249df0ad7
commit 6a8cb2965c
3 changed files with 29 additions and 13 deletions

View file

@ -17,12 +17,12 @@ class BotServerTestCase(TestCase):
available_bots: Optional[List[str]]=None,
bots_config: Optional[Dict[str, Dict[str, str]]]=None,
bot_handlers: Optional[Dict[str, Any]]=None,
payload_url: str="/bots/helloworld",
message: Optional[Dict[str, Any]]=dict(message={'key': "test message"}),
check_success: bool=False,
third_party_bot_conf: Optional[configparser.ConfigParser]=None,
) -> None:
if available_bots is not None and bots_config is not None:
server.bots_config = bots_config
bots_lib_modules = server.load_lib_modules(available_bots)
server.app.config["BOTS_LIB_MODULES"] = bots_lib_modules
if bot_handlers is None:
@ -31,7 +31,7 @@ class BotServerTestCase(TestCase):
server.app.config["BOT_HANDLERS"] = bot_handlers
server.app.config["MESSAGE_HANDLERS"] = message_handlers
response = self.app.post(payload_url, data=json.dumps(message))
response = self.app.post(data=json.dumps(message))
if check_success:
assert 200 <= response.status_code < 300

View file

@ -31,6 +31,8 @@ class BotServerTests(BotServerTestCase):
}
self.assert_bot_server_response(available_bots=available_bots,
bots_config=bots_config,
message=dict(message={'content': "test message"},
bot_email='helloworld-bot@zulip.com'),
check_success=True)
@mock.patch('zulip_bots.lib.ExternalBotHandler')
@ -49,12 +51,15 @@ class BotServerTests(BotServerTestCase):
}
}
self.assert_bot_server_response(available_bots=available_bots,
message=dict(message={'content': "test message"},
bot_email='helloworld-bot@zulip.com'),
bots_config=bots_config,
check_success=True)
def test_bot_module_not_exists(self) -> None:
self.assert_bot_server_response(available_bots=[],
payload_url="/bots/not_supported_bot",
message=dict(message={'content': "test message"},
bot_email='nonexistent-bot@zulip.com'),
check_success=False)
@mock.patch('logging.error')