示例#1
0
    def test_validate_commit_path_with_more_than_one_entry(self):
        mocked_repo = MagicMock()
        mocked_commit = MagicMock()
        mocked_entry = MagicMock()
        mocked_second_entry = MagicMock()

        mocked_commit.tree = "tree"
        mocked_repo.revparse_single.return_value = mocked_commit

        mocked_second_entry.id = 1
        mocked_second_entry.name = "complex_entry"
        mocked_second_entry.filemode = GIT_FILEMODE_TREE
        mocked_entry.name = "simple_entry"
        mocked_entry.filemode = GIT_FILEMODE_TREE

        mocked_repo.__getitem__.return_value = [mocked_entry]

        view = CommitView(repo=mocked_repo,
                          commit_sha1="sha1",
                          mount_time="now",
                          uid=1,
                          gid=1)
        result = view._validate_commit_path(
            [mocked_second_entry, mocked_entry],
            ["complex_entry", "simple_entry"])
        assert result is True
        mocked_repo.__getitem__.assert_called_once_with(1)
示例#2
0
    def test_getattr_with_simple_path(self):
        mocked_repo = MagicMock()
        mocked_commit = MagicMock()
        stats = {
            'st_mode': S_IFDIR | 0o555,
            'st_nlink': 2
        }

        mocked_commit.tree = "tree"
        mocked_commit.commit_time = "now+1"
        mocked_repo.revparse_single.return_value = mocked_commit
        mocked_repo.get_git_object_default_stats.return_value = stats

        view = CommitView(repo=mocked_repo, commit_sha1="sha1",
                          mount_time="now", uid=1, gid=1)
        result = view.getattr("/", 1)
        asserted_result = {
            'st_uid': 1,
            'st_gid': 1,
            'st_mtime': "now+1",
            'st_ctime': "now+1",
            'st_mode': S_IFDIR | 0o555,
            'st_nlink': 2
        }
        assert result == asserted_result
示例#3
0
    def test_validate_commit_path_with_more_than_one_entry(self):
        mocked_repo = MagicMock()
        mocked_commit = MagicMock()
        mocked_entry = MagicMock()
        mocked_second_entry = MagicMock()

        mocked_commit.tree = "tree"
        mocked_repo.revparse_single.return_value = mocked_commit

        mocked_second_entry.id = 1
        mocked_second_entry.name = "complex_entry"
        mocked_second_entry.filemode = GIT_FILEMODE_TREE
        mocked_entry.name = "simple_entry"
        mocked_entry.filemode = GIT_FILEMODE_TREE

        mocked_repo.__getitem__.return_value = [mocked_entry]

        view = CommitView(repo=mocked_repo, commit_sha1="sha1",
                          mount_time="now", uid=1, gid=1)
        result = view._validate_commit_path([mocked_second_entry,
                                             mocked_entry],
                                            ["complex_entry",
                                             "simple_entry"])
        assert result is True
        mocked_repo.__getitem__.assert_called_once_with(1)
示例#4
0
    def test_getattr_for_a_valid_file(self):
        mocked_repo = MagicMock()
        mocked_commit = MagicMock()

        mocked_commit.tree = "tree"
        mocked_commit.commit_time = "now+1"
        mocked_repo.revparse_single.return_value = mocked_commit
        mocked_repo.get_git_object_default_stats.return_value = {
            'st_mode': S_IFREG | 0o444,
            'st_size': 10
        }

        view = CommitView(repo=mocked_repo,
                          commit_sha1="sha1",
                          mount_time="now",
                          uid=1,
                          gid=1)

        result = view.getattr("/path", 1)

        asserted_result = {
            'st_uid': 1,
            'st_gid': 1,
            'st_mtime': "now+1",
            'st_ctime': "now+1",
            'st_mode': S_IFREG | 0o444,
            'st_size': 10
        }
        assert result == asserted_result
        args = ("tree", "/path")
        mocked_repo.get_git_object_default_stats.assert_called_once_with(*args)
