API: rename get_state & update_state to get_storage & update_storage.

This commit is contained in:
derAnfaenger 2017-11-13 09:57:41 +01:00 committed by showell
parent 2736223073
commit f41030b515
3 changed files with 10 additions and 10 deletions

View file

@ -859,13 +859,13 @@ class Client(object):
request=request, request=request,
) )
def update_state(self, request): def update_storage(self, request):
# type: (Dict[str, Any]) -> Dict[str, Any] # type: (Dict[str, Any]) -> Dict[str, Any]
''' '''
Example usage: Example usage:
>>> client.update_state({'state': {"entry 1": "value 1", "entry 2": "value 2", "entry 3": "value 3"}}) >>> client.update_storage({'state': {"entry 1": "value 1", "entry 2": "value 2", "entry 3": "value 3"}})
>>> 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': ''} {'result': 'success', 'state': {'entry 1': 'value 1', 'entry 3': 'value 3'}, 'msg': ''}
''' '''
return self.call_endpoint( return self.call_endpoint(
@ -874,15 +874,15 @@ class Client(object):
request=request, request=request,
) )
def get_state(self, request=None): def get_storage(self, request=None):
# type: (Optional[Dict[str, Any]]) -> Dict[str, Any] # type: (Optional[Dict[str, Any]]) -> Dict[str, Any]
''' '''
Example usage: Example usage:
>>> client.update_state({'state': {"entry 1": "value 1", "entry 2": "value 2", "entry 3": "value 3"}}) >>> client.update_storage({'state': {"entry 1": "value 1", "entry 2": "value 2", "entry 3": "value 3"}})
>>> client.get_state() >>> client.get_storage()
{'result': 'success', 'state': {"entry 1": "value 1", "entry 2": "value 2", "entry 3": "value 3"}, 'msg': ''} {'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': ''} {'result': 'success', 'state': {'entry 1': 'value 1', 'entry 3': 'value 3'}, 'msg': ''}
''' '''
return self.call_endpoint( return self.call_endpoint(

View file

@ -61,7 +61,7 @@ class StateHandler(object):
self._client = client self._client = client
self.marshal = lambda obj: json.dumps(obj) self.marshal = lambda obj: json.dumps(obj)
self.demarshal = lambda obj: json.loads(obj) self.demarshal = lambda obj: json.loads(obj)
response = self._client.get_state() response = self._client.get_storage()
if response['result'] == 'success': if response['result'] == 'success':
self.state_ = response['state'] self.state_ = response['state']
self._modified_entries = set() # type: Set[Text] self._modified_entries = set() # type: Set[Text]
@ -85,7 +85,7 @@ class StateHandler(object):
# type: () -> None # type: () -> None
state_update = {'state': {key: self.state_[key] for key in self._modified_entries}} state_update = {'state': {key: self.state_[key] for key in self._modified_entries}}
if state_update: if state_update:
response = self._client.update_state(state_update) response = self._client.update_storage(state_update)
if response['result'] == 'success': if response['result'] == 'success':
self._modified_entries.clear() self._modified_entries.clear()
else: else:

View file

@ -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) self.mock_bot_handler = self.MockClass(None, None)
self.mock_client = MagicMock() 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.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}
self.mock_bot_handler.send_reply.return_value = {'id': 42} self.mock_bot_handler.send_reply.return_value = {'id': 42}