Exemplo n.º 1
0
 def test_get_config_file(self, mock_isfile):
     mock_isfile.return_value = True
     with patch.dict('os.environ', {'HOME': 'foo'}):
         assert Config.get_config_file(
             account_name='bob',
             platform='lin') == 'foo/.config/azurectl/bob.config'
     with patch.dict('os.environ', {'HOME': 'foo'}):
         assert Config.get_config_file(filename='bob',
                                       platform='lin') == 'bob'
     with patch.dict('os.environ', {'HOME': 'foo'}):
         assert Config.get_config_file(
             platform='lin') == 'foo/.config/azurectl/config'
Exemplo n.º 2
0
 def remove(self):
     """
         remove account configuration file
     """
     default_config_file = Config.get_config_file()
     os.remove(self.filename)
     if default_config_file and os.path.islink(default_config_file):
         link_target = os.readlink(default_config_file)
         if not os.path.exists(link_target):
             # account configuration was also configured as default account
             # remove the now broken default config symlink too
             os.remove(default_config_file)
Exemplo n.º 3
0
 def __check_account_existing_in_default_config(self):
     default_config = None
     try:
         default_config = Config()
     except Exception:
         # ignore exception thrown if no config file exists
         pass
     if default_config:
         account_section_name = 'account:' + self.command_args['--name']
         if default_config.config.has_section(account_section_name):
             raise AzureAccountConfigurationError(
                 'Account %s already configured in file %s' % (
                     self.command_args['--name'],
                     Config.get_config_file()
                 )
             )
Exemplo n.º 4
0
 def __load_account_setup(self, for_account=None):
     self.setup = AccountSetup(
         Config.get_config_file(account_name=for_account)
     )