Ejemplo n.º 1
0
    def test_add_secrets_unexpected_exception(self, mock_sys_exit, mock_add_secrets):
        mock_add_secrets.side_effect = Exception
        mock_sys_exit.side_effect = SystemExit

        with self.assertRaises(SystemExit):
            with make_test_context(
                [
                    "github",
                    "add-secrets",
                    "--repo-name",
                    self.repo_name,
                    "-s",
                    self.secrets[0],
                    "--secret",
                    self.secrets[1],
                ]
            ) as ctx:
                cli.cli.invoke(ctx)

        self.mock_rli_config.assert_called_once()
        mock_add_secrets.assert_called_once_with(
            self.repo_name, self.secrets, self.mock_rli_config().rli_secrets
        )
        self.mock_logging_info.assert_not_called()
        self.mock_logging_error.assert_called_once_with(
            "There was an unexpected error while adding secrets."
        )
        mock_sys_exit.assert_called_once_with(ExitCode.UNEXPECTED_ERROR)
Ejemplo n.º 2
0
    def test_add_secrets_invalid_rli_configuration(
        self, mock_sys_exit, mock_add_secrets
    ):
        mock_add_secrets.side_effect = InvalidRLIConfiguration
        mock_sys_exit.side_effect = SystemExit

        with self.assertRaises(SystemExit):
            with make_test_context(
                [
                    "github",
                    "add-secrets",
                    "--repo-name",
                    self.repo_name,
                    "-s",
                    self.secrets[0],
                    "--secret",
                    self.secrets[1],
                ]
            ) as ctx:
                cli.cli.invoke(ctx)

        self.mock_rli_config.assert_called_once()
        mock_add_secrets.assert_called_once_with(
            self.repo_name, self.secrets, self.mock_rli_config().rli_secrets
        )
        self.mock_logging_info.assert_not_called()
        self.mock_logging_error.assert_called_once_with(
            "Your Github RLI configuration is incorrect."
        )
        mock_sys_exit.assert_called_once_with(ExitCode.INVALID_RLI_CONFIG)
Ejemplo n.º 3
0
    def test_create_repo_failure(self, mock_sys_exit, mock_create_repo):
        mock_create_repo.return_value = None
        with make_test_context([
                "github", "create-repo", "--repo-name", self.repo_name,
                "--repo-description", self.repo_desc, "--private",
                self.repo_private
        ]) as ctx:
            cli.rli.invoke(ctx)

            self.mock_rli_config.assert_called_once()
            self.mock_logging_info.assert_not_called()
            mock_sys_exit.assert_called_with(
                ExitStatus.GITHUB_EXCEPTION_RAISED)
            mock_create_repo.assert_called_with(self.repo_name, self.repo_desc,
                                                "true")
Ejemplo n.º 4
0
    def test_create_repo_success(self, mock_sys_exit, mock_create_repo):
        mock_create_repo.return_value = {"name": "some name"}

        with make_test_context([
                "github", "create-repo", "--repo-name", self.repo_name,
                "--repo-description", self.repo_desc, "--private",
                self.repo_private
        ]) as ctx:
            cli.rli.invoke(ctx)

            self.mock_rli_config.assert_called_once()
            self.mock_logging_info.assert_called_with(
                f'Here is your new repo:\n{str({"name": "some name"})}')
            mock_sys_exit.assert_called_with(ExitStatus.OK)
            mock_create_repo.assert_called_with(self.repo_name, self.repo_desc,
                                                "true")
Ejemplo n.º 5
0
    def test_add_secrets_no_repo(self, mock_sys_exit, mock_add_secrets):
        mock_add_secrets.return_value = None
        mock_sys_exit.side_effect = SystemExit
        with self.assertRaises(SystemExit):
            with make_test_context(
                [
                    "github",
                    "add-secrets",
                    "-s",
                    self.secrets[0],
                    "--secret",
                    self.secrets[1],
                ]
            ) as ctx:
                cli.cli.invoke(ctx)

        self.mock_rli_config.assert_not_called()
        mock_add_secrets.assert_not_called()
        self.mock_logging_info.assert_not_called()
        mock_sys_exit.assert_called_once_with(ExitCode.MISSING_ARG)
        self.mock_logging_error.assert_called_once_with("You must provide a repo name!")
Ejemplo n.º 6
0
    def test_add_secrets(self, mock_sys_exit, mock_add_secrets):
        mock_add_secrets.return_value = None
        with make_test_context(
            [
                "github",
                "add-secrets",
                "--repo-name",
                self.repo_name,
                "-s",
                self.secrets[0],
                "--secret",
                self.secrets[1],
            ]
        ) as ctx:
            cli.cli.invoke(ctx)

            self.mock_rli_config.assert_called_once()
            mock_add_secrets.assert_called_once_with(
                self.repo_name, self.secrets, self.mock_rli_config().rli_secrets
            )
            self.mock_logging_info.assert_called_once_with(
                "Successfully added all secrets to your repo."
            )
            mock_sys_exit.assert_called_once_with(ExitCode.OK)