Ejemplo n.º 1
0
    def test_strip_common_prefix_symlink(self):
        # Create tar file for testing
        os.makedirs(os.path.join("src", "test_prefix"))
        file_to_tar = os.path.join("src", "test_prefix", "test.txt")
        open(file_to_tar, "w").close()

        file_to_link = os.path.join("src", "test_prefix", "link.txt")
        os.symlink("./test.txt", file_to_link)
        self.assertTrue(os.path.islink(file_to_link))

        def check_for_symlink(tarinfo):
            self.assertTrue(tarinfo.issym())
            self.assertThat(file_to_link, Equals(tarinfo.name))
            self.assertThat(
                file_to_tar,
                Equals(
                    os.path.normpath(
                        os.path.join(os.path.dirname(file_to_tar),
                                     tarinfo.linkname))),
            )
            return tarinfo

        tar = tarfile.open(os.path.join("src", "test.tar"), "w")
        tar.add(file_to_tar)
        tar.add(file_to_link, filter=check_for_symlink)
        tar.close()

        tar_source = sources.Tar(os.path.join("src", "test.tar"), "dst")
        os.mkdir("dst")
        tar_source.pull()

        # The 'test_prefix' part of the path should have been removed
        self.assertTrue(os.path.exists(os.path.join("dst", "test.txt")))
        self.assertTrue(os.path.exists(os.path.join("dst", "link.txt")))
Ejemplo n.º 2
0
 def _maven_tar(self):
     if self._maven_tar_handle is None:
         maven_uri = _MAVEN_URL.format(version=self._maven_version)
         self._maven_tar_handle = sources.Tar(
             maven_uri,
             self._maven_dir,
             source_checksum=self._maven_checksum)
     return self._maven_tar_handle
Ejemplo n.º 3
0
    def test_strip_common_prefix(self):
        # Create tar file for testing
        os.makedirs(os.path.join("src", "test_prefix"))
        file_to_tar = os.path.join("src", "test_prefix", "test.txt")
        open(file_to_tar, "w").close()
        tar = tarfile.open(os.path.join("src", "test.tar"), "w")
        tar.add(file_to_tar)
        tar.close()

        tar_source = sources.Tar(os.path.join("src", "test.tar"), "dst")
        os.mkdir("dst")
        tar_source.pull()

        # The 'test_prefix' part of the path should have been removed
        self.assertTrue(os.path.exists(os.path.join("dst", "test.txt")))
Ejemplo n.º 4
0
    def test_pull_twice_downloads_once(self, mock_prov):
        """If a source checksum is defined, the cache should be tried first."""
        source = "http://{}:{}/{file_name}".format(*self.server.server_address,
                                                   file_name="test.tar")
        expected_checksum = ("sha384/d9da1f5d54432edc8963cd817ceced83f7c6d61d3"
                             "50ad76d1c2f50c4935d11d50211945ca0ecb980c04c98099"
                             "085b0c3")
        tar_source = sources.Tar(source,
                                 self.path,
                                 source_checksum=expected_checksum)

        tar_source.pull()
        with mock.patch("requests.get",
                        new=mock.Mock(wraps=requests.get)) as download_spy:
            tar_source.pull()
            self.assertThat(download_spy.call_count, Equals(0))
Ejemplo n.º 5
0
    def test_pull_tarball_must_download_to_sourcedir(self, mock_prov):
        plugin_name = "test_plugin"
        dest_dir = os.path.join("parts", plugin_name, "src")
        os.makedirs(dest_dir)
        tar_file_name = "test.tar"
        source = "http://{}:{}/{file_name}".format(*self.server.server_address,
                                                   file_name=tar_file_name)
        tar_source = sources.Tar(source, dest_dir)

        tar_source.pull()

        source_file = os.path.join(dest_dir, tar_file_name)
        mock_prov.assert_called_once_with(dest_dir,
                                          src=source_file,
                                          clean_target=False)
        with open(os.path.join(dest_dir, tar_file_name), "r") as tar_file:
            self.assertThat(tar_file.read(), Equals("Test fake file"))
Ejemplo n.º 6
0
 def _ant_tar(self):
     if self._ant_tar_handle is None:
         ant_uri = _ANT_ARCHIVE_FORMAT_URL.format(version=self._ant_version)
         self._ant_tar_handle = sources.Tar(
             ant_uri, self._ant_dir, source_checksum=self._ant_checksum)
     return self._ant_tar_handle