def test_archive_corruption_case_actual(self, vault_mock): vault_file_one = self.vault.add(Branch.Staged, self.file_one) vault_file_two = self.vault.add(Branch.Limbo, self.file_two) walk = [(self.vault, File.FromFS(vault_file_one.path), VaultExc.PhysicalVaultFile("File is in Staged and can have to hardlinks if the file was archived with the stash option")), (self.vault, File.FromFS(vault_file_two.path), VaultExc.PhysicalVaultFile("File is in Limbo and has two hardlinks"))] dummy_walker = _DummyWalker(walk) dummy_persistence = MagicMock() Sweeper(dummy_walker, dummy_persistence, True) self.assertTrue(os.path.isfile(self.file_one)) self.assertTrue(os.path.isfile(vault_file_one.path)) self.assertTrue(os.path.isfile(self.file_two)) self.assertTrue(os.path.isfile(vault_file_two.path))
def FromFS(cls, path: T.Path, idm: IdM.base.IdentityManager, ctime: datetime, atime: datetime, mtime: datetime) -> File: file = models.File.FromFS(path, idm) file.ctime = ctime file.atime = atime file.mtime = mtime return File(file)
def test_tracked_file_non_archive(self, vault_mock): vault_file_one = self.vault.add(Branch.Keep, self.file_one) vault_file_two = self.vault.add(Branch.Staged, self.file_two) vault_file_three = self.vault.add(Branch.Limbo, self.file_three) walk = [(self.vault, File.FromFS(self.file_one), Branch.Keep), (self.vault, File.FromFS(self.file_two), Branch.Stash), (self.vault, File.FromFS( self.file_three), VaultExc.VaultCorruption(f"{self.file_three} is limboed in the vault in {self.vault.root}, but also exists outside the vault"))] dummy_walker = _DummyWalker(walk) dummy_persistence = MagicMock() Sweeper(dummy_walker, dummy_persistence, True) self.assertTrue(os.path.isfile(self.file_one)) self.assertTrue(os.path.isfile(vault_file_one.path)) self.assertTrue(os.path.isfile(self.file_two)) self.assertTrue(os.path.isfile(vault_file_two.path)) self.assertTrue(os.path.isfile(self.file_three)) self.assertTrue(os.path.isfile(vault_file_three.path))
def test_keep_corruption_case_actual(self, vault_mock): vault_file_one = self.vault.add(Branch.Keep, self.file_one) vault_file_two = self.vault.add(Branch.Archive, self.file_two) vault_file_three = self.vault.add(Branch.Limbo, self.file_three) self.file_one.unlink() walk = [(self.vault, File.FromFS(vault_file_one.path), VaultExc.PhysicalVaultFile()), (self.vault, File.FromFS(vault_file_two.path), VaultExc.PhysicalVaultFile()), (self.vault, File.FromFS(vault_file_three.path), VaultExc.PhysicalVaultFile())] dummy_walker = _DummyWalker(walk) dummy_persistence = MagicMock() Sweeper(dummy_walker, dummy_persistence, True) self.assertFalse(os.path.isfile(self.file_one)) self.assertFalse(os.path.isfile(vault_file_one.path)) self.assertTrue(os.path.isfile(self.file_two)) self.assertTrue(os.path.isfile(vault_file_two.path)) self.assertTrue(os.path.isfile(self.file_three)) self.assertTrue(os.path.isfile(vault_file_three.path))
def test_unactionable_file_wont_be_actioned(self): """Gets the Sweeper to try and action a file with the wrong permissions. The file won't be actionable, and it should throw the exception. Anything in the file `can_add` criteria will throw this exception. """ dummy_walker = _DummyWalker( [(self.vault, File.FromFS(self.wrong_perms), None)]) dummy_persistence = MagicMock() self.assertRaises(core.file.exception.UnactionableFile, lambda: Sweeper(dummy_walker, dummy_persistence, True))
def test_tracked_file_stashed(self, vault_mock): vault_file_one_stash = self.vault.add(Branch.Stash, self.file_one) walk = [(self.vault, File.FromFS(self.file_one), Branch.Stash)] vault_file_one_staged = self.determine_vault_path( self.file_one, Branch.Staged) dummy_walker = _DummyWalker(walk) dummy_persistence = MagicMock() Sweeper(dummy_walker, dummy_persistence, True) self.assertTrue(os.path.isfile(self.file_one)) self.assertFalse(os.path.isfile(vault_file_one_stash.path)) self.assertTrue(os.path.isfile(vault_file_one_staged))