Exemplo n.º 1
0
    def test_opens_nothing_if_open_prompt_returns_false(
            self, with_issues, parsed_args_issues_dir, api_mock):
        """Test that the callback does not attempt to open any issues if the
        'may I open' prompt returns false.
        """
        args_dict = vars(parsed_args_issues_dir)
        args_dict["batch_mode"] = False
        parsed_args_interactive = argparse.Namespace(**args_dict)

        with mock.patch("builtins.input", return_value="n", autospec=True):
            feedback.callback(args=parsed_args_interactive, api=api_mock)

        assert not api_mock.create_issue.called
Exemplo n.º 2
0
    def test_opens_issues_from_issues_dir(self, with_issues,
                                          parsed_args_issues_dir, api_mock):
        """Test that the callback calls the API.open_issue for the expected
        repos and issues, when the issues all exist and are well formed.
        """
        expected_calls = [
            mock.call(issue.title, issue.body, mock.ANY)
            for repo_name, issue in with_issues
        ]

        feedback.callback(args=parsed_args_issues_dir, api=api_mock)

        api_mock.create_issue.assert_has_calls(expected_calls, any_order=True)
Exemplo n.º 3
0
    def test_opens_issues_from_multi_issues_file(
            self, with_multi_issues_file, api_mock,
            parsed_args_multi_issues_file):
        """Test that the callback opens issues correctly when they are all
        contained in a multi issues file.
        """
        issues_file, repos_and_issues = with_multi_issues_file
        expected_calls = [
            mock.call(issue.title, issue.body, mock.ANY)
            for repo_name, issue in repos_and_issues
        ]

        feedback.callback(args=parsed_args_multi_issues_file, api=api_mock)

        api_mock.create_issue.assert_has_calls(expected_calls)
Exemplo n.º 4
0
    def test_aborts_if_issue_is_missing(self, with_issues,
                                        parsed_args_issues_dir, api_mock,
                                        tmp_path):
        """Test that the callback exits with a plug.PlugError if any of the
        expected issues is not found.
        """
        repo_without_issue = plug.generate_repo_name(STUDENT_TEAM_NAMES[-1],
                                                     ASSIGNMENT_NAMES[0])
        missing_file = tmp_path / "{}.md".format(repo_without_issue)
        missing_file.unlink()

        with pytest.raises(plug.PlugError) as exc_info:
            feedback.callback(args=parsed_args_issues_dir, api=api_mock)

        assert repo_without_issue in str(exc_info.value)
        assert not api_mock.create_issue.called
Exemplo n.º 5
0
    def test_ignores_missing_issue_if_allow_missing(self, with_issues,
                                                    parsed_args_issues_dir,
                                                    api_mock, tmp_path):
        """Test that missing issues are ignored if --allow-mising is set."""
        repo_without_issue = plug.generate_repo_name(STUDENT_TEAM_NAMES[-1],
                                                     ASSIGNMENT_NAMES[0])
        (tmp_path / "{}.md".format(repo_without_issue)).unlink()
        expected_calls = [
            mock.call(issue.title, issue.body, mock.ANY)
            for repo_name, issue in with_issues
            if repo_name != repo_without_issue
        ]
        args_dict = vars(parsed_args_issues_dir)
        args_dict["allow_missing"] = True
        args = argparse.Namespace(**args_dict)

        feedback.callback(args=args, api=api_mock)

        api_mock.create_issue.assert_has_calls(expected_calls, any_order=True)
Exemplo n.º 6
0
    def test_skips_unexpected_issues_in_multi_issues_file(
            self, with_multi_issues_file, parsed_args_multi_issues_file,
            api_mock):
        """Test that an exception is raised if one or more issues are found
        relating to student repos that ar not in prod(assignments, students).
        """
        student_teams = parsed_args_multi_issues_file.students
        args_dict = vars(parsed_args_multi_issues_file)
        args_dict["students"] = student_teams[:-1]
        args = argparse.Namespace(**args_dict)
        unexpected_repos = plug.generate_repo_names(student_teams[-1:],
                                                    ASSIGNMENT_NAMES)

        _, repos_and_issues = with_multi_issues_file
        expected_calls = [
            mock.call(issue.title, issue.body, mock.ANY)
            for repo_name, issue in repos_and_issues
            if repo_name not in unexpected_repos
        ]

        feedback.callback(args=args, api=api_mock)

        api_mock.create_issue.assert_has_calls(expected_calls, any_order=True)