class Describe_AvailableTrashDirs_when_parent_is_unsticky:
    def setUp(self):
        self.error_log = MagicMock()
        self.fs = MagicMock()
        self.dirs = AvailableTrashDirs(environ =  {}, getuid = lambda:123,
                                       fs = self.fs)
        self.fs.list_volumes.return_value = ['/topdir']
        self.fs.is_sticky_dir.side_effect = (
                lambda path: {'/topdir/.Trash':False}[path])

    def test_it_should_report_skipped_dir_non_sticky(self):
        self.fs.exists.side_effect = (
                lambda path: {'/topdir/.Trash/123':True}[path])

        self.dirs.list_trashdirs(error_log = self.error_log)

        (self.error_log.top_trashdir_skipped_because_parent_not_sticky.
                assert_called_with('/topdir/.Trash/123'))

    def test_it_shouldnot_care_about_non_existent(self):
        self.fs.exists.side_effect = (
                lambda path: {'/topdir/.Trash/123':False}[path])

        self.dirs.list_trashdirs(error_log = self.error_log)

        assert_equals([], self.error_log.
                top_trashdir_skipped_because_parent_not_sticky.mock_calls)
 def setUp(self):
     self.error_log = MagicMock()
     self.fs = MagicMock()
     self.dirs = AvailableTrashDirs(environ =  {}, getuid = lambda:123,
                                    fs = self.fs)
     self.fs.list_volumes.return_value = ['/topdir']
     self.fs.exists.side_effect = (lambda path: {'/topdir/.Trash/123':True}[path])
class Describe_AvailableTrashDirs_when_parent_is_symlink:
    def setUp(self):
        self.error_log = MagicMock()
        self.fs = MagicMock()
        self.dirs = AvailableTrashDirs(environ =  {}, getuid = lambda:123,
                                       fs = self.fs)
        self.fs.list_volumes.return_value = ['/topdir']
        self.fs.exists.side_effect = (lambda path: {'/topdir/.Trash/123':True}[path])


    def test_it_should_skip_symlink(self):
        self.fs.is_sticky_dir.return_value = True
        self.fs.is_symlink.return_value    = True

        self.dirs.list_trashdirs(error_log = self.error_log)

        (self.error_log.top_trashdir_skipped_because_parent_is_symlink.
                assert_called_with('/topdir/.Trash/123'))