Пример #1
0
    def test_restore_create_needed_directories(self):
        require_empty_dir('sandbox')

        write_file('sandbox/TrashDir/files/bar')
        instance = TrashedFile('sandbox/foo/bar', 'deletion_date', 'info_file',
                               'sandbox/TrashDir/files/bar')
        self.cmd.restore(instance)
        assert os.path.exists("sandbox/foo/bar")
Пример #2
0
    def test_restore(self):
        trashed_file = TrashedFile('parent/path', None, 'info_file', 'orig')
        open('orig', 'w').close()
        open('info_file', 'w').close()

        self.cmd.restore(trashed_file)

        assert_true(os.path.exists('parent/path'))
        assert_true(not os.path.exists('info_file'))
Пример #3
0
    def test_restore(self):
        trashed_file = TrashedFile(self.temp_dir / 'parent/path', None,
                                   self.temp_dir / 'info_file',
                                   self.temp_dir / 'orig')
        make_empty_file(self.temp_dir / 'orig')
        make_empty_file(self.temp_dir / 'info_file')

        self.cmd.restore(trashed_file)

        assert os.path.exists(self.temp_dir / 'parent/path')
        assert not os.path.exists(self.temp_dir / 'info_file')
        assert not os.path.exists(self.temp_dir / 'orig')
Пример #4
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
Пример #5
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)
Пример #6
0
    def test_until_the_restore_intgration(self):
        from trashcli.fs import remove_file
        from trashcli.fs import contents_of
        self.user_reply = '0'
        open('orig_file', 'w').write('original')
        open('info_file', 'w').write('')
        remove_file('parent/path')
        remove_file('parent')

        trashed_file = TrashedFile('parent/path', None, 'info_file',
                                   'orig_file')

        self.cmd.restore_asking_the_user([trashed_file])

        assert_equals('', self.stdout.getvalue())
        assert_equals('', self.stderr.getvalue())
        assert_true(not os.path.exists('info_file'))
        assert_true(not os.path.exists('orig_file'))
        assert_true(os.path.exists('parent/path'))
        assert_equals('original', contents_of('parent/path'))
Пример #7
0
    def test_restore_over_existing_file(self):
        trashed_file = TrashedFile('path', None, None, None)
        open('path', 'w').close()

        assert_raises(IOError, lambda: self.cmd.restore(trashed_file))
Пример #8
0
    def test_restore_over_existing_file(self):
        trashed_file = TrashedFile(self.temp_dir / 'path',None,None,None)
        make_empty_file(self.temp_dir / 'path')

        self.assertRaises(IOError, lambda:self.cmd.restore(trashed_file))