zulip_botserver: Get rid of some global variables.

This commit is contained in:
Guitar1st 2018-05-15 14:55:58 +00:00 committed by Tim Abbott
parent 7b6da265ea
commit f90913d54c
3 changed files with 35 additions and 23 deletions

View file

@ -1,9 +1,11 @@
import json
from typing import Any, List, Dict, Optional
from typing import Any, List, Dict, Optional, Union
from unittest import TestCase
from werkzeug.exceptions import BadRequest
from zulip_botserver import server
class BotServerTestCase(TestCase):
def setUp(self) -> None:
@ -12,17 +14,21 @@ class BotServerTestCase(TestCase):
def assert_bot_server_response(self,
available_bots: Optional[List[str]]=None,
bots_config: Optional[Dict[str, Any]]=None,
bots_config: Optional[Dict[str, Dict[str, str]]]=None,
bots_lib_module: Optional[Dict[str, Any]]=None,
bot_handlers: Optional[Dict[str, Any]]=None,
bot_handlers: Optional[Union[Dict[str, Any], BadRequest]]=None,
payload_url: str="/bots/helloworld",
message: Optional[Dict[str, Any]]=dict(message={'key': "test message"}),
check_success: bool=False,
) -> None:
if available_bots is not None:
if available_bots is not None and bots_config is not None:
server.available_bots = available_bots
server.load_lib_modules()
server.load_bot_handlers(bots_config)
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, bots_lib_modules)
if not isinstance(bot_handlers, BadRequest):
server.app.config["BOT_HANDLERS"] = bot_handlers
response = self.app.post(payload_url, data=json.dumps(message))

View file

@ -4,6 +4,7 @@ import unittest
from .server_test_lib import BotServerTestCase
import six
class BotServerTests(BotServerTestCase):
class MockMessageHandler(object):
def handle_message(self, message: Dict[str, str], bot_handler: Any) -> None: