예제 #1
0
def test_commit_comment_instead_of_status(
    project,
    commit_sha,
    pr_id,
    has_pr_id,
    pr_object,
    state,
    description,
    check_name,
    url,
    exception_mock,
):
    reporter = StatusReporter(project, commit_sha, pr_id)

    exception, exception_args, exception_kwargs = exception_mock
    project.should_receive("set_commit_status").with_args(
        commit_sha, state, url, description, check_name,
        trim=True).and_raise(exception, *exception_args,
                             **exception_kwargs).once()
    project.should_receive("commit_comment").with_args(
        commit=commit_sha,
        body="\n".join([
            f"- name: {check_name}",
            f"- state: {state.name}",
            f"- url: {url if url else 'not provided'}",
        ]) + f"\n\n{description}",
    )

    if has_pr_id:
        project.should_receive("get_pr").with_args(pr_id).once().and_return(
            pr_object)

    reporter.set_status(state, description, check_name, url)
예제 #2
0
def test_set_status(
    project,
    commit_sha,
    pr_id,
    has_pr_id,
    pr_object,
    state,
    description,
    check_name,
    url,
    needs_pr_flags,
    uid,
):
    reporter = StatusReporter(project, commit_sha, pr_id)

    project.should_receive("set_commit_status").with_args(
        commit_sha, state, url, description, check_name, trim=True
    ).once()

    if has_pr_id:
        project.should_receive("get_pr").with_args(pr_id).once().and_return(pr_object)

    if needs_pr_flags:
        pr_object.should_receive("set_flag").with_args(
            check_name, description, url, state, uid
        )

    reporter.set_status(state, description, check_name, url)
예제 #3
0
def test_set_status_gitlab(
    commit_sha,
    pr_id,
    pr_object,
    state,
    description,
    check_name,
    url,
):
    project = GitlabProject(None, None, None)
    reporter = StatusReporter(project, commit_sha, pr_id)
    act_upon = flexmock(
        pr_object.source_project) if pr_id else flexmock(GitlabProject)

    act_upon.should_receive("set_commit_status").with_args(commit_sha,
                                                           state,
                                                           url,
                                                           description,
                                                           check_name,
                                                           trim=True).once()

    if pr_id is not None:
        flexmock(GitlabProject).should_receive("get_pr").with_args(
            pr_id).and_return(pr_object)

    reporter.set_status(state, description, check_name, url)