示例#5
0
    def test_getattr_for_a_valid_file(self):
        mocked_repo = MagicMock()
        mocked_commit = MagicMock()

        mocked_commit.tree = "tree"
        mocked_commit.commit_time = "now+1"
        mocked_repo.revparse_single.return_value = mocked_commit
        mocked_repo.get_git_object_default_stats.return_value = {
            'st_mode': S_IFREG | 0o444,
            'st_size': 10
        }

        view = CommitView(repo=mocked_repo, commit_sha1="sha1",
                          mount_time="now", uid=1, gid=1)

        result = view.getattr("/path", 1)

        asserted_result = {
            'st_uid': 1,
            'st_gid': 1,
            'st_mtime': "now+1",
            'st_ctime': "now+1",
            'st_mode': S_IFREG | 0o444,
            'st_size': 10
        }
        assert result == asserted_result
        args = ("tree", "/path")
        mocked_repo.get_git_object_default_stats.assert_called_once_with(*args)
示例#6
0
    def test_getattr_with_simple_path(self):
        mocked_repo = MagicMock()
        mocked_commit = MagicMock()
        stats = {'st_mode': S_IFDIR | 0o555, 'st_nlink': 2}

        mocked_commit.tree = "tree"
        mocked_commit.commit_time = "now+1"
        mocked_repo.revparse_single.return_value = mocked_commit
        mocked_repo.get_git_object_default_stats.return_value = stats

        view = CommitView(repo=mocked_repo,
                          commit_sha1="sha1",
                          mount_time="now",
                          uid=1,
                          gid=1)
        result = view.getattr("/", 1)
        asserted_result = {
            'st_uid': 1,
            'st_gid': 1,
            'st_mtime': "now+1",
            'st_ctime': "now+1",
            'st_mode': S_IFDIR | 0o555,
            'st_nlink': 2
        }
        assert result == asserted_result
示例#7
0
    def test_getattr_with_no_path(self):
        mocked_repo = MagicMock()
        mocked_commit = MagicMock()

        mocked_commit.tree = "tree"
        mocked_repo.revparse_single.return_value = mocked_commit

        view = CommitView(repo=mocked_repo, commit_sha1="sha1")
        assert view.getattr(False, 1) is None
示例#8
0
    def test_access_with_missing_relative_path(self):
        mocked_repo = MagicMock()
        mocked_commit = MagicMock()

        mocked_repo.revparse_single.return_value = mocked_commit

        view = CommitView(repo=mocked_repo, commit_sha1="sha1")

        assert view.access("path", "mode") == 0
示例#9
0
    def test_getattr_with_no_path(self):
        mocked_repo = MagicMock()
        mocked_commit = MagicMock()

        mocked_commit.tree = "tree"
        mocked_repo.revparse_single.return_value = mocked_commit

        view = CommitView(repo=mocked_repo, commit_sha1="sha1")
        assert view.getattr(False, 1) is None
示例#10
0
    def test_access_with_missing_relative_path(self):
        mocked_repo = MagicMock()
        mocked_commit = MagicMock()

        mocked_repo.revparse_single.return_value = mocked_commit

        view = CommitView(repo=mocked_repo, commit_sha1="sha1")

        assert view.access("path", "mode") == 0
示例#11
0
    def test_validate_commit_path_with_no_entries(self):
        mocked_repo = MagicMock()
        mocked_commit = MagicMock()

        mocked_commit.tree = "tree"
        mocked_repo.revparse_single.return_value = mocked_commit

        view = CommitView(repo=mocked_repo, commit_sha1="sha1",
                          mount_time="now", uid=1, gid=1)

        assert view._validate_commit_path([], "") is False
示例#12
0
    def test_validate_commit_path_with_no_entries(self):
        mocked_repo = MagicMock()
        mocked_commit = MagicMock()

        mocked_commit.tree = "tree"
        mocked_repo.revparse_single.return_value = mocked_commit

        view = CommitView(repo=mocked_repo, commit_sha1="sha1",
                          mount_time="now", uid=1, gid=1)

        assert view._validate_commit_path([], "") is False
