class TestTopTrashDirRules(unittest.TestCase): def setUp(self): self.fs = Mock(spec=['exists', 'is_sticky_dir', 'is_symlink']) self.rules = TopTrashDirRules(self.fs) def test_path_not_exists(self): self.fs.exists.return_value = False result = self.rules.valid_to_be_read("/path") assert (result, self.fs.mock_calls) == \ (top_trash_dir_does_not_exist, [call.exists('/path')]) def test_parent_not_sticky(self): self.fs.exists.return_value = True self.fs.is_sticky_dir.return_value = False result = self.rules.valid_to_be_read("/path") assert (result, self.fs.mock_calls) == \ (top_trash_dir_invalid_because_not_sticky, [call.exists('/path'), call.is_sticky_dir('/')]) def test_parent_is_symlink(self): self.fs.exists.return_value = True self.fs.is_sticky_dir.return_value = True self.fs.is_symlink.return_value = True result = self.rules.valid_to_be_read("/path") assert (result, self.fs.mock_calls) == \ (top_trash_dir_invalid_because_parent_is_symlink, [call.exists('/path'), call.is_sticky_dir('/'), call.is_symlink('/')]) def test_parent_is_sym(self): self.fs.exists.return_value = True self.fs.is_sticky_dir.return_value = True self.fs.is_symlink.return_value = False result = self.rules.valid_to_be_read("/path") assert (result, self.fs.mock_calls) == \ (top_trash_dir_valid, [call.exists('/path'), call.is_sticky_dir('/'), call.is_symlink('/')])
def run(self, argv): args = argv[1:] self.exit_code = 0 if not args: self.print_err('Usage:\n' ' trash-rm PATTERN\n' '\n' 'Please specify PATTERN') self.exit_code = 8 return trashcan = CleanableTrashcan(FileRemover()) cmd = Filter(trashcan.delete_trashinfo_and_backup_copy) cmd.use_pattern(args[0]) listing = ListTrashinfos(cmd.delete_if_matches, self.file_reader, self.unable_to_parse_path) trashdirs = TrashDirs(self.environ, self.getuid, self.list_volumes, TopTrashDirRules(self.file_reader)) trashdirs.on_trash_dir_found = listing.list_from_volume_trashdir trashdirs.list_trashdirs()
def run(self, argv): args = argv[1:] self.exit_code = 0 if not args: self.stderr.write('Usage:\n' ' trash-rm PATTERN\n' '\n' 'Please specify PATTERN\n') self.exit_code = 8 return trashcan = CleanableTrashcan(FileRemover()) cmd = Filter(trashcan.delete_trashinfo_and_backup_copy) cmd.use_pattern(args[0]) file_reader = FileSystemReader() listing = ListTrashinfos(cmd.delete_if_matches) top_trashdir_rules = TopTrashDirRules(file_reader) trashdirs = TrashDirs(self.environ, self.getuid, list_volumes=self.list_volumes, top_trashdir_rules=top_trashdir_rules) trashdirs.on_trash_dir_found = listing.list_from_volume_trashdir trashdirs.list_trashdirs()
def run(self, argv): args = argv[1:] self.exit_code = 0 if not args: self.print_err('Usage:\n' ' trash-rm PATTERN\n' '\n' 'Please specify PATTERN') self.exit_code = 8 return trashcan = CleanableTrashcan(FileRemover()) cmd = Filter(args[0]) listing = ListTrashinfos(self.file_reader) user_info_provider = UserInfoProvider(self.environ, self.getuid) scanner = TrashDirsScanner(user_info_provider, self.volumes_listing, TopTrashDirRules(self.file_reader)) for event, args in scanner.scan_trash_dirs(self.environ): if event == trash_dir_found: path, volume = args for type, arg in listing.list_from_volume_trashdir( path, volume): if type == 'unable_to_parse_path': self.unable_to_parse_path(arg) elif type == 'trashed_file': original_location, info_file = arg if cmd.matches(original_location): trashcan.delete_trashinfo_and_backup_copy( info_file)
def setUp(self): self.fs = Mock() self.scanner = TrashDirsScanner( environ={}, getuid=lambda: 123, top_trash_dir_rules=TopTrashDirRules(self.fs), list_volumes=lambda: ['/topdir']) self.fs.exists.side_effect = (lambda path: {'/topdir/.Trash/123':True}[path])
def setUp(self): self.fs = MagicMock() self.dirs = TrashDirs(environ = {}, getuid = lambda:123, top_trashdir_rules = TopTrashDirRules(self.fs), list_volumes = lambda: ['/topdir']) self.fs.exists.side_effect = (lambda path: {'/topdir/.Trash/123':True}[path]) self.symlink_error = Mock() self.dirs.on_trashdir_skipped_because_parent_is_symlink = self.symlink_error
def setUp(self): self.fs = Mock() self.scanner = TrashDirsScanner( environ={}, getuid=lambda: 123, top_trash_dir_rules=TopTrashDirRules(self.fs), list_volumes=lambda: ['/topdir'], ) self.fs.is_sticky_dir.side_effect = ( lambda path: {'/topdir/.Trash':False}[path])
def setUp(self): self.fs = MagicMock() self.dirs = TrashDirs(environ = {}, getuid = lambda:123, top_trashdir_rules = TopTrashDirRules(self.fs), list_volumes = lambda: ['/topdir'], ) self.dirs.on_trashdir_skipped_because_parent_not_sticky = Mock() self.dirs.on_trashdir_skipped_because_parent_is_symlink = Mock() self.fs.is_sticky_dir.side_effect = ( lambda path: {'/topdir/.Trash':False}[path])
def setUp(self): self.fs = Mock(spec=['exists', 'is_sticky_dir', 'is_symlink']) self.rules = TopTrashDirRules(self.fs)