Beispiel #1
0
def test_update_on_cockpit_ostree_pr_exists(cockpit_ostree):
    upstream_path, dist_git_path = cockpit_ostree

    def mocked_new_sources(sources=None):
        if not Path(sources).is_file():
            raise RuntimeError("archive does not exist")

    flexmock(PkgTool, new_sources=mocked_new_sources)
    flexmock(PackitAPI, init_kerberos_ticket=lambda: None)

    flexmock(
        DistGit,
        push_to_fork=lambda *args, **kwargs: None,
        is_archive_in_lookaside_cache=lambda archive_path: False,
        upload_to_lookaside_cache=lambda archive, pkg_tool: None,
        download_upstream_archive=lambda: "the-archive",
    )
    pr = flexmock(url="https://example.com/pull/1")
    flexmock(DistGit).should_receive("existing_pr").and_return(pr)

    pc = get_local_package_config(str(upstream_path))
    up_lp = LocalProject(working_dir=upstream_path)
    c = get_test_config()
    api = PackitAPI(c, pc, up_lp)
    api._dg = DistGit(c, pc)
    api._dg._local_project = LocalProject(working_dir=dist_git_path)

    with cwd(upstream_path):
        assert pr == api.sync_release(
            dist_git_branch="main",
            use_local_content=False,
            version="179",
            force_new_sources=False,
            create_pr=True,
        )
Beispiel #2
0
def test_set_spec_ver_empty_changelog(tmpdir):
    t = Path(str(tmpdir))

    u_remote_path = t / "upstream_remote"
    u_remote_path.mkdir(parents=True, exist_ok=True)

    subprocess.check_call(["git", "init", "--bare", "."], cwd=u_remote_path)

    u = t / "upstream_git"
    shutil.copytree(EMPTY_CHANGELOG, u)
    initiate_git_repo(u, tag="0.1.0")

    with cwd(tmpdir):
        c = get_test_config()

        pc = get_local_package_config(str(u))
        pc.upstream_project_url = str(u)
        lp = LocalProject(working_dir=str(u))

        ups = Upstream(c, pc, lp)

    new_ver = "1.2.3"
    ups.specfile.set_spec_version(version=new_ver, changelog_entry="- asdqwe")

    assert ups.get_specfile_version() == new_ver
    assert "%changelog" not in u.joinpath("beer.spec").read_text()
Beispiel #3
0
def test_get_builds(upstream_n_distgit, expected_results, br_list, number_of_builds):
    u, d = upstream_n_distgit
    from bodhi.client.bindings import BodhiClient

    c = get_test_config()
    pc = get_local_package_config(str(u))
    pc.downstream_project_url = str(d)
    pc.upstream_project_url = str(u)
    dg = DistGit(c, pc)
    pc = get_local_package_config(str(u))
    flexmock(BodhiClient).should_receive("latest_builds").and_return(
        BODHI_LATEST_BUILDS
    )
    status = Status(c, pc, u, dg)
    flexmock(
        PagureProject,
        get_git_urls=lambda: {"git": "foo.git"},
        fork_create=lambda: None,
        get_fork=lambda: PagureProject("", "", PagureService()),
        get_branches=br_list,
    )
    assert status
    table = status.get_builds(number_of_builds)
    assert table
    assert len(table.keys()) == number_of_builds
    assert table == expected_results
Beispiel #4
0
def api_instance(upstream_and_remote, distgit_and_remote):
    u, _ = upstream_and_remote
    d, _ = distgit_and_remote

    c = get_test_config()
    api = get_packit_api(config=c, local_project=LocalProject(working_dir=Path.cwd()))
    return u, d, api
Beispiel #5
0
def test_basic_local_update_direct_push(upstream_distgit_remote,
                                        mock_remote_functionality_upstream):
    """ basic propose-update test: mock remote API, use local upstream and dist-git """
    upstream, distgit, remote_dir = upstream_distgit_remote

    with cwd(upstream):
        c = get_test_config()

        pc = get_local_package_config(str(upstream))
        pc.upstream_project_url = str(upstream)
        pc.dist_git_clone_path = str(distgit)
        up_lp = LocalProject(working_dir=str(upstream))
        api = PackitAPI(c, pc, up_lp)
        api.sync_release("master", "0.1.0", create_pr=False)

        remote_dir_clone = Path(f"{remote_dir}-clone")
        subprocess.check_call(
            ["git", "clone", remote_dir,
             str(remote_dir_clone)],
            cwd=str(remote_dir_clone.parent),
        )

        spec = get_specfile(str(remote_dir_clone / "beer.spec"))
        assert spec.get_version() == "0.1.0"
        assert (remote_dir_clone / "README.packit").is_file()
