zulip_botserver: Add option to test third party configs
This commit is contained in:
parent
d3b99959c6
commit
b06ebdecef
|
@ -1,3 +1,4 @@
|
||||||
|
import configparser
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from typing import Any, List, Dict, Optional
|
from typing import Any, List, Dict, Optional
|
||||||
|
@ -19,13 +20,14 @@ class BotServerTestCase(TestCase):
|
||||||
payload_url: str="/bots/helloworld",
|
payload_url: str="/bots/helloworld",
|
||||||
message: Optional[Dict[str, Any]]=dict(message={'key': "test message"}),
|
message: Optional[Dict[str, Any]]=dict(message={'key': "test message"}),
|
||||||
check_success: bool=False,
|
check_success: bool=False,
|
||||||
|
third_party_bot_conf: Optional[configparser.ConfigParser]=None,
|
||||||
) -> None:
|
) -> None:
|
||||||
if available_bots is not None and bots_config is not None:
|
if available_bots is not None and bots_config is not None:
|
||||||
server.available_bots = available_bots
|
server.available_bots = available_bots
|
||||||
bots_lib_modules = server.load_lib_modules()
|
bots_lib_modules = server.load_lib_modules()
|
||||||
server.app.config["BOTS_LIB_MODULES"] = bots_lib_modules
|
server.app.config["BOTS_LIB_MODULES"] = bots_lib_modules
|
||||||
if bot_handlers is None:
|
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)
|
message_handlers = server.init_message_handlers(bots_lib_modules, bot_handlers)
|
||||||
server.app.config["BOT_HANDLERS"] = bot_handlers
|
server.app.config["BOT_HANDLERS"] = bot_handlers
|
||||||
server.app.config["MESSAGE_HANDLERS"] = message_handlers
|
server.app.config["MESSAGE_HANDLERS"] = message_handlers
|
||||||
|
|
|
@ -60,10 +60,9 @@ def load_lib_modules() -> Dict[str, Any]:
|
||||||
|
|
||||||
def load_bot_handlers(
|
def load_bot_handlers(
|
||||||
bots_config: Dict[str, Dict[str, str]],
|
bots_config: Dict[str, Dict[str, str]],
|
||||||
bot_config_file: Optional[str]=None
|
third_party_bot_conf: Optional[configparser.ConfigParser]=None,
|
||||||
) -> Dict[str, ExternalBotHandler]:
|
) -> Dict[str, ExternalBotHandler]:
|
||||||
bot_handlers = {}
|
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:
|
for bot in available_bots:
|
||||||
client = Client(email=bots_config[bot]["email"],
|
client = Client(email=bots_config[bot]["email"],
|
||||||
api_key=bots_config[bot]["key"],
|
api_key=bots_config[bot]["key"],
|
||||||
|
@ -123,7 +122,8 @@ def main() -> None:
|
||||||
global available_bots
|
global available_bots
|
||||||
available_bots = list(bots_config.keys())
|
available_bots = list(bots_config.keys())
|
||||||
bots_lib_modules = load_lib_modules()
|
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)
|
message_handlers = init_message_handlers(bots_lib_modules, bot_handlers)
|
||||||
app.config["BOTS_LIB_MODULES"] = bots_lib_modules
|
app.config["BOTS_LIB_MODULES"] = bots_lib_modules
|
||||||
app.config["BOT_HANDLERS"] = bot_handlers
|
app.config["BOT_HANDLERS"] = bot_handlers
|
||||||
|
|
Loading…
Reference in a new issue