def test_get_or_create_pr():
    clean_db()
    s = get_sa_session()

    try:
        expected_pr = PullRequest.get_or_create(pr_id=42,
                                                namespace="clapton",
                                                repo_name="layla")
        actual_pr = PullRequest.get_or_create(pr_id=42,
                                              namespace="clapton",
                                              repo_name="layla")

        assert s.query(PullRequest).count() == 1
        assert expected_pr.project_id == actual_pr.project_id

        expected_pr = PullRequest.get_or_create(pr_id=42,
                                                namespace="clapton",
                                                repo_name="cocaine")
        actual_pr = PullRequest.get_or_create(pr_id=42,
                                              namespace="clapton",
                                              repo_name="cocaine")

        assert s.query(PullRequest).count() == 2
        assert expected_pr.project_id == actual_pr.project_id
    finally:
        clean_db()
def copr_build():
    proj = GitProject(id=1, repo_name="bar", namespace="foo")
    pr = PullRequest(id=1, pr_id=123)
    pr.project = proj
    c = CoprBuild(id=1)
    c.pr = pr
    return c
def copr_build():
    proj = GitProject(id=1, repo_name="bar", namespace="foo")
    pr = PullRequest(id=1, pr_id=123)
    pr.project = proj
    c = CoprBuild(id=1)
    c.pr = pr
    c.commit_sha = "0011223344"
    return c
Beispiel #4
0
def test_errors_while_doing_db():
    with get_sa_session() as session:
        try:
            try:
                PullRequest.get_or_create(pr_id="nope", namespace="", repo_name=False)
            except ProgrammingError:
                pass
            assert len(session.query(PullRequest).all()) == 0
            PullRequest.get_or_create(pr_id=111, namespace="asd", repo_name="qwe")
            assert len(session.query(PullRequest).all()) == 1
        finally:
            clean_db()
Beispiel #5
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()