Beispiel #6
0
def test_set_spec_ver_empty_changelog(tmp_path):
    u_remote_path = tmp_path / "upstream_remote"
    u_remote_path.mkdir(parents=True, exist_ok=True)

    create_new_repo(u_remote_path, ["--bare"])

    u = tmp_path / "upstream_git"
    shutil.copytree(EMPTY_CHANGELOG, u)
    initiate_git_repo(u, tag="0.1.0")

    with cwd(tmp_path):
        c = get_test_config()

        pc = get_local_package_config(str(u))
        pc.upstream_project_url = str(u)
        lp = LocalProject(working_dir=u)

        ups = Upstream(c, pc, lp)

    new_ver = "1.2.3"
    ups.specfile.version = new_ver
    ups.specfile.add_changelog_entry("- asdqwe")

    assert ups.get_specfile_version() == new_ver
    assert "%changelog" not in u.joinpath("beer.spec").read_text()
Beispiel #7
0
def test_set_spec_macro_source(tmp_path):
    u_remote_path = tmp_path / "upstream_remote"
    u_remote_path.mkdir(parents=True, exist_ok=True)

    create_new_repo(u_remote_path, ["--bare"])

    u = tmp_path / "upstream_git"
    shutil.copytree(UPSTREAM_MACRO_IN_SOURCE, u)
    initiate_git_repo(u, tag="0.1.0")

    with cwd(tmp_path):
        c = get_test_config()

        pc = get_local_package_config(str(u))
        pc.upstream_project_url = str(u)
        lp = LocalProject(working_dir=u)

        ups = Upstream(c, pc, lp)

    expected_sources = ups.specfile.sources
    new_ver = "1.2.3"
    ups.specfile.set_spec_version(version=new_ver, changelog_entry="- asdqwe")

    assert ups.get_specfile_version() == new_ver
    assert ups.specfile.sources == expected_sources

    expected_sources = ups.specfile.sources
    new_rel = "121"
    ups.specfile.set_spec_version(release=new_rel)

    assert ups.specfile.get_release() == new_rel
    assert ups.specfile.sources == expected_sources
Beispiel #8
0
def test_update_on_cockpit_ostree(cockpit_ostree):
    def mocked_new_sources(sources=None):
        if not Path(sources).is_file():
            raise RuntimeError("archive does not exist")

    flexmock(FedPKG,
             init_ticket=lambda x=None: None,
             new_sources=mocked_new_sources)

    flexmock(
        DistGit,
        push_to_fork=lambda *args, **kwargs: None,
        is_archive_in_lookaside_cache=lambda archive_path: False,
    )
    flexmock(
        PackitAPI,
        push_and_create_pr=lambda pr_title, pr_description, dist_git_branch:
        None,
    )

    pc = get_local_package_config(str(cockpit_ostree))
    up_lp = LocalProject(working_dir=str(cockpit_ostree))
    c = get_test_config()

    api = PackitAPI(c, pc, up_lp)
    with cwd(cockpit_ostree):
        api.sync_release(
            "master",
            use_local_content=False,
            version="179",
            force_new_sources=False,
            create_pr=True,
        )

    assert api.dg.download_upstream_archive().is_file()
Beispiel #9
0
def test_is_downstream(distgit_and_remote):
    downstream, _ = distgit_and_remote
    c = get_test_config()
    api = get_packit_api(config=c,
                         local_project=LocalProject(working_dir=downstream))
    assert api.downstream_local_project
    assert not api.upstream_local_project
    assert api.downstream_local_project.working_dir == downstream
Beispiel #10
0
def test_url_is_upstream():
    c = get_test_config()
    api = get_packit_api(
        config=c,
        local_project=LocalProject(git_url="https://github.com/packit/ogr"),
    )
    assert api.upstream_local_project
    assert not api.downstream_local_project
