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.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')]
Exemplo n.º 2
0
    def test_until_the_restore_unit(self):
        self.fs.path_exists.return_value = False
        trashed_file = TrashedFile('parent/path', None, 'info_file',
                                   'orig_file')

        self.user_reply = '0'
        self.cmd.restore_asking_the_user([trashed_file])

        assert '' == self.stdout.getvalue()
        assert '' == self.stderr.getvalue()
        assert [
            call.path_exists('parent/path'),
            call.mkdirs('parent'),
            call.move('orig_file', 'parent/path'),
            call.remove_file('info_file')
        ] == self.fs.mock_calls
Exemplo n.º 3
0
    def test_until_the_restore_unit(self):
        trashed_file = TrashedFile('parent/path', None, 'info_file',
                                   'orig_file')
        fs = Mock()
        self.cmd.fs = fs
        self.cmd.path_exists = lambda _: False

        self.user_reply = '0'
        self.cmd.restore_asking_the_user([trashed_file])

        assert_equals('', self.stdout.getvalue())
        assert_equals('', self.stderr.getvalue())
        assert_equals([
            call.mkdirs('parent'),
            call.move('orig_file', 'parent/path'),
            call.remove_file('info_file')
        ], fs.mock_calls)
Exemplo n.º 4
0
    def test_until_the_restore_unit(self):
        from mock import Mock, call
        trashed_file = TrashedFile(
                'parent/path',
                None,
                'info_file',
                'orig_file')
        fs = Mock()
        self.cmd.fs = fs
        self.cmd.path_exists = lambda _: False

        self.user_reply = '0'
        self.cmd.restore_asking_the_user([trashed_file])

        assert_equals('', self.stdout.getvalue())
        assert_equals('', self.stderr.getvalue())
        assert_equals([
            call.mkdirs('parent')
            , call.move('orig_file', 'parent/path')
            , call.remove_file('info_file')
            ], fs.mock_calls)