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