Beispiel #11
0
def test_url_is_downstream():
    c = get_test_config()
    api = get_packit_api(
        config=c,
        local_project=LocalProject(git_url="https://src.fedoraproject.org/rpms/packit"),
    )
    assert api.downstream_local_project
    assert not api.upstream_local_project
def test_srpm_on_example(example_repo):
    c = get_test_config()
    api = get_packit_api(
        config=c, local_project=LocalProject(working_dir=str(example_repo)))
    with cwd(example_repo):
        path = api.create_srpm()
    assert path.exists()
    build_srpm(path)
Beispiel #13
0
def distgit_instance(upstream_n_distgit, mock_remote_functionality_upstream):
    u, d = upstream_n_distgit
    c = get_test_config()
    pc = get_local_package_config(str(u))
    pc.downstream_project_url = str(d)
    pc.upstream_project_url = str(u)
    dg = DistGit(c, pc)
    return d, dg
Beispiel #14
0
def mock_api_for_source_git(
    sourcegit: Path, distgit: Path, up_local_project: LocalProject
):
    with cwd(sourcegit):
        c = get_test_config()
        pc = get_local_package_config(str(sourcegit))
        pc.upstream_project_url = str(sourcegit)
        pc.dist_git_clone_path = str(distgit)
        return PackitAPI(c, pc, up_local_project)
Beispiel #15
0
def test_loop(mock_upstream_remote_functionality, github_release_fedmsg):
    def mocked_iter_releases():
        msg = copy.deepcopy(github_release_fedmsg)
        yield msg["topic"], msg

    flexmock(Consumerino, iterate_releases=mocked_iter_releases)
    conf = get_test_config()
    api = PackitBotAPI(conf)
    api.watch_upstream_release()
Beispiel #16
0
def upstream_mock(local_project_mock, package_config_mock):
    upstream = Upstream(
        config=get_test_config(),
        package_config=package_config_mock,
        local_project=LocalProject(working_dir=str("test")),
    )
    flexmock(upstream)
    upstream.should_receive("local_project").and_return(local_project_mock)
    return upstream
Beispiel #17
0
def test_single_message(github_release_fedmsg, mock_upstream_remote_functionality):
    u, d = mock_upstream_remote_functionality

    conf = get_test_config()
    api = PackitBotAPI(conf)
    api.sync_upstream_release_with_fedmsg(github_release_fedmsg)
    assert (d / TARBALL_NAME).is_file()
    spec = SpecFile(str(d / "beer.spec"), None)
    assert spec.get_version() == "0.1.0"
Beispiel #18
0
def api_instance_source_git(sourcegit_n_distgit):
    sourcegit, distgit = sourcegit_n_distgit
    with cwd(sourcegit):
        c = get_test_config()
        pc = get_local_package_config(str(sourcegit))
        pc.upstream_project_url = str(sourcegit)
        pc.downstream_project_url = str(distgit)
        up_lp = LocalProject(path_or_url=str(sourcegit))
        api = PackitAPI(c, pc, up_lp)
        return api
Beispiel #19
0
def test_srpm_on_cockpit_ostree(cockpit_ostree):
    upstream_path, dist_git_path = cockpit_ostree

    pc = get_local_package_config(str(upstream_path))
    up_lp = LocalProject(working_dir=str(upstream_path))
    c = get_test_config()
    api = PackitAPI(c, pc, up_lp)

    with cwd(upstream_path):
        api.create_srpm()
Beispiel #20
0
def distgit_instance(upstream_and_remote, distgit_and_remote,
                     mock_remote_functionality_upstream):
    u, _ = upstream_and_remote
    d, _ = distgit_and_remote
    c = get_test_config()
    pc = get_local_package_config(str(u))
    pc.dist_git_clone_path = str(d)
    pc.upstream_project_url = str(u)
    dg = DistGit(c, pc)
    return d, dg
Beispiel #21
0
def api_instance_source_git(sourcegit_and_remote, distgit_and_remote):
    sourcegit, _ = sourcegit_and_remote
    distgit, _ = distgit_and_remote
    with cwd(sourcegit):
        c = get_test_config()
        pc = get_local_package_config(str(sourcegit))
        pc.upstream_project_url = str(sourcegit)
        pc.dist_git_clone_path = str(distgit)
        up_lp = LocalProject(working_dir=str(sourcegit))
        api = PackitAPI(c, pc, up_lp)
        return api
