Rename bot storage endpoint from state to storage.
This commit is contained in:
parent
80e4ef9f72
commit
d6a4c02ba5
|
@ -878,12 +878,12 @@ class Client(object):
|
||||||
'''
|
'''
|
||||||
Example usage:
|
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"]})
|
>>> 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(
|
return self.call_endpoint(
|
||||||
url='user_state',
|
url='bot_storage',
|
||||||
method='PUT',
|
method='PUT',
|
||||||
request=request,
|
request=request,
|
||||||
)
|
)
|
||||||
|
@ -893,14 +893,14 @@ class Client(object):
|
||||||
'''
|
'''
|
||||||
Example usage:
|
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()
|
>>> 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'))
|
>>> 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(
|
return self.call_endpoint(
|
||||||
url='user_state',
|
url='bot_storage',
|
||||||
method='GET',
|
method='GET',
|
||||||
request=request,
|
request=request,
|
||||||
)
|
)
|
||||||
|
|
|
@ -66,14 +66,14 @@ class StateHandler(object):
|
||||||
self.demarshal = lambda obj: json.loads(obj)
|
self.demarshal = lambda obj: json.loads(obj)
|
||||||
response = self._client.get_storage()
|
response = self._client.get_storage()
|
||||||
if response['result'] == 'success':
|
if response['result'] == 'success':
|
||||||
self.state_ = response['state']
|
self.state_ = response['storage']
|
||||||
else:
|
else:
|
||||||
raise StateHandlerError("Error initializing state: {}".format(str(response)))
|
raise StateHandlerError("Error initializing state: {}".format(str(response)))
|
||||||
|
|
||||||
def put(self, key, value):
|
def put(self, key, value):
|
||||||
# type: (Text, Text) -> None
|
# type: (Text, Text) -> None
|
||||||
self.state_[key] = self.marshal(value)
|
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':
|
if response['result'] != 'success':
|
||||||
raise StateHandlerError("Error updating state: {}".format(str(response)))
|
raise StateHandlerError("Error updating state: {}".format(str(response)))
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ class BotTestCaseBase(TestCase):
|
||||||
self.MockClass = self.patcher.start()
|
self.MockClass = self.patcher.start()
|
||||||
self.mock_bot_handler = self.MockClass(None, None, None, None)
|
self.mock_bot_handler = self.MockClass(None, None, None, None)
|
||||||
self.mock_client = MagicMock()
|
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_client.update_storage.return_value = {'result': 'success'}
|
||||||
self.mock_bot_handler.storage = StateHandler(self.mock_client)
|
self.mock_bot_handler.storage = StateHandler(self.mock_client)
|
||||||
self.mock_bot_handler.send_message.return_value = {'id': 42}
|
self.mock_bot_handler.send_message.return_value = {'id': 42}
|
||||||
|
|
Loading…
Reference in a new issue