1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
9 from arvados import config as arv_config
12 @pytest.fixture(autouse=True)
13 def setup(self, monkeypatch):
14 arv_config._settings = None
15 monkeypatch.delenv('ARVADOS_API_HOST', raising=False)
16 monkeypatch.delenv('ARVADOS_API_TOKEN', raising=False)
20 arv_config._settings = None
23 def tmp_settings(self, tmp_path):
24 path = tmp_path / 'settings.conf'
25 with path.open('w') as settings_file:
26 print("ARVADOS_API_HOST=localhost", file=settings_file)
27 print("ARVADOS_API_TOKEN=TestInitialize", file=settings_file)
30 def test_static_path(self, tmp_settings):
31 arv_config.initialize(tmp_settings)
32 actual = arv_config.settings()
33 assert actual['ARVADOS_API_HOST'] == 'localhost'
34 assert actual['ARVADOS_API_TOKEN'] == 'TestInitialize'
36 def test_search_path(self, tmp_settings):
38 assert filename == tmp_settings.name
40 arv_config.initialize(search)
41 actual = arv_config.settings()
42 assert actual['ARVADOS_API_HOST'] == 'localhost'
43 assert actual['ARVADOS_API_TOKEN'] == 'TestInitialize'
45 def test_default_search(self, tmp_settings, monkeypatch):
46 monkeypatch.setenv('CONFIGURATION_DIRECTORY', str(tmp_settings.parent))
47 monkeypatch.setenv('XDG_CONFIG_HOME', str(tmp_settings.parent))
48 monkeypatch.delenv('XDG_CONFIG_DIRS', raising=False)
49 actual = arv_config.settings()
50 assert actual['ARVADOS_API_HOST'] == 'localhost'
51 assert actual['ARVADOS_API_TOKEN'] == 'TestInitialize'
53 def test_environ_override(self, monkeypatch):
54 monkeypatch.setenv('ARVADOS_API_TOKEN', 'test_environ_override')
55 arv_config.initialize('')
56 actual = arv_config.settings()
57 assert actual.get('ARVADOS_API_HOST') is None
58 assert actual['ARVADOS_API_TOKEN'] == 'test_environ_override'