Beispiel #22
0
def api_instance(upstream_n_distgit):
    u, d = upstream_n_distgit

    chdir(u)
    c = get_test_config()

    pc = get_local_package_config(str(u))
    pc.upstream_project_url = str(u)

    api = PackitAPI(c, pc)
    return u, d, api
Beispiel #23
0
def test_loop(mock_remote_functionality_upstream, github_release_fedmsg):
    u, d = mock_remote_functionality_upstream

    def mocked_iter_releases():
        msg = copy.deepcopy(github_release_fedmsg)
        yield msg["topic"], msg

    flexmock(Repo).should_receive("clone_from").and_return(git.Repo(str(u)))
    flexmock(Consumerino, iterate_releases=mocked_iter_releases)
    conf = get_test_config()
    api = PackitBotAPI(conf)
    api.watch_upstream_release()
Beispiel #24
0
def upstream_instance(upstream_n_distgit, tmpdir):
    with cwd(tmpdir):
        u, d = upstream_n_distgit
        c = get_test_config()

        pc = get_local_package_config(str(u))
        pc.upstream_project_url = str(u)
        pc.dist_git_clone_path = str(d)
        lp = LocalProject(working_dir=str(u))

        ups = Upstream(c, pc, lp)
        yield u, ups
Beispiel #25
0
def upstream_instance(upstream_n_distgit):
    u, d = upstream_n_distgit

    chdir(u)
    c = get_test_config()

    pc = get_local_package_config(str(u))
    pc.upstream_project_url = str(u)
    pc.downstream_project_url = str(d)

    ups = Upstream(c, pc)
    return u, ups
Beispiel #26
0
def test_basic_build(upstream_n_distgit, mock_remote_functionality_upstream):
    u, d = upstream_n_distgit

    with cwd(u):
        c = get_test_config()

        pc = get_local_package_config(str(u))
        pc.upstream_project_url = str(u)
        pc.downstream_project_url = str(d)
        up_lp = LocalProject(path_or_url=u)

        api = PackitAPI(c, pc, up_lp)
        api.build("master")
Beispiel #27
0
def test_single_message(github_release_fedmsg,
                        mock_remote_functionality_upstream):
    u, d = mock_remote_functionality_upstream

    conf = get_test_config()
    api = PackitBotAPI(conf)

    flexmock(Repo).should_receive("clone_from").and_return(git.Repo(str(u)))

    api.sync_upstream_release_with_fedmsg(github_release_fedmsg)
    assert (d / TARBALL_NAME).is_file()
    spec = get_specfile(str(d / "beer.spec"))
    assert spec.get_version() == "0.1.0"
Beispiel #28
0
def test_get_releases(upstream_instance, distgit_instance, expected_releases):
    u, up = upstream_instance
    d, dg = distgit_instance
    c = get_test_config()
    pc = get_local_package_config(str(u))
    up.local_project.git_project = flexmock()

    flexmock(up.local_project.git_project).should_receive(
        "get_releases").and_return(expected_releases)
    status = Status(c, pc, up, dg)
    releases = status.get_up_releases()
    assert len(releases) == len(expected_releases)
    assert releases == expected_releases
Beispiel #29
0
def upstream_instance(upstream_and_remote, distgit_and_remote, tmp_path):
    with cwd(tmp_path):
        u, _ = upstream_and_remote
        d, _ = distgit_and_remote
        c = get_test_config()

        pc = get_local_package_config(str(u))
        pc.upstream_project_url = str(u)
        pc.dist_git_clone_path = str(d)
        lp = LocalProject(working_dir=str(u))

        ups = Upstream(c, pc, lp)
        yield u, ups
Beispiel #30
0
def upstream_mock(local_project_mock, package_config_mock):
    upstream = Upstream(
        config=get_test_config(),
        package_config=package_config_mock,
        local_project=LocalProject(working_dir="test"),
    )
    flexmock(upstream)
    upstream.should_receive("local_project").and_return(local_project_mock)
    upstream.should_receive("absolute_specfile_path").and_return("_spec_file_path")
    upstream.should_receive("absolute_specfile_dir").and_return("_spec_file_dir")
    upstream.should_receive("is_dirty").and_return(False)
    upstream.should_receive("create_patches")

    return upstream