def add_profile_to_config(url, config, profile, insecure, version): """Add profile to config file.""" configuration.Manager(config).add_profile( profile, url, version=version, insecure=insecure, )
def test_add_load_bad_profile_from_file(tmpdir): path = tmpdir / 'substra.cfg' conf = "node-1" path.write_text(conf, "UTF-8") manager = configuration.Manager(str(path)) with pytest.raises(configuration.ConfigException): manager.load_profile('node-1')
def test_add_load_profile(tmpdir): path = tmpdir / 'substra.cfg' manager = configuration.Manager(str(path)) profile_1 = manager.add_profile( 'owkin', url='http://substra-backend.owkin.xyz:8000', version='0.0') profile_2 = manager.load_profile('owkin') assert profile_1 == profile_2
def test_load_profile_fail(tmpdir): path = tmpdir / 'substra.cfg' manager = configuration.Manager(str(path)) with pytest.raises(configuration.ConfigException): manager.load_profile('notfound') manager.add_profile('default', 'foo', 'bar') with pytest.raises(configuration.ProfileNotFoundError): manager.load_profile('notfound')
def __init__(self, config_path=None, profile_name=None, user_path=None): self._cfg_manager = cfg.Manager(config_path or cfg.DEFAULT_PATH) self._usr_manager = usr.Manager(user_path or usr.DEFAULT_PATH) self._current_profile = None self._profiles = {} self.client = rest_client.Client() self._profile_name = 'default' if profile_name: self._profile_name = profile_name self.set_profile(profile_name) # set current logged user if exists self.set_user()
def test_add_load_profile_from_file(tmpdir): path = tmpdir / 'substra.cfg' conf = { "node-1": { "insecure": False, "url": "http://substra-backend.node-1.com", "version": "0.0" }, } path.write_text(json.dumps(conf), "UTF-8") manager = configuration.Manager(str(path)) profile = manager.load_profile('node-1') assert conf['node-1'] == profile
def __init__(self, config_path=None, profile_name=None, user_path=None, token=None, retry_timeout=DEFAULT_RETRY_TIMEOUT): self._cfg_manager = cfg.Manager(config_path or cfg.DEFAULT_PATH) self._usr_manager = usr.Manager(user_path or usr.DEFAULT_PATH) self._current_profile = None self._profiles = {} self.client = rest_client.Client() self._profile_name = 'default' self._retry_timeout = retry_timeout if profile_name: self._profile_name = profile_name self.set_profile(profile_name) # set current logged user if exists self.set_user() if token: self._set_token(token)