def test_get_config_path_from_env_var(self):
        # arrange
        args = {}
        input_parser = GlobalInputParser(args)

        # act
        config_path = input_parser.get_config_path()

        # assert
        self.assertEqual(config_path, "some_path")
    def test_get_config_path_returns_none_when_not_exist(self):
        # arrange
        args = {}
        input_parser = GlobalInputParser(args)

        # act
        config_path = input_parser.get_config_path()

        # assert
        self.assertIsNone(config_path)
Exemplo n.º 3
0
def main():
    # Colorama init for colored output
    init()
    version = pkg_resources.get_distribution("colony-cli").version
    args = docopt(__doc__, options_first=True, version=version)
    input_parser = GlobalInputParser(args)

    # Check for new version
    VersionCheckService(version).check_for_new_version_safely()

    level = logging.DEBUG if input_parser.debug else logging.WARNING
    logging.basicConfig(format="%(levelname)s - %(message)s", level=level)

    # Validate command
    BootstrapHelper.validate_command(input_parser.command)

    # Take auth parameters
    conn = BootstrapHelper.get_connection_params(input_parser)

    argv = [input_parser.command] + input_parser.command_args

    command_class = commands_table[input_parser.command]
    command = command_class(argv, conn)
    result = command.execute()

    exit(result)
    def test_get_command_args_returns_none_when_not_exist(self):
        # arrange
        args = {}
        input_parser = GlobalInputParser(args)

        # act
        command_args = input_parser.command_args

        # assert
        self.assertIsNone(command_args)
    def test_get_token_from_env_var(self):
        # arrange
        args = {}
        input_parser = GlobalInputParser(args)

        # act
        token = input_parser.token

        # assert
        self.assertEqual(token, "colony_token")
    def test_get_debug_returns_none_when_not_exist(self):
        # arrange
        args = {}
        input_parser = GlobalInputParser(args)

        # act
        debug = input_parser.debug

        # assert
        self.assertIsNone(debug)
    def test_get_profile_returns_none_when_not_exist(self):
        # arrange
        args = {}
        input_parser = GlobalInputParser(args)

        # act
        profile = input_parser.profile

        # assert
        self.assertIsNone(profile)
    def test_get_account_returns_none_when_not_exist(self):
        # arrange
        args = {}
        input_parser = GlobalInputParser(args)

        # act
        account = input_parser.account

        # assert
        self.assertIsNone(account)
    def test_get_token_returns_none_when_not_exist(self):
        # arrange
        args = {}
        input_parser = GlobalInputParser(args)

        # act
        token = input_parser.token

        # assert
        self.assertIsNone(token)
Exemplo n.º 10
0
    def test_get_space_from_env_var(self):
        # arrange
        args = {}
        input_parser = GlobalInputParser(args)

        # act
        space = input_parser.space

        # assert
        self.assertEqual(space, "colony_space")
Exemplo n.º 11
0
    def test_get_space_returns_none_when_not_exist(self):
        # arrange
        args = {}
        input_parser = GlobalInputParser(args)

        # act
        space = input_parser.space

        # assert
        self.assertIsNone(space)
Exemplo n.º 12
0
    def test_get_account_from_env_var(self):
        # arrange
        args = {}
        input_parser = GlobalInputParser(args)

        # act
        account = input_parser.account

        # assert
        self.assertEqual(account, "colony_account")
Exemplo n.º 13
0
    def test_get_debug_from_args(self):
        # arrange
        debug_mock = Mock()
        args = {"--debug": debug_mock}
        input_parser = GlobalInputParser(args)

        # act
        debug = input_parser.debug

        # assert
        self.assertEqual(debug, debug_mock)
Exemplo n.º 14
0
    def test_get_profile_from_args(self):
        # arrange
        account_mock = Mock()
        args = {"--profile": account_mock}
        input_parser = GlobalInputParser(args)

        # act
        profile = input_parser.profile

        # assert
        self.assertEqual(profile, account_mock)