示例#13
0
    def test_read(self):
        mocked_repo = MagicMock()
        mocked_commit = MagicMock()

        mocked_commit.tree = "tree"
        mocked_repo.revparse_single.return_value = mocked_commit
        mocked_repo.get_blob_data.return_value = [1, 1, 1]

        view = CommitView(repo=mocked_repo, commit_sha1="sha1",
                          mount_time="now", uid=1, gid=1)
        assert view.read("/path", 1, 1, 0) == [1]
        mocked_repo.get_blob_data.assert_called_once_with("tree", "/path")
示例#14
0
    def test_read(self):
        mocked_repo = MagicMock()
        mocked_commit = MagicMock()

        mocked_commit.tree = "tree"
        mocked_repo.revparse_single.return_value = mocked_commit
        mocked_repo.get_blob_data.return_value = [1, 1, 1]

        view = CommitView(repo=mocked_repo, commit_sha1="sha1",
                          mount_time="now", uid=1, gid=1)
        assert view.read("/path", 1, 1, 0) == [1]
        mocked_repo.get_blob_data.assert_called_once_with("tree", "/path")
示例#15
0
    def test_validate_commit_path_with_trees(self):
        mocked_repo = MagicMock()
        mocked_commit = MagicMock()
        mocked_entry = MagicMock()

        mocked_commit.tree = "tree"
        mocked_repo.revparse_single.return_value = mocked_commit
        mocked_entry.name = "simple_entry"
        mocked_entry.filemode = GIT_FILEMODE_TREE

        view = CommitView(repo=mocked_repo, commit_sha1="sha1",
                          mount_time="now", uid=1, gid=1)
        result = view._validate_commit_path([mocked_entry], ["simple_entry"])
        assert result is True
示例#16
0
    def test_validate_commit_path_with_trees(self):
        mocked_repo = MagicMock()
        mocked_commit = MagicMock()
        mocked_entry = MagicMock()

        mocked_commit.tree = "tree"
        mocked_repo.revparse_single.return_value = mocked_commit
        mocked_entry.name = "simple_entry"
        mocked_entry.filemode = GIT_FILEMODE_TREE

        view = CommitView(repo=mocked_repo, commit_sha1="sha1",
                          mount_time="now", uid=1, gid=1)
        result = view._validate_commit_path([mocked_entry], ["simple_entry"])
        assert result is True
示例#17
0
    def test_init_with_invalid_commit_sha1(self):
        mocked_repo = MagicMock()
        mocked_repo.revparse_single.side_effect = KeyError

        with pytest.raises(FuseOSError):
            CommitView(repo=mocked_repo, commit_sha1="sha1")

        mocked_repo.revparse_single.assert_called_once_with("sha1")
示例#18
0
    def test_readdir_without_tree_name(self):
        mocked_repo = MagicMock()
        mocked_commit = MagicMock()
        mocked_entry = MagicMock()

        mocked_entry.name = "entry"
        mocked_commit.tree = [mocked_entry]
        mocked_repo.revparse_single.return_value = mocked_commit

        view = CommitView(repo=mocked_repo, commit_sha1="sha1")
        with patch('gitfs.views.commit.os') as mocked_os:
            mocked_os.path.split.return_value = [None, None]

            dirs = [entry for entry in view.readdir("/path", 0)]
            assert dirs == [".", "..", "entry"]

            mocked_os.path.split.assert_called_once_with("/path")
示例#19
0
    def test_readlink(self):
        mocked_repo = MagicMock()
        mocked_commit = MagicMock()

        mocked_commit.tree = "tree"
        mocked_repo.revparse_single.return_value = mocked_commit
        mocked_repo.get_blob_data.return_value = "link value"

        with patch('gitfs.views.commit.os') as mocked_os:
            mocked_os.path.split.return_value = ["name", "another_name"]

            view = CommitView(repo=mocked_repo, commit_sha1="sha1",
                              mount_time="now", uid=1, gid=1)
            assert view.readlink("/path") == "link value"
            mocked_os.path.split.assert_called_once_with("/path")
            mocked_repo.get_blob_data.assert_called_once_with("tree",
                                                              "another_name")
