diff --git a/zulip_botserver/tests/server_test_lib.py b/zulip_botserver/tests/server_test_lib.py index ec4da16..b460846 100644 --- a/zulip_botserver/tests/server_test_lib.py +++ b/zulip_botserver/tests/server_test_lib.py @@ -1,3 +1,4 @@ +import configparser import json from typing import Any, List, Dict, Optional @@ -19,13 +20,14 @@ class BotServerTestCase(TestCase): 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.available_bots = available_bots bots_lib_modules = server.load_lib_modules() server.app.config["BOTS_LIB_MODULES"] = bots_lib_modules if bot_handlers is None: - bot_handlers = server.load_bot_handlers(bots_config) + bot_handlers = server.load_bot_handlers(bots_config, third_party_bot_conf) message_handlers = server.init_message_handlers(bots_lib_modules, bot_handlers) server.app.config["BOT_HANDLERS"] = bot_handlers server.app.config["MESSAGE_HANDLERS"] = message_handlers diff --git a/zulip_botserver/zulip_botserver/server.py b/zulip_botserver/zulip_botserver/server.py index 0c07835..d0e0381 100644 --- a/zulip_botserver/zulip_botserver/server.py +++ b/zulip_botserver/zulip_botserver/server.py @@ -60,10 +60,9 @@ def load_lib_modules() -> Dict[str, Any]: def load_bot_handlers( bots_config: Dict[str, Dict[str, str]], - bot_config_file: Optional[str]=None + third_party_bot_conf: Optional[configparser.ConfigParser]=None, ) -> Dict[str, ExternalBotHandler]: bot_handlers = {} - third_party_bot_conf = parse_config_file(bot_config_file) if bot_config_file is not None else None for bot in available_bots: client = Client(email=bots_config[bot]["email"], api_key=bots_config[bot]["key"], @@ -123,7 +122,8 @@ def main() -> None: global available_bots available_bots = list(bots_config.keys()) bots_lib_modules = load_lib_modules() - bot_handlers = load_bot_handlers(bots_config, options.bot_config_file) + third_party_bot_conf = parse_config_file(options.bot_config_file) if options.bot_config_file is not None else None + bot_handlers = load_bot_handlers(bots_config, third_party_bot_conf) message_handlers = init_message_handlers(bots_lib_modules, bot_handlers) app.config["BOTS_LIB_MODULES"] = bots_lib_modules app.config["BOT_HANDLERS"] = bot_handlers