def test_home_path_win(self): with patch.dict('os.environ', {'HOMEPATH': 'foo'}): paths = ConfigFilePath(platform='win') assert paths.default_new_config() == \ os.environ['HOMEPATH'] + '/.config/azurectl/config' with patch.dict('os.environ', {'UserProfile': 'foo'}): paths = ConfigFilePath(platform='win') assert paths.default_new_config() == \ os.environ['UserProfile'] + '/.config/azurectl/config'
def set_default_config_file(self, account_name, platform=None): paths = ConfigFilePath(account_name, platform) account_config_file = paths.default_new_account_config() if not os.path.exists(account_config_file): raise AzureConfigAccountFileNotFound( 'Account config file %s not found' % account_config_file ) default_config_file = paths.default_config() if not default_config_file: default_config_file = paths.default_new_config() default_exists = os.path.exists(default_config_file) default_islink = os.path.islink(default_config_file) if default_exists and not default_islink: message = dedent(''' Can not link %s as default account. A default account configuration file from a former azurectl version was found. Consider one of the following options to handle the config file: %s 1. Delete the configuration file if no longer needed 2. Move the configuration file with context information to ~/.config/azurectl/config.<context> ''').strip() raise AzureConfigDefaultLinkError( message % (account_config_file, default_config_file) ) if default_exists: os.remove(default_config_file) os.symlink(account_config_file, default_config_file)
def test_home_path_linux(self): with patch.dict('os.environ', {'HOME': 'foo'}): paths = ConfigFilePath(platform='lin') assert paths.default_new_config() == \ os.environ['HOME'] + '/.config/azurectl/config'