From 8a15452525a047ba437205bde4f8abc2a1e15992 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Mon, 27 Nov 2017 12:51:02 -0800 Subject: [PATCH] bots: Require bots_details in ExternalBotHandler. This parameter was defaulting to a dictionary, which is a classic Python pitfall. --- zulip_bots/zulip_bots/lib.py | 2 +- zulip_bots/zulip_bots/test_lib.py | 2 +- zulip_botserver/zulip_botserver/server.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/zulip_bots/zulip_bots/lib.py b/zulip_bots/zulip_bots/lib.py index b7a2720..0d45c54 100644 --- a/zulip_bots/zulip_bots/lib.py +++ b/zulip_bots/zulip_bots/lib.py @@ -83,7 +83,7 @@ class StateHandler(object): return key in self.state_ class ExternalBotHandler(object): - def __init__(self, client, root_dir, bot_details={}): + def __init__(self, client, root_dir, bot_details): # type: (Client, str, Dict[str, Any]) -> None # Only expose a subset of our Client's functionality try: diff --git a/zulip_bots/zulip_bots/test_lib.py b/zulip_bots/zulip_bots/test_lib.py index e6d877a..fc29ef6 100755 --- a/zulip_bots/zulip_bots/test_lib.py +++ b/zulip_bots/zulip_bots/test_lib.py @@ -44,7 +44,7 @@ class BotTestCaseBase(TestCase): # Mocking ExternalBotHandler self.patcher = patch('zulip_bots.lib.ExternalBotHandler', autospec=True) self.MockClass = self.patcher.start() - self.mock_bot_handler = self.MockClass(None, None) + self.mock_bot_handler = self.MockClass(None, None, None) self.mock_client = MagicMock() self.mock_client.get_storage.return_value = {'result': 'success', 'state': {}} self.mock_client.update_storage.return_value = {'result': 'success'} diff --git a/zulip_botserver/zulip_botserver/server.py b/zulip_botserver/zulip_botserver/server.py index 17545f8..f83e696 100644 --- a/zulip_botserver/zulip_botserver/server.py +++ b/zulip_botserver/zulip_botserver/server.py @@ -54,7 +54,7 @@ def load_bot_handlers(): try: bot_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'bots', bot) - bot_handlers[bot] = ExternalBotHandler(client, bot_dir) + bot_handlers[bot] = ExternalBotHandler(client, bot_dir, bot_details={}) except SystemExit: return BadRequest("Cannot fetch user profile for bot {}, make sure you have set up the flaskbotrc " "file correctly.".format(bot))