Esempio n. 1
0
def test_download_remote_sources(source, package_config, expected_url,
                                 tmp_path: Path):
    specfile_content = ("Name: rsync\n"
                        "Version: 3.1.3\n"
                        "Release: 1\n"
                        f"Source0: {source}\n"
                        "License: GPLv3+\n"
                        "Summary: rsync\n"
                        "%description\nrsync\n")
    spec_path = tmp_path / "rsync.spec"
    spec_path.write_text(specfile_content)
    specfile = Specfile(spec_path, sources_dir=tmp_path)
    base_git = PackitRepositoryBase(config=flexmock(),
                                    package_config=package_config)
    flexmock(base_git).should_receive("specfile").and_return(specfile)

    expected_path = tmp_path / "rsync-3.1.3.tar.gz"

    # sadly we can't mock os.path.is_file, b/c the function is defined in posixpath.py
    # and flexmock is not able to mock that
    def mocked_download_file(url, destination_path, blocksize=8192):
        assert url == expected_url
        Path(destination_path).write_text("1")

    flexmock(DownloadHelper, download_file=mocked_download_file)

    base_git.download_remote_sources()

    assert expected_path.exists()
Esempio n. 2
0
    def test_download_remote_sources_via_spec(self):
        """
        Use case: package_config.sources and Source0 are out of sync,
        make sure packit downloads correct archive specifiec in the spec file
        """
        # we should use an actual git.centos.org url but we'd store the tarball in our history
        # which we don't want I'd say
        # "https://git.centos.org/sources/rsync/c8s/82e7829c0b3cefbd33c233005341e2073c425629"
        git_centos_org_url = "https://example.org/"
        package_config = PackageConfig(
            specfile_path="rsync.spec",
            sources=[
                SourcesItem(
                    path="rsync-3.1.2.tar.gz",
                    url=git_centos_org_url,
                ),
            ],
            jobs=[],
        )
        # same drill here, let's not store tarballs in our git-history
        # source = "https://download.samba.org/pub/rsync/src/rsync-3.1.3.tar.gz"
        source = "https://httpbin.org/anything/rsync-3.1.3.tar.gz"

        base_git = PackitRepositoryBase(config=flexmock(),
                                        package_config=package_config)
        specfile_content = ("Name: rsync\n"
                            "Version: 3.1.3\n"
                            "Release: 1\n"
                            f"Source0: {source}\n"
                            "License: GPLv3+\n"
                            "Summary: rsync\n"
                            "%description\nrsync\n")
        tmp = Path(self.static_tmp)
        spec_path = tmp / "rsync.spec"
        spec_path.write_text(specfile_content)
        specfile = Specfile(spec_path, sourcedir=tmp, autosave=True)
        flexmock(base_git).should_receive("specfile").and_return(specfile)

        def mocked_is_file():
            import inspect

            # return False only if Path.is_file() is called directly from within
            # the download_remote_sources() method
            # this is necessary because specfile relies on Path.is_file() as well
            return inspect.stack()[3].function != "download_remote_sources"

        flexmock(Path).should_receive("is_file").replace_with(mocked_is_file)

        base_git.download_remote_sources()

        expected_path = tmp / "rsync-3.1.3.tar.gz"
        assert Path(expected_path).exists()