def test_copr_build_fails_in_packit(pull_request_event):
    # status is set for each build-target (4x):
    #  - Building SRPM ...
    #  - Build failed, check latest comment for details.
    helper = build_helper(event=pull_request_event)
    templ = "packit-stg/rpm-build-fedora-{ver}-x86_64"
    for v in ["29", "30", "31", "rawhide"]:
        flexmock(GitProject).should_receive("set_commit_status").with_args(
            "528b803be6f93e19ca4130bf4976f2800a3004c4",
            CommitStatus.pending,
            "",
            "Building SRPM ...",
            templ.format(ver=v),
            trim=True,
        ).and_return().once()
    for v in ["29", "30", "31", "rawhide"]:
        flexmock(GitProject).should_receive("set_commit_status").with_args(
            "528b803be6f93e19ca4130bf4976f2800a3004c4",
            CommitStatus.failure,
            "https://localhost:5000/srpm-build/2/logs",
            "SRPM build failed, check the logs for details.",
            templ.format(ver=v),
            trim=True,
        ).and_return().once()
    flexmock(RedisCoprBuild).should_receive("create").and_return(FakeCoprBuildModel())
    flexmock(SRPMBuild).should_receive("create").and_return(SRPMBuild(id=2))
    flexmock(CoprBuild).should_receive("get_or_create").and_return(CoprBuild(id=1))
    flexmock(sentry_integration).should_receive("send_to_sentry").and_return().once()
    flexmock(PackitAPI).should_receive("run_copr_build").and_raise(
        FailedCreateSRPM, "some error"
    )
    assert not helper.run_copr_build()["success"]
def test_copr_build_for_release(release_event):
    # status is set for each build-target (4x):
    #  - Building SRPM ...
    #  - Building RPM ...
    branch_build_job = JobConfig(
        type=JobType.build,
        trigger=JobConfigTriggerType.release,
        metadata={
            "branch": "build-branch",
            "owner": "nobody",
            "targets": [
                "fedora-29-x86_64",
                "fedora-30-x86_64",
                "fedora-31-x86_64",
                "fedora-rawhide-x86_64",
            ],
        },
    )
    helper = build_helper(jobs=[branch_build_job], event=release_event)
    flexmock(GitProject).should_receive("set_commit_status").and_return().times(8)
    flexmock(RedisCoprBuild).should_receive("create").and_return(FakeCoprBuildModel())
    flexmock(SRPMBuild).should_receive("create").and_return(SRPMBuild())
    flexmock(CoprBuild).should_receive("get_or_create").and_return(CoprBuild(id=1))
    flexmock(PackitAPI).should_receive("run_copr_build").and_return(1, None).once()
    assert helper.run_copr_build()["success"]
def test_copr_build_check_names():
    metadata = {"owner": "nobody", "targets": ["bright-future-x86_64"]}
    handler = build_handler(metadata)
    flexmock(BuildStatusReporter).should_receive("set_status").with_args(
        state="pending",
        description="Building SRPM ...",
        check_name="packit-stg/rpm-build-bright-future-x86_64",
        url="",
    ).and_return()
    flexmock(BuildStatusReporter).should_receive("set_status").with_args(
        state="pending",
        description="Building RPM ...",
        check_name="packit-stg/rpm-build-bright-future-x86_64",
        url="https://localhost:5000/copr-build/1/logs",
    ).and_return()

    flexmock(GitProject).should_receive(
        "set_commit_status").and_return().never()
    flexmock(RedisCoprBuild).should_receive("create").and_return(
        FakeCoprBuildModel())
    flexmock(SRPMBuild).should_receive("create").and_return(SRPMBuild())
    flexmock(CoprBuild).should_receive("get_or_create").and_return(
        CoprBuild(id=1))
    flexmock(PackitAPI).should_receive("run_copr_build").and_return(1, None)
    assert handler.run_copr_build()["success"]
def test_copr_build_no_targets(pull_request_event):
    # status is set for each build-target (fedora-stable => 2x):
    #  - Building SRPM ...
    #  - Building RPM ...
    helper = build_helper(event=pull_request_event, metadata={"owner": "nobody"})
    flexmock(GitProject).should_receive("set_commit_status").and_return().times(4)
    flexmock(RedisCoprBuild).should_receive("create").and_return(FakeCoprBuildModel())
    flexmock(SRPMBuild).should_receive("create").and_return(SRPMBuild())
    flexmock(CoprBuild).should_receive("get_or_create").and_return(CoprBuild(id=1))
    flexmock(PackitAPI).should_receive("run_copr_build").and_return(1, None).once()
    assert helper.run_copr_build()["success"]
