def test_kv_does_request_with_specified_timeout(self): get_kv('some/path', recurse=True, timeout=10) self.request.urlopen.assert_called_once_with( self.request.Request.return_value, timeout=10 )
def test_get_kv_does_request(self): get_kv('some/path', recurse=True) self.request.urlopen.assert_called_once_with( self.request.Request.return_value, timeout=socket._GLOBAL_DEFAULT_TIMEOUT )
def test_kv_gets_endpoint_root_if_no_key_specified(self): get_kv() expected_url = 'http://localhost:8500/v1/kv/' self.request.Request.assert_called_once_with( url=expected_url, method='GET' )
def test_get_kv_gets_all_nested_values_if_specified(self): get_kv('some/path', recurse=True) expected_url = 'http://localhost:8500/v1/kv/some/path/?recurse' self.request.Request.assert_called_once_with( url=expected_url, method='GET' )
def test_get_kv_instantiates_request_object_with_specified_endpoint(self): get_kv('some/path', endpoint='http://some_host:8500/v1/kv/') expected_url = 'http://some_host:8500/v1/kv/some/path' self.request.Request.assert_called_once_with( url=expected_url, method='GET' )
def test_get_kv_instantiates_request_object(self): get_kv('some/path') expected_url = 'http://localhost:8500/v1/kv/some/path' self.request.Request.assert_called_once_with( url=expected_url, method='GET' )
def test_get_kv_returns_mapping(self): ret = get_kv('some/path', recurse=True) expected_mapping = { 'key1': 'value1' } self.assertEqual(ret, expected_mapping)
def test_get_kv_ignores_empty_keys(self): self.json_dump = '[{"Key": "", "Value": null}]' self.request.urlopen.return_value.__enter__ = lambda x: Mock( read=lambda: Mock( decode=lambda _: self.json_dump ) ) ret = get_kv('some/path', recurse=True) expected_mapping = {} self.assertEqual(ret, expected_mapping)