Пример #1
0
    def test_walk_success(self):
        s_dir = api.Stat()
        s_dir.st_mode = stat.S_IFDIR
        d1 = DirEntry(Mock(), 'dirpath', 'dir1', s_dir)
        d2 = DirEntry(Mock(), 'dirpath', 'dir2', s_dir)
        s_file = api.Stat()
        s_file.st_mode = stat.S_IFREG
        d3 = DirEntry(Mock(), 'dirpath', 'file1', s_file)
        d4 = DirEntry(Mock(), 'dirpath', 'file2', s_file)
        mock_scandir = MagicMock()
        mock_scandir.return_value = [d1, d3, d2, d4]

        with patch("gluster.gfapi.Volume.scandir", mock_scandir):
            for (path, dirs, files) in self.vol.walk("dirpath"):
                self.assertEqual(dirs, ['dir1', 'dir2'])
                self.assertEqual(files, ['file1', 'file2'])
                break
Пример #2
0
    def test_rmtree_success(self):
        s_file = api.Stat()
        s_file.st_mode = stat.S_IFREG
        d = DirEntry(None, 'dirpath', 'file1', s_file)
        mock_scandir = MagicMock()
        mock_scandir.return_value = [d]

        mock_unlink = Mock()
        mock_rmdir = Mock()
        mock_islink = Mock(return_value=False)

        with nested(patch("gluster.gfapi.Volume.scandir", mock_scandir),
                    patch("gluster.gfapi.Volume.islink", mock_islink),
                    patch("gluster.gfapi.Volume.unlink", mock_unlink),
                    patch("gluster.gfapi.Volume.rmdir", mock_rmdir)):
            self.vol.rmtree("dirpath")

        mock_islink.assert_called_once_with("dirpath")
        mock_unlink.assert_called_once_with("dirpath/file1")
        mock_rmdir.assert_called_once_with("dirpath")
Пример #3
0
    def test_rmtree_ignore_unlink_rmdir_exception(self):
        s_file = api.Stat()
        s_file.st_mode = stat.S_IFREG
        d = DirEntry(None, 'dirpath', 'file1', s_file)
        mock_scandir = MagicMock()
        mock_scandir.return_value = [d]

        mock_unlink = Mock(side_effect=OSError)
        mock_rmdir = Mock(side_effect=OSError)
        mock_islink = Mock(return_value=False)

        with patch("gluster.gfapi.Volume.scandir", mock_scandir):
            with patch("gluster.gfapi.Volume.islink", mock_islink):
                with patch("gluster.gfapi.Volume.unlink", mock_unlink):
                    with patch("gluster.gfapi.Volume.rmdir", mock_rmdir):
                        self.vol.rmtree("dirpath", True)

        mock_islink.assert_called_once_with("dirpath")
        mock_unlink.assert_called_once_with("dirpath/file1")
        mock_rmdir.assert_called_once_with("dirpath")