def test_copr_build_success():
    # status is set for each build-target (4x):
    #  - Building SRPM ...
    #  - Building RPM ...
    handler = build_handler()
    flexmock(GitProject).should_receive(
        "set_commit_status").and_return().times(8)
    flexmock(RedisCoprBuild).should_receive("create").and_return(
        FakeCoprBuildModel())
    flexmock(SRPMBuild).should_receive("create").and_return(SRPMBuild())
    flexmock(CoprBuild).should_receive("get_or_create").and_return(
        CoprBuild(id=1))
    flexmock(PackitAPI).should_receive("run_copr_build").and_return(
        1, None).once()
    assert handler.run_copr_build()["success"]
Exemple #6
0
def test_get_logs(client):
    chroot = "foo-1-x86_64"
    state = "pending"
    build_id = 2

    project = GitProject()
    project.namespace = "john-foo"
    project.repo_name = "bar"

    pr = PullRequest()
    pr.pr_id = 234
    pr.project = project

    srpm_build = SRPMBuild()
    srpm_build.logs = "asd<br>qwe"

    c = CoprBuild()
    c.target = chroot
    c.build_id = str(build_id)
    c.srpm_build = srpm_build
    c.status = state
    c.web_url = (
        "https://copr.fedorainfracloud.org/coprs/john-foo-bar/john-foo-bar/build/2/"
    )
    c.build_logs_url = "https://localhost:5000/build/2/foo-1-x86_64/logs"
    c.pr = pr

    flexmock(CoprBuild).should_receive("get_by_id").and_return(c)

    url = f"/copr-build/1/logs"
    logs_url = get_log_url(1)
    assert logs_url.endswith(url)

    resp = client.get(url)
    expected = (
        "<html><head>"
        f"<title>Build {c.pr.project.namespace}/{c.pr.project.repo_name}"
        f" #{c.pr.pr_id}</title></head><body>"
        f"COPR Build ID: {c.build_id}<br>"
        f"State: {c.status}<br><br>"
        f'Build web interface URL: <a href="{c.web_url}">{c.web_url}</a><br>'
        f'Build logs: <a href="{c.build_logs_url}">{c.build_logs_url}</a><br>'
        "SRPM creation logs:<br><br>"
        f"<pre>{c.srpm_build.logs}</pre>"
        "<br></body></html>"
    )
    assert resp.data == expected.encode()
def test_copr_build_success_set_test_check(pull_request_event):
    # status is set for each build-target (4x):
    #  - Building SRPM ...
    #  - Building RPM ...
    # status is set for each test-target (4x):
    #  - Building SRPM ...
    #  - Building RPM ...
    test_job = JobConfig(
        type=JobType.tests, trigger=JobConfigTriggerType.pull_request, metadata={}
    )
    helper = build_helper(jobs=[test_job], event=pull_request_event)
    flexmock(GitProject).should_receive("set_commit_status").and_return().times(16)
    flexmock(RedisCoprBuild).should_receive("create").and_return(FakeCoprBuildModel())
    flexmock(SRPMBuild).should_receive("create").and_return(SRPMBuild())
    flexmock(CoprBuild).should_receive("get_or_create").and_return(CoprBuild(id=1))
    flexmock(PackitAPI).should_receive("run_copr_build").and_return(1, None).once()
    assert helper.run_copr_build()["success"]
def test_copr_build_fails_in_packit():
    # status is set for each build-target (4x):
    #  - Building SRPM ...
    #  - Build failed, check latest comment for details.
    handler = build_handler()
    flexmock(GitProject, pr_comment=lambda *args, **kw: None)
    flexmock(GitProject).should_receive(
        "set_commit_status").and_return().times(8)
    flexmock(GitProject).should_receive("pr_comment").and_return().once()
    flexmock(RedisCoprBuild).should_receive("create").and_return(
        FakeCoprBuildModel())
    flexmock(SRPMBuild).should_receive("create").and_return(SRPMBuild())
    flexmock(CoprBuild).should_receive("get_or_create").and_return(
        CoprBuild(id=1))
    flexmock(sentry_integration).should_receive(
        "send_to_sentry").and_return().once()
    flexmock(PackitAPI).should_receive("run_copr_build").and_raise(
        FailedCreateSRPM, "some error")
    assert not handler.run_copr_build()["success"]
Exemple #9
0
def test_get_srpm_logs(client):
    srpm_build = SRPMBuild()
    srpm_build.id = 2
    srpm_build.logs = "asd\nqwe"

    flexmock(SRPMBuild).should_receive("get_by_id").and_return(srpm_build)

    url = f"/srpm-build/2/logs"
    logs_url = get_srpm_log_url(2)
    assert logs_url.endswith(url)

    resp = client.get(url)
    expected = (
        "<html><head>"
        "<title>SRPM Build id=2</title></head><body>"
        "SRPM creation logs:<br><br>"
        "<pre>asd\nqwe</pre>"
        "<br></body></html>"
    )
    assert resp.data == expected.encode()