def get_settings(self, block_id, settings): request = consensus_pb2.ConsensusSettingsGetRequest( block_id=block_id, keys=settings) response_type = consensus_pb2.ConsensusSettingsGetResponse response = self._send( request=request, message_type=Message.CONSENSUS_SETTINGS_GET_REQUEST, response_type=response_type) status = response.status if status == response_type.UNKNOWN_BLOCK: raise exceptions.UnknownBlock() if status != response_type.OK: raise exceptions.ReceiveError( 'Failed with status {}'.format(status)) return { entry.key: entry.value for entry in response.entries }
def test_get_settings(self): self.mock_stream.send.return_value = self._make_future( message_type=Message.CONSENSUS_SETTINGS_GET_RESPONSE, content=consensus_pb2.ConsensusSettingsGetResponse( status=consensus_pb2.ConsensusSettingsGetResponse.OK, entries=[ consensus_pb2.ConsensusSettingsEntry(key='key1', value='value1'), consensus_pb2.ConsensusSettingsEntry(key='key2', value='value2') ]).SerializeToString()) entries = self.service.get_settings(block_id=b'test', settings=['test1', 'test2']) self.mock_stream.send.assert_called_with( message_type=Message.CONSENSUS_SETTINGS_GET_REQUEST, content=consensus_pb2.ConsensusSettingsGetRequest( block_id=b'test', keys=['test1', 'test2']).SerializeToString()) self.assertEqual(entries, { 'key1': 'value1', 'key2': 'value2', })