Exemplo n.º 15
0
    def test_get_command_args_from_args(self):
        # arrange
        command_args_mock = Mock()
        args = {"<args>": command_args_mock}
        input_parser = GlobalInputParser(args)

        # act
        command_args = input_parser.command_args

        # assert
        self.assertEqual(command_args, command_args_mock)
Exemplo n.º 16
0
    def test_get_account_from_args(self):
        # arrange
        account_mock = Mock()
        args = {"--account": account_mock}
        input_parser = GlobalInputParser(args)

        # act
        account = input_parser.account

        # assert
        self.assertEqual(account, account_mock)
Exemplo n.º 17
0
    def test_get_token_from_args(self):
        # arrange
        token_mock = Mock()
        args = {"--token": token_mock}
        input_parser = GlobalInputParser(args)

        # act
        token = input_parser.token

        # assert
        self.assertEqual(token, token_mock)
Exemplo n.º 18
0
    def test_get_space_from_args(self):
        # arrange
        space_mock = Mock()
        args = {"--space": space_mock}
        input_parser = GlobalInputParser(args)

        # act
        space = input_parser.space

        # assert
        self.assertEqual(space, space_mock)
Exemplo n.º 19
0
    def do_remove(self):
        profile_to_remove = self.input_parser.configure_remove.profile
        if not profile_to_remove:
            raise DocoptExit("Please provide a profile name to remove")

        try:
            config_file = GlobalInputParser.get_config_path()
            config_provider = ColonyConfigProvider(config_file)
            config_provider.remove_profile(profile_to_remove)
        except Exception as e:
            logger.exception(e, exc_info=False)
            return self.die()

        return self.success()
Exemplo n.º 20
0
    def do_list(self):
        config = None
        try:
            config_file = GlobalInputParser.get_config_path()
            config = ColonyConfigProvider(config_file).load_all()
            result_table = ConfigureListView(config).render()

        except ConfigFileMissingError:
            raise DocoptExit("Config file doesn't exist. Use 'colony configure set' to configure Colony CLI.")
        except Exception as e:
            logger.exception(e, exc_info=False)
            return self.die()

        self.message(result_table)
        return self.success()
Exemplo n.º 21
0
    def do_configure(self):
        config_file = GlobalInputParser.get_config_path()
        config_provider = ColonyConfigProvider(config_file)
        config = {}
        try:
            config = config_provider.load_all()
        except Exception:
            pass

        # read profile
        profile = input("Profile Name [default]: ")
        profile = profile or "default"

        # if profile exists set current values from profile
        current_account = config.get(profile, {}).get(ColonyConfigKeys.ACCOUNT, "")
        current_space = config.get(profile, {}).get(ColonyConfigKeys.SPACE, "")
        current_token = config.get(profile, {}).get(ColonyConfigKeys.TOKEN, "")

        # read account
        account = input(f"Colony Account (optional) [{current_account}]: ")
        account = account or current_account

        # read space name
        space = input(f"Colony Space [{current_space}]: ")
        space = space or current_space
        if not space:
            return self.die("Space cannot be empty")

        # read token
        token = getpass.getpass(f"Colony Token [{mask_token(current_token)}]: ")
        token = token or current_token
        if not token:
            return self.die("Token cannot be empty")

        # save user inputs
        config_provider.save_profile(profile, token, space, account)

        return self.success()
Exemplo n.º 22
0
 def test_help_needed_with_command_no_subcommand_args(self):
     user_input = ["sb"]
     args = docopt(doc=self.main_doc, options_first=True, argv=user_input)
     input_parser = GlobalInputParser(args)
     self.assertTrue(
         shell.BootstrapHelper.is_help_message_requested(input_parser))
Exemplo n.º 23
0
 def test_help_not_needed_with_command(self):
     user_input = ["sb", "start", "some_blueprint"]
     args = docopt(doc=self.main_doc, options_first=True, argv=user_input)
     input_parser = GlobalInputParser(args)
     self.assertFalse(
         shell.BootstrapHelper.is_help_message_requested(input_parser))