bot tests: Add StubBotTestCase.mock_config_info().

We now auto-initialize bots in verify_reply() and have
a mock_config_info() helper that can override the new
StubBotHandler.get_config_info().
This commit is contained in:
Steve Howell 2017-12-06 19:41:19 -08:00 committed by showell
parent be9570c9c4
commit 87662da139

View file

@ -59,6 +59,10 @@ class StubBotHandler:
# type: (Dict[str, Any]) -> None # type: (Dict[str, Any]) -> None
self.message_server.update(message) self.message_server.update(message)
def get_config_info(self, bot_name, optional=False):
# type: (str, bool) -> Dict[str, Any]
return None
def unique_reply(self): def unique_reply(self):
# type: () -> Dict[str, Any] # type: () -> Dict[str, Any]
responses = [ responses = [
@ -103,6 +107,9 @@ class StubBotTestCase(TestCase):
bot = get_bot_message_handler(self.bot_name) bot = get_bot_message_handler(self.bot_name)
bot_handler = StubBotHandler() bot_handler = StubBotHandler()
if hasattr(bot, 'initialize'):
bot.initialize(bot_handler)
message = dict( message = dict(
sender_email='foo@example.com', sender_email='foo@example.com',
content=request, content=request,
@ -140,6 +147,10 @@ class StubBotTestCase(TestCase):
http_data = read_bot_fixture_data(self.bot_name, test_name) http_data = read_bot_fixture_data(self.bot_name, test_name)
return mock_http_conversation(http_data) return mock_http_conversation(http_data)
def mock_config_info(self, config_info):
# type: (Dict[str, str]) -> Any
return patch('zulip_bots.test_lib.StubBotHandler.get_config_info', return_value=config_info)
def get_bot_message_handler(bot_name): def get_bot_message_handler(bot_name):
# type: (str) -> Any # type: (str) -> Any
# message_handler is of type 'Any', since it can contain any bot's # message_handler is of type 'Any', since it can contain any bot's