API: rename get_state & update_state to get_storage & update_storage.
This commit is contained in:
parent
2736223073
commit
f41030b515
|
@ -859,13 +859,13 @@ class Client(object):
|
|||
request=request,
|
||||
)
|
||||
|
||||
def update_state(self, request):
|
||||
def update_storage(self, request):
|
||||
# type: (Dict[str, Any]) -> Dict[str, Any]
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
>>> client.update_state({'state': {"entry 1": "value 1", "entry 2": "value 2", "entry 3": "value 3"}})
|
||||
>>> client.get_state({'keys': ["entry 1", "entry 3"]})
|
||||
>>> client.update_storage({'state': {"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': ''}
|
||||
'''
|
||||
return self.call_endpoint(
|
||||
|
@ -874,15 +874,15 @@ class Client(object):
|
|||
request=request,
|
||||
)
|
||||
|
||||
def get_state(self, request=None):
|
||||
def get_storage(self, request=None):
|
||||
# type: (Optional[Dict[str, Any]]) -> Dict[str, Any]
|
||||
'''
|
||||
Example usage:
|
||||
|
||||
>>> client.update_state({'state': {"entry 1": "value 1", "entry 2": "value 2", "entry 3": "value 3"}})
|
||||
>>> client.get_state()
|
||||
>>> client.update_storage({'state': {"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': ''}
|
||||
>>> client.get_state(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': ''}
|
||||
'''
|
||||
return self.call_endpoint(
|
||||
|
|
|
@ -61,7 +61,7 @@ class StateHandler(object):
|
|||
self._client = client
|
||||
self.marshal = lambda obj: json.dumps(obj)
|
||||
self.demarshal = lambda obj: json.loads(obj)
|
||||
response = self._client.get_state()
|
||||
response = self._client.get_storage()
|
||||
if response['result'] == 'success':
|
||||
self.state_ = response['state']
|
||||
self._modified_entries = set() # type: Set[Text]
|
||||
|
@ -85,7 +85,7 @@ class StateHandler(object):
|
|||
# type: () -> None
|
||||
state_update = {'state': {key: self.state_[key] for key in self._modified_entries}}
|
||||
if state_update:
|
||||
response = self._client.update_state(state_update)
|
||||
response = self._client.update_storage(state_update)
|
||||
if response['result'] == 'success':
|
||||
self._modified_entries.clear()
|
||||
else:
|
||||
|
|
|
@ -46,7 +46,7 @@ class BotTestCaseBase(TestCase):
|
|||
self.MockClass = self.patcher.start()
|
||||
self.mock_bot_handler = self.MockClass(None, None)
|
||||
self.mock_client = MagicMock()
|
||||
self.mock_client.get_state.return_value = {'result': 'success', 'state': {}}
|
||||
self.mock_client.get_storage.return_value = {'result': 'success', 'state': {}}
|
||||
self.mock_bot_handler.storage = StateHandler(self.mock_client)
|
||||
self.mock_bot_handler.send_message.return_value = {'id': 42}
|
||||
self.mock_bot_handler.send_reply.return_value = {'id': 42}
|
||||
|
|
Loading…
Reference in a new issue