Rename bot storage endpoint from state to storage.

This commit is contained in:
Robert Hönig 2017-11-28 20:34:25 +01:00
parent 80e4ef9f72
commit d6a4c02ba5
3 changed files with 10 additions and 10 deletions

View file

@ -878,12 +878,12 @@ class Client(object):
'''
Example usage:
>>> client.update_storage({'state': {"entry 1": "value 1", "entry 2": "value 2", "entry 3": "value 3"}})
>>> client.update_storage({'storage': {"entry 1": "value 1", "entry 2": "value 2", "entry 3": "value 3"}})
>>> client.get_storage({'keys': ["entry 1", "entry 3"]})
{'result': 'success', 'state': {'entry 1': 'value 1', 'entry 3': 'value 3'}, 'msg': ''}
{'result': 'success', 'storage': {'entry 1': 'value 1', 'entry 3': 'value 3'}, 'msg': ''}
'''
return self.call_endpoint(
url='user_state',
url='bot_storage',
method='PUT',
request=request,
)
@ -893,14 +893,14 @@ class Client(object):
'''
Example usage:
>>> client.update_storage({'state': {"entry 1": "value 1", "entry 2": "value 2", "entry 3": "value 3"}})
>>> client.update_storage({'storage': {"entry 1": "value 1", "entry 2": "value 2", "entry 3": "value 3"}})
>>> client.get_storage()
{'result': 'success', 'state': {"entry 1": "value 1", "entry 2": "value 2", "entry 3": "value 3"}, 'msg': ''}
{'result': 'success', 'storage': {"entry 1": "value 1", "entry 2": "value 2", "entry 3": "value 3"}, 'msg': ''}
>>> client.get_storage(keys=('entry 1', 'entry 3'))
{'result': 'success', 'state': {'entry 1': 'value 1', 'entry 3': 'value 3'}, 'msg': ''}
{'result': 'success', 'storage': {'entry 1': 'value 1', 'entry 3': 'value 3'}, 'msg': ''}
'''
return self.call_endpoint(
url='user_state',
url='bot_storage',
method='GET',
request=request,
)

View file

@ -66,14 +66,14 @@ class StateHandler(object):
self.demarshal = lambda obj: json.loads(obj)
response = self._client.get_storage()
if response['result'] == 'success':
self.state_ = response['state']
self.state_ = response['storage']
else:
raise StateHandlerError("Error initializing state: {}".format(str(response)))
def put(self, key, value):
# type: (Text, Text) -> None
self.state_[key] = self.marshal(value)
response = self._client.update_storage({'state': {key: self.state_[key]}})
response = self._client.update_storage({'storage': {key: self.state_[key]}})
if response['result'] != 'success':
raise StateHandlerError("Error updating state: {}".format(str(response)))

View file

@ -46,7 +46,7 @@ class BotTestCaseBase(TestCase):
self.MockClass = self.patcher.start()
self.mock_bot_handler = self.MockClass(None, None, None, None)
self.mock_client = MagicMock()
self.mock_client.get_storage.return_value = {'result': 'success', 'state': {}}
self.mock_client.get_storage.return_value = {'result': 'success', 'storage': {}}
self.mock_client.update_storage.return_value = {'result': 'success'}
self.mock_bot_handler.storage = StateHandler(self.mock_client)
self.mock_bot_handler.send_message.return_value = {'id': 42}