コード例 #1
0
class TestTrashedFileRestoreIntegration:
    def setUp(self):
        remove_file_if_exists('parent/path')
        remove_dir_if_exists('parent')
        self.cmd = RestoreCmd(None, None, None, None, None)

    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'))

    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))

    def tearDown(self):
        remove_file_if_exists('path')
        remove_file_if_exists('parent/path')
        remove_dir_if_exists('parent')

    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
class TestTrashedFileRestoreIntegration(unittest.TestCase):
    def setUp(self):
        self.temp_dir = MyPath.make_temp_dir()
        trash_directories = make_trash_directories()
        trashed_files = TrashedFiles(trash_directories, TrashDirectory(),
                                     contents_of)
        self.cmd = RestoreCmd(None,
                              None,
                              exit=None,
                              input=None,
                              trashed_files=trashed_files,
                              mount_points=os_mount_points,
                              fs=restore.FileSystem())

    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')

    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))

    def tearDown(self):
        self.temp_dir.clean_up()
コード例 #3
0
class TestTrashedFileRestoreIntegration(unittest.TestCase):
    def setUp(self):
        remove_file_if_exists('parent/path')
        remove_dir_if_exists('parent')
        trash_directories = make_trash_directories()
        trashed_files = TrashedFiles(trash_directories, TrashDirectory(),
                                     contents_of)
        self.cmd = RestoreCmd(None,
                              None,
                              exit=None,
                              input=None,
                              trashed_files=trashed_files,
                              mount_points=os_mount_points,
                              fs=restore.FileSystem())

    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 os.path.exists('parent/path')
        assert not os.path.exists('info_file')

    def test_restore_over_existing_file(self):
        trashed_file = TrashedFile('path',None,None,None)
        open('path','w').close()

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

    def tearDown(self):
        remove_file_if_exists('path')
        remove_file_if_exists('parent/path')
        remove_dir_if_exists('parent')

    def test_restore_create_needed_directories(self):
        require_empty_dir('sandbox')

        make_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")
コード例 #4
0
class TestTrashedFileRestore:
    def setUp(self):
        self.remove_file_if_exists('parent/path')
        self.remove_dir_if_exists('parent')
        self.cmd = RestoreCmd(None, None, None, None, None)

    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'))

    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))

    def tearDown(self):
        self.remove_file_if_exists('path')
        self.remove_file_if_exists('parent/path')
        self.remove_dir_if_exists('parent')

    def remove_file_if_exists(self, path):
        if os.path.lexists(path):
            os.unlink(path)
    def remove_dir_if_exists(self, dir):
        if os.path.exists(dir):
            os.rmdir(dir)

    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")