Ejemplo n.º 1
0
def test_hash_archive_sha256():
    expect_hash = ('795f4b4446b0ea968b9201c25e8c1ef8a6ade710ebca4657dd879c'
                   '35916ad362')
    arc = Archive(tc.TAR_FILE, target='./temp', hash=expect_hash)
    arc.download()
    assert hash_archive(arc.arc_file) == expect_hash
    os.remove(arc.arc_file)
Ejemplo n.º 2
0
 def setup(self):
     self.test_dir = os.path.join(tc.CONF.path_to("source"), "tmux")
     self.archive = Archive(
         tc.TAR_FILE,
         target=self.test_dir,
         hash="795f4b4446b0ea968b9201c25e8c1ef8a6ade710" "ebca4657dd879c35916ad362",
     )
Ejemplo n.º 3
0
 def test_filename_argument(self):
     self.archive = Archive(tc.TAR_FILE, target=self.test_dir,
                            filename='file.tar.gz',
                            hash='795f4b4446b0ea968b9201c25e8c1ef8a6ade710'
                            'ebca4657dd879c35916ad362')
     self.archive.download()
     assert os.path.exists(self.archive.arc_file)
     assert os.path.basename(self.archive.arc_file) == 'file.tar.gz'
Ejemplo n.º 4
0
 def test_download_bad_hash(self):
     self.archive = Archive(tc.TAR_FILE, target=self.test_dir, hash="bad hash")
     with pytest.raises(PakitError):
         self.archive.download()
Ejemplo n.º 5
0
class TestArchive(object):
    def setup(self):
        self.test_dir = os.path.join(tc.CONF.path_to("source"), "tmux")
        self.archive = Archive(
            tc.TAR_FILE,
            target=self.test_dir,
            hash="795f4b4446b0ea968b9201c25e8c1ef8a6ade710" "ebca4657dd879c35916ad362",
        )

    def teardown(self):
        tc.delete_it(self.archive.arc_file)
        tc.delete_it(self.test_dir)

    def test__str__(self):
        expect = "Archive: " + self.archive.uri
        assert str(self.archive) == expect

    def test_ready(self):
        with self.archive:
            assert self.archive.ready

    def test_with_nested(self):
        with self.archive:
            with self.archive:
                assert self.archive.ready

    def test_filename_argument(self):
        self.archive = Archive(
            tc.TAR_FILE,
            target=self.test_dir,
            filename="file.tar.gz",
            hash="795f4b4446b0ea968b9201c25e8c1ef8a6ade710" "ebca4657dd879c35916ad362",
        )
        self.archive.download()
        assert os.path.exists(self.archive.arc_file)
        assert os.path.basename(self.archive.arc_file) == "file.tar.gz"

    def test_download_remote(self):
        self.archive.uri = tc.TAR
        self.archive.download()
        assert os.path.exists(self.archive.arc_file)

    def test_download_local(self):
        self.archive.download()
        assert os.path.exists(self.archive.arc_file)

    def test_download_bad_hash(self):
        self.archive = Archive(tc.TAR_FILE, target=self.test_dir, hash="bad hash")
        with pytest.raises(PakitError):
            self.archive.download()

    def test_extract(self):
        with self.archive:
            assert os.path.exists(self.test_dir)
            assert len(os.listdir(self.test_dir)) != 0
            assert os.path.join(self.test_dir, "README")

    def test_hash(self):
        assert self.archive.src_hash == self.archive.actual_hash()

    def test_clean(self):
        self.archive.download()
        self.archive.clean()
        assert not os.path.exists(self.archive.arc_file)
        assert not os.path.exists(self.archive.target)

    def test_clean_extracted(self):
        with self.archive:
            self.archive.clean()
            assert not os.path.exists(self.archive.arc_file)
            assert not os.path.exists(self.archive.target)
Ejemplo n.º 6
0
 def setup(self):
     self.test_dir = os.path.join(tc.CONF.path_to('source'), 'tmux')
     self.archive = Archive(tc.TAR_FILE, target=self.test_dir,
                            filename=os.path.basename(tc.TAR_FILE),
                            hash='795f4b4446b0ea968b9201c25e8c1ef8a6ade710'
                            'ebca4657dd879c35916ad362')