Пример #1
0
    def test_bug_will_use_top_trashdir_even_with_not_sticky(self):
        self.fs.mock_add_spec(['isdir', 'islink', 'has_sticky_bit',
                               'move', 'atomic_write',
                               'remove_file', 'ensure_dir'])
        self.fs.isdir.return_value = True
        self.fs.islink.return_value = False
        self.fs.has_sticky_bit.return_value = False

        result = TrashResult(False)
        self.file_trasher.trash_file('sandbox/foo',
                                     None,
                                     None,
                                     result,
                                     self.logger,
                                     self.reporter)

        assert self.fs.mock_calls == [
            call.isdir('.Trash'),
            call.islink('.Trash'),
            call.has_sticky_bit('.Trash'),
            call.ensure_dir('.Trash-123/files', 448),
            call.ensure_dir('.Trash-123/info', 448),
            call.atomic_write('.Trash-123/info/foo.trashinfo', ANY),
            call.move('sandbox/foo', '.Trash-123/files/foo')
        ]
Пример #2
0
    def test_should_skip_top_trash_if_does_not_exists(self):
        self.fs.mock_add_spec(['isdir', 'islink', 'move', 'atomic_write',
            'remove_file', 'ensure_dir'])
        self.fs.isdir.side_effect = lambda x:['.Trash'][False]
        self.fs.islink.side_effect = lambda x:['.Trash'][False]

        self.trashcan.trash('sandbox/foo')

        assert_equals([
            call.isdir('.Trash'),
            call.islink('.Trash'),
            call.ensure_dir('.Trash/123/info', 448),
            call.atomic_write('.Trash/123/info/foo.trashinfo', ANY),
            call.ensure_dir('.Trash/123/files', 448),
            call.move('sandbox/foo', '.Trash/123/files/foo')
        ], self.fs.mock_calls)
Пример #3
0
    def test_should_skip_top_trash_if_does_not_exists(self):
        self.fs.mock_add_spec([
            'isdir', 'islink', 'move', 'atomic_write', 'remove_file',
            'ensure_dir'
        ])
        self.fs.isdir.side_effect = lambda x: ['.Trash'][False]
        self.fs.islink.side_effect = lambda x: ['.Trash'][False]

        self.trashcan.trash('sandbox/foo')

        assert_equals([
            call.isdir('.Trash'),
            call.islink('.Trash'),
            call.ensure_dir('.Trash/123/info', 448),
            call.atomic_write('.Trash/123/info/foo.trashinfo', ANY),
            call.ensure_dir('.Trash/123/files', 448),
            call.move('sandbox/foo', '.Trash/123/files/foo')
        ], self.fs.mock_calls)
Пример #4
0
    def test_bug_will_use_top_trashdir_even_with_not_sticky(self):
        self.fs.mock_add_spec(['isdir', 'islink', 'has_sticky_bit',
                               'move', 'atomic_write',
                               'remove_file', 'ensure_dir'])
        self.fs.isdir.return_value = True
        self.fs.islink.return_value = False
        self.fs.has_sticky_bit.return_value = False

        self.trashcan.trash('sandbox/foo')

        assert_equal([
            call.isdir('.Trash'),
            call.islink('.Trash'),
            call.has_sticky_bit('.Trash'),
            call.ensure_dir('.Trash-123/info', 448),
            call.atomic_write('.Trash-123/info/foo.trashinfo', ANY),
            call.ensure_dir('.Trash-123/files', 448),
            call.move('sandbox/foo', '.Trash-123/files/foo')
        ], self.fs.mock_calls, self.fs.mock_calls)
Пример #5
0
    def test_bug_will_use_top_trashdir_even_with_not_sticky(self):
        self.fs.mock_add_spec(['isdir', 'islink', 'has_sticky_bit',
                               'move', 'atomic_write',
                               'remove_file', 'ensure_dir'])
        self.fs.isdir.return_value = True
        self.fs.islink.return_value = False
        self.fs.has_sticky_bit.return_value = False

        self.trashcan.trash('sandbox/foo')

        assert_equals([
            call.isdir('.Trash'),
            call.islink('.Trash'),
            call.has_sticky_bit('.Trash'),
            call.ensure_dir('.Trash-123/info', 448),
            call.atomic_write('.Trash-123/info/foo.trashinfo', ANY),
            call.ensure_dir('.Trash-123/files', 448),
            call.move('sandbox/foo', '.Trash-123/files/foo')
        ], self.fs.mock_calls, self.fs.mock_calls)
Пример #6
0
    def test_use_of_top_trash_dir_when_sticky(self):
        self.fs.mock_add_spec([
            'isdir', 'islink', 'has_sticky_bit', 'move', 'atomic_write',
            'remove_file', 'ensure_dir'
        ])
        self.fs.isdir.return_value = True
        self.fs.islink.return_value = False
        self.fs.has_sticky_bit.return_value = True

        self.trashcan.trash('sandbox/foo')

        assert [
            call.isdir('.Trash'),
            call.islink('.Trash'),
            call.has_sticky_bit('.Trash'),
            call.ensure_dir('.Trash/123/info', 448),
            call.atomic_write('.Trash/123/info/foo.trashinfo', ANY),
            call.ensure_dir('.Trash/123/files', 448),
            call.move('sandbox/foo', '.Trash/123/files/foo')
        ] == self.fs.mock_calls
Пример #7
0
    def test_the_file_should_be_moved_in_trash_dir(self):

        self.trashdir.trash2('foo', self.now)

        assert self.fs.mock_calls == [
            call.ensure_dir('~/.Trash/files', 0o700),
            call.move('foo', 'files/')
        ]
        assert self.info_dir.mock_calls == [
            call.persist_trash_info(
                'foo',
                b'[Trash Info]\nPath=foo\nDeletionDate=1970-01-01T00:00:00\n')
        ]
Пример #8
0
    def test_should_rollback_trashinfo_creation_on_problems(self):
        self.fs.move.side_effect = IOError

        try:
            self.trashdir.trash2('foo', self.now)
        except IOError:
            pass

        assert self.fs.mock_calls == [
            call.ensure_dir('~/.Trash/files', 448),
            call.move('foo', 'files/'),
            call.remove_file('info_file')
        ]
        assert self.info_dir.mock_calls == [
            call.persist_trash_info(
                'foo',
                b'[Trash Info]\nPath=foo\nDeletionDate=1970-01-01T00:00:00\n')
        ]