1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
10 from arvados import safeapi
12 from . import run_test_server
14 class SafeApiTest(run_test_server.TestCaseWithServers):
17 def test_constructor(self):
20 for key, value in os.environ.items()
21 if key.startswith('ARVADOS_API_')
27 key[12:].lower(): value
28 for key, value in env_mapping.items()
31 base_params['insecure'] = base_params.pop('host_insecure')
34 expected_keep_params = {}
35 for config, params, subtest in [
36 (None, {}, "default arguments"),
37 (None, extra_params, "extra params"),
38 (env_mapping, {}, "explicit config"),
39 (env_mapping, extra_params, "explicit config and params"),
40 ({}, base_params, "params only"),
42 with self.subTest(f"test constructor with {subtest}"):
43 expected_timeout = params.get('timeout', 300)
44 expected_params = dict(params)
45 keep_params = dict(expected_keep_params)
46 client = safeapi.ThreadSafeApiCache(config, keep_params, params, 'v1')
47 self.assertTrue(hasattr(client, 'localapi'), "client missing localapi method")
48 self.assertEqual(client.api_token, os.environ['ARVADOS_API_TOKEN'])
49 self.assertEqual(client._http.timeout, expected_timeout)
50 self.assertEqual(params, expected_params,
51 "api_params was modified in-place")
52 self.assertEqual(keep_params, expected_keep_params,
53 "keep_params was modified in-place")
55 def test_constructor_no_args(self):
56 client = safeapi.ThreadSafeApiCache()
57 self.assertTrue(hasattr(client, 'localapi'), "client missing localapi method")
58 self.assertEqual(client.api_token, os.environ['ARVADOS_API_TOKEN'])
59 self.assertTrue(client.insecure)
61 def test_constructor_bad_version(self):
62 with self.assertRaises(googleapiclient.errors.UnknownApiNameOrVersion):
63 safeapi.ThreadSafeApiCache(version='BadTestVersion')