示例#20
0
    def test_readlink(self):
        mocked_repo = MagicMock()
        mocked_commit = MagicMock()

        mocked_commit.tree = "tree"
        mocked_repo.revparse_single.return_value = mocked_commit
        mocked_repo.get_blob_data.return_value = "link value"

        with patch('gitfs.views.commit.os') as mocked_os:
            mocked_os.path.split.return_value = ["name", "another_name"]

            view = CommitView(repo=mocked_repo, commit_sha1="sha1",
                              mount_time="now", uid=1, gid=1)
            assert view.readlink("/path") == "link value"
            mocked_os.path.split.assert_called_once_with("/path")
            mocked_repo.get_blob_data.assert_called_once_with("tree",
                                                              "another_name")
示例#21
0
    def test_getattr_with_invalid_object_type(self):
        mocked_repo = MagicMock()
        mocked_commit = MagicMock()

        mocked_commit.tree = "tree"
        mocked_commit.commit_time = "now+1"
        mocked_repo.revparse_single.return_value = mocked_commit
        mocked_repo.get_git_object_default_stats.return_value = None

        view = CommitView(repo=mocked_repo, commit_sha1="sha1",
                          mount_time="now", uid=1, gid=1)

        with pytest.raises(FuseOSError):
            view.getattr("/path", 1)

        args = ("tree", "/path")
        mocked_repo.get_git_object_default_stats.assert_called_once_with(*args)
示例#22
0
    def test_readdir_without_tree_name(self):
        mocked_repo = MagicMock()
        mocked_commit = MagicMock()
        mocked_entry = MagicMock()

        mocked_entry.name = "entry"
        mocked_commit.tree = [mocked_entry]
        mocked_repo.revparse_single.return_value = mocked_commit

        view = CommitView(repo=mocked_repo, commit_sha1="sha1")
        with patch('gitfs.views.commit.os') as mocked_os:
            mocked_os.path.split.return_value = [None, None]

            dirs = [entry for entry in view.readdir("/path", 0)]
            assert dirs == [".", "..", "entry"]

            mocked_os.path.split.assert_called_once_with("/path")
示例#23
0
    def test_getattr_with_invalid_object_type(self):
        mocked_repo = MagicMock()
        mocked_commit = MagicMock()

        mocked_commit.tree = "tree"
        mocked_commit.commit_time = "now+1"
        mocked_repo.revparse_single.return_value = mocked_commit
        mocked_repo.get_git_object_default_stats.return_value = None

        view = CommitView(repo=mocked_repo, commit_sha1="sha1",
                          mount_time="now", uid=1, gid=1)

        with pytest.raises(FuseOSError):
            view.getattr("/path", 1)

        args = ("tree", "/path")
        mocked_repo.get_git_object_default_stats.assert_called_once_with(*args)
示例#24
0
    def test_access_with_invalid_path(self):
        mocked_repo = MagicMock()
        mocked_validation = MagicMock()
        mocked_commit = MagicMock()

        mocked_commit.tree = "tree"
        mocked_repo.revparse_single.return_value = mocked_commit
        mocked_validation.return_value = False

        with patch("gitfs.views.commit.split_path_into_components") as split:
            split.return_value = "elements"

            view = CommitView(repo=mocked_repo, commit_sha1="sha1")
            view._validate_commit_path = mocked_validation
            view.relative_path = "relative_path"

            with pytest.raises(FuseOSError):
                view.access("path", "mode")

            split.assert_called_once_with("relative_path")
            mocked_validation.assert_called_once_with("tree", "elements")
示例#25
0
    def test_access_with_invalid_path(self):
        mocked_repo = MagicMock()
        mocked_validation = MagicMock()
        mocked_commit = MagicMock()

        mocked_commit.tree = "tree"
        mocked_repo.revparse_single.return_value = mocked_commit
        mocked_validation.return_value = False

        with patch("gitfs.views.commit.split_path_into_components") as split:
            split.return_value = "elements"

            view = CommitView(repo=mocked_repo, commit_sha1="sha1")
            view._validate_commit_path = mocked_validation
            view.relative_path = "relative_path"

            with pytest.raises(FuseOSError):
                view.access("path", "mode")

            split.assert_called_once_with("relative_path")
            mocked_validation.assert_called_once_with("tree", "elements")