Exemple #1
0
    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
        )
Exemple #2
0
    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
        )
Exemple #3
0
    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'
        )
Exemple #4
0
    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'
        )
Exemple #5
0
    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'
        )
Exemple #6
0
    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'
        )
Exemple #7
0
    def test_get_kv_returns_mapping(self):
        ret = get_kv('some/path', recurse=True)

        expected_mapping = {
            'key1': 'value1'
        }
        self.assertEqual(ret, expected_mapping)
Exemple #8
0
    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)