zulip_bots: Rename state_handler to storage.
MODIFY
zulip_bots/zulip_bots/bots/incrementor/incrementor.py
zulip_bots/zulip_bots/bots/incrementor/incrementor.py
@@ -12,7 +12,7 @@ class IncrementorHandler(object):
'''
def handle_message(self, message, bot_handler):
- with bot_handler.state_handler.state({'number': 0, 'message_id': None}) as state:
+ with bot_handler.storage.state({'number': 0, 'message_id': None}) as state:
state['number'] += 1
if state['message_id'] is None:
result = bot_handler.send_reply(message, str(state['number']))

MODIFY
zulip_bots/zulip_bots/bots/incrementor/test_incrementor.py
zulip_bots/zulip_bots/bots/incrementor/test_incrementor.py
@@ -23,11 +23,11 @@ class TestIncrementorBot(BotTestCase):
'sender_email': 'foo_sender@zulip.com',
},
]
- state_handler = StateHandler()
+ storage = StateHandler()
self.assert_bot_response(dict(messages[0], content=""), {'content': "1"},
- 'send_reply', state_handler)
+ 'send_reply', storage)
# Last test commented out since we don't have update_message
# support in the test framework yet.
# self.assert_bot_response(dict(messages[0], content=""), {'message_id': 5, 'content': "2"},
- # 'update_message', state_handler)
+ # 'update_message', storage)

MODIFY
zulip_bots/zulip_bots/bots/tictactoe/tictactoe.py
zulip_bots/zulip_bots/bots/tictactoe/tictactoe.py
@@ -281,7 +281,7 @@ class ticTacToeHandler(object):
command += val
original_sender = message['sender_email']
- with bot_handler.state_handler.state({}) as mydict:
+ with bot_handler.storage.state({}) as mydict:
user_game = mydict.get(original_sender)
if (not user_game) and command == "new":
user_game = TicTacToeGame(copy.deepcopy(initial_board))

MODIFY
zulip_bots/zulip_bots/bots/virtual_fs/test_virtual_fs.py
zulip_bots/zulip_bots/bots/virtual_fs/test_virtual_fs.py
@@ -45,5 +45,5 @@ class TestVirtualFsBot(BotTestCase):
("cd /home", "foo_sender@zulip.com:\nCurrent path: /home/"),
]
- state_handler = StateHandler()
- self.check_expected_responses(expected, state_handler = state_handler)
+ storage = StateHandler()
+ self.check_expected_responses(expected, storage = storage)

MODIFY
zulip_bots/zulip_bots/bots/virtual_fs/virtual_fs.py
zulip_bots/zulip_bots/bots/virtual_fs/virtual_fs.py
@@ -18,7 +18,7 @@ class VirtualFsHandler(object):
if isinstance(recipient, list): # If not a stream, then hash on list of emails
recipient = " ".join([x['email'] for x in recipient])
- with bot_handler.state_handler.state({}) as state:
+ with bot_handler.storage.state({}) as state:
if recipient not in state:
state[recipient] = fs_new()
fs = state[recipient]

MODIFY
zulip_bots/zulip_bots/lib.py
zulip_bots/zulip_bots/lib.py
@@ -79,7 +79,7 @@ class ExternalBotHandler(object):
self._rate_limit = RateLimit(20, 5)
self._client = client
self._root_dir = root_dir
- self.state_handler = StateHandler()
+ self.storage = StateHandler()
try:
self.user_id = user_profile['user_id']
self.full_name = user_profile['full_name']

MODIFY
zulip_bots/zulip_bots/test_lib.py
zulip_bots/zulip_bots/test_lib.py
@@ -56,7 +56,7 @@ class BotTestCase(TestCase):
def check_expected_responses(self, expectations, expected_method='send_reply',
email="foo_sender@zulip.com", recipient="foo", subject="foo",
sender_id=0, sender_full_name="Foo Bar", type="all",
- state_handler=None):
+ storage=None):
# type: (Union[Sequence[Tuple[str, Any]], Dict[str, Any]], str, str, str, str, int, str, str, Optional[StateHandler]) -> None
# To test send_message, Any would be a Dict type,
# to test send_reply, Any would be a str type.
@@ -82,12 +82,12 @@ class BotTestCase(TestCase):
trigger_messages.append(stream_message_dict)
for trigger_message in trigger_messages:
- if state_handler is None:
- current_state_handler = None
+ if storage is None:
+ current_storage = None
else:
- # A new (copy of) the state_handler is used for each trigger message.
+ # A new (copy of) the StateHandler is used for each trigger message.
# This avoids type="all" failing if state is created in the first iteration.
- current_state_handler = deepcopy(state_handler)
+ current_storage = deepcopy(storage)
for m, r in expected:
# For calls with send_reply, r is a string (the content of a message),
@@ -97,15 +97,15 @@ class BotTestCase(TestCase):
response = {'content': r} if expected_method == 'send_reply' else r
self.assert_bot_response(message=message, response=response,
expected_method=expected_method,
- state_handler=current_state_handler)
+ storage=current_storage)
- def call_request(self, message, expected_method, response, state_handler):
+ def call_request(self, message, expected_method, response, storage):
# type: (Dict[str, Any], str, Dict[str, Any], Optional[StateHandler]) -> None
- if state_handler is None:
- state_handler = StateHandler()
+ if storage is None:
+ storage = StateHandler()
# Send message to the concerned bot
mock_bot_handler = self.MockClass(None, None)
- mock_bot_handler.state_handler = state_handler
+ mock_bot_handler.storage = storage
self.message_handler.handle_message(message, mock_bot_handler)
# Check if the bot is sending a message via `send_message` function.
@@ -159,8 +159,8 @@ class BotTestCase(TestCase):
else:
mock_get.assert_called_with(http_request['api_url'])
- def assert_bot_response(self, message, response, expected_method, state_handler = None):
+ def assert_bot_response(self, message, response, expected_method, storage = None):
# type: (Dict[str, Any], Dict[str, Any], str, Optional[StateHandler]) -> None
# Strictly speaking, this function is not needed anymore,
# kept for now for legacy reasons.
- self.call_request(message, expected_method, response, state_handler)
+ self.call_request(message, expected_method, response, storage)

zulip_bots: Rename state_handler to storage.