Exemplo n.º 1
0
class TestHowOriginalLocationIsStored:
    def test_for_absolute_paths(self):
        fs = Mock()
        self.dir = TrashDirectoryForPut('/volume/.Trash', '/volume', fs = fs)
        self.dir.store_absolute_paths()

        self.assert_path_for_trashinfo_is('/file'            , '/file')
        self.assert_path_for_trashinfo_is('/file'            , '/dir/../file')
        self.assert_path_for_trashinfo_is('/outside/file'    , '/outside/file')
        self.assert_path_for_trashinfo_is('/volume/file'     , '/volume/file')
        self.assert_path_for_trashinfo_is('/volume/dir/file' , '/volume/dir/file')

    def test_for_relative_paths(self):
        self.dir = TrashDirectoryForPut('/volume/.Trash', '/volume')
        self.dir.store_relative_paths()

        self.assert_path_for_trashinfo_is('/file'         , '/file')
        self.assert_path_for_trashinfo_is('/file'         , '/dir/../file')
        self.assert_path_for_trashinfo_is('/outside/file' , '/outside/file')
        self.assert_path_for_trashinfo_is('file'          , '/volume/file')
        self.assert_path_for_trashinfo_is('dir/file'      , '/volume/dir/file')

    def assert_path_for_trashinfo_is(self, expected_value, file_to_be_trashed):
        result = self.dir.path_for_trash_info.for_file(file_to_be_trashed)
        assert_equals(expected_value, result)
Exemplo n.º 2
0
class TestHowOriginalLocationIsStored:
    def test_for_absolute_paths(self):
        fs = Mock()
        self.dir = TrashDirectoryForPut("/volume/.Trash", "/volume", None, fs)
        self.dir.store_absolute_paths()

        self.assert_path_for_trashinfo_is("/file", "/file")
        self.assert_path_for_trashinfo_is("/file", "/dir/../file")
        self.assert_path_for_trashinfo_is("/outside/file", "/outside/file")
        self.assert_path_for_trashinfo_is("/volume/file", "/volume/file")
        self.assert_path_for_trashinfo_is("/volume/dir/file", "/volume/dir/file")

    def test_for_relative_paths(self):
        self.dir = TrashDirectoryForPut("/volume/.Trash", "/volume", None, Mock())
        self.dir.store_relative_paths()

        self.assert_path_for_trashinfo_is("/file", "/file")
        self.assert_path_for_trashinfo_is("/file", "/dir/../file")
        self.assert_path_for_trashinfo_is("/outside/file", "/outside/file")
        self.assert_path_for_trashinfo_is("file", "/volume/file")
        self.assert_path_for_trashinfo_is("dir/file", "/volume/dir/file")

    def assert_path_for_trashinfo_is(self, expected_value, file_to_be_trashed):
        result = self.dir.path_for_trash_info.for_file(file_to_be_trashed)
        assert_equals(expected_value, result)
Exemplo n.º 3
0
class TestTrashing:
    def setUp(self):
        self.now = Mock()
        self.fs = Mock()
        self.trashdir = TrashDirectoryForPut('~/.Trash', '/', self.now,
                                             self.fs)
        self.trashdir.store_relative_paths()
        path_for_trash_info = Mock()
        path_for_trash_info.for_file.return_value = 'foo'
        self.trashdir.path_for_trash_info = path_for_trash_info

    @istest
    def the_file_should_be_moved_in_trash_dir(self):

        self.trashdir.trash('foo')

        self.fs.move.assert_called_with('foo', '~/.Trash/files/foo')

    @istest
    def test_should_create_a_trashinfo(self):

        self.trashdir.trash('foo')

        self.fs.atomic_write.assert_called_with('~/.Trash/info/foo.trashinfo',
                                                ANY)

    @istest
    def trashinfo_should_contains_original_location_and_deletion_date(self):
        from datetime import datetime

        self.now.return_value = datetime(2012, 9, 25, 21, 47, 39)
        self.trashdir.trash('foo')

        self.fs.atomic_write.assert_called_with(
            ANY, b'[Trash Info]\n'
            b'Path=foo\n'
            b'DeletionDate=2012-09-25T21:47:39\n')

    @istest
    def should_rollback_trashinfo_creation_on_problems(self):
        self.fs.move.side_effect = IOError

        try:
            self.trashdir.trash('foo')
        except IOError:
            pass

        self.fs.remove_file.assert_called_with('~/.Trash/info/foo.trashinfo')
Exemplo n.º 4
0
class TestTrashing:
    def setUp(self):
        self.now = Mock()
        self.fs = Mock()
        self.trashdir = TrashDirectoryForPut("~/.Trash", "/", now=self.now, fs=self.fs)
        self.trashdir.store_relative_paths()
        path_for_trash_info = Mock()
        path_for_trash_info.for_file.return_value = "foo"
        self.trashdir.path_for_trash_info = path_for_trash_info

    @istest
    def the_file_should_be_moved_in_trash_dir(self):

        self.trashdir.trash("foo")

        self.fs.move.assert_called_with("foo", "~/.Trash/files/foo")

    @istest
    def test_should_create_a_trashinfo(self):

        self.trashdir.trash("foo")

        self.fs.atomic_write.assert_called_with("~/.Trash/info/foo.trashinfo", ANY)

    @istest
    def trashinfo_should_contains_original_location_and_deletion_date(self):
        from datetime import datetime

        self.now.return_value = datetime(2012, 9, 25, 21, 47, 39)
        self.trashdir.trash("foo")

        self.fs.atomic_write.assert_called_with(ANY, "[Trash Info]\n" "Path=foo\n" "DeletionDate=2012-09-25T21:47:39\n")

    @istest
    def should_rollback_trashinfo_creation_on_problems(self):
        self.fs.move.side_effect = IOError

        try:
            self.trashdir.trash("foo")
        except IOError:
            pass

        self.fs.remove_file.assert_called_with("~/.Trash/info/foo.trashinfo")