def test_run_restore_file_from_basket(self): with open(self.file_path, 'rb') as afile: buf = afile.read() self.hasher.update(buf) handler_file = RemoveHandler( logger=self.logger, is_basket=True, basket_path=self.basket, ) handler_file.remove(self.file_path) self.assertEqual(exists(self.file_path), False) self.assertTrue(exists(join(self.basket, basename(self.file_path)))) restorehandler.restore(basename(self.file_path), basket_path=self.basket, logger=self.logger, is_replace=True) self.assertFalse(exists(join(self.basket, basename(self.file_path)))) self.assertEqual(exists(self.file_path), True) hasher2 = hashlib.md5() with open(self.file_path, 'rb') as afile: buf = afile.read() hasher2.update(buf) self.assertEqual(hasher2.hexdigest(), self.hasher.hexdigest())
def test_run_remove_dir_to_basket(self): handler_dir = RemoveHandler(is_recursive=True, is_basket=True, basket_path=self.basket, logger=self.logger) handler_dir.remove(self.dir_path) self.assertEqual(exists(self.dir_path), False) self.assertTrue(exists(join(self.basket, basename(self.dir_path))))
def test_run_remove_file(self): handler_file = RemoveHandler(logger=self.logger, basket_path=self.basket, is_basket=True) handler_file.remove(self.file_path) self.assertEqual(exists(self.file_path), False) self.assertEqual( exists(join(self.basket, basename(self.file_path) + "(1)")), True)
def test_run_remove_empty_dir_to_basket(self): handler_empty_dir = RemoveHandler(is_dir=True, is_basket=True, basket_path=self.basket, logger=self.logger) handler_empty_dir.remove(self.empty_dir_path) self.assertEqual(exists(self.empty_dir_path), False) self.assertEqual( exists(join(self.basket, basename(self.empty_dir_path) + "(1)")), True)
def test_run_restore_dir_from_basket(self): handler_dir = RemoveHandler(is_recursive=True, is_basket=True, basket_path=self.basket, logger=self.logger) handler_dir.remove(self.dir_path) self.assertEqual(exists(self.dir_path), False) self.assertTrue(exists(join(self.basket, basename(self.dir_path)))) restorehandler.restore(basename(self.dir_path), basket_path=self.basket, logger=self.logger, is_replace=True) self.assertFalse(exists(join(self.basket, basename(self.dir_path)))) self.assertEqual(exists(self.dir_path), True)
def test_run_remove_file_to_basket(self): handler_file = RemoveHandler(logger=self.logger, is_basket=True, symlinks=False, basket_path=self.basket,) handler_file.remove(self.link_to_file) self.assertEqual(exists(self.file_path), True) self.assertEqual(exists(self.link_to_file), False)
def test_run_remove_dir_to_basket(self): handler_dir = RemoveHandler(is_recursive=True, symlinks=False, is_basket=True, basket_path=self.basket, logger=self.logger) handler_dir.remove(self.link_to_dir) self.assertEqual(exists(self.link_to_dir), False) self.assertEqual(exists(self.dir_path), True)
def test_run_remove_link_empty_dir(self): handler_empty_dir = RemoveHandler(symlinks=False, is_dir=True, is_basket=True, basket_path=self.basket, logger=self.logger) handler_empty_dir.remove(self.link_to_emptydir) self.assertEqual(exists(self.link_to_emptydir), False) self.assertEqual(exists(self.empty_dir_path), True)
def test_run_remove_file(self): handler_file = RemoveHandler(logger=self.logger) handler_file.remove(self.file_path) self.assertEqual(exists(self.file_path), False)
def test_run_remove_dir(self): handler_dir = RemoveHandler(is_recursive=True, logger=self.logger) handler_dir.remove(self.dir_path) self.assertEqual(exists(self.dir_path), False)