Ejemplo n.º 1
0
def test_archivate_dirs(mocker, directories, links, files):
    test_archive = mocker.Mock()
    path = "/path"
    tag = "tag"
    mocker.patch("os.path.exists", return_value=True)

    def contains(lst):
        def foo(x):
            return x in [os.path.join(path, d) for d in lst]
        return foo

    mocker.patch("os.path.isdir", side_effect=contains(directories))
    mocker.patch("os.path.islink", side_effect=contains(links))
    in_path = directories + links + files
    random.shuffle(in_path)
    mocker.patch("os.listdir", return_value=in_path)
    archivate.archive_dirs(test_archive, path, tag)
    assert len(test_archive.add.call_args_list) == len(directories)
    for directory in directories:
        test_archive.add.assert_has_calls([
            mock.call(
                os.path.join(path, directory),
                "{0}/{1}".format(tag, directory))
        ])
Ejemplo n.º 2
0
 def backup(self):
     assert self.path
     assert self.tag
     archivate.archive_dirs(self.archive, self.path, self.tag)
Ejemplo n.º 3
0
 def backup(self):
     assert self.path
     assert self.tag
     archivate.archive_dirs(self.archive, self.path, self.tag)
Ejemplo n.º 4
0
def test_archivate_dirs_no_paths(mocker):
    test_archive = mocker.Mock()
    mocker.patch("os.path.exists", return_value=False)
    archivate.archive_dirs(test_archive, "/path", "tag")
    assert not test_archive.add.called