Skip to content

Commit f5c93c8

Browse files
committed
feat: Add Project collaborator tests
1 parent 32788c0 commit f5c93c8

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

tests/future/conftest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from httpx import Request, Response
2323

2424
from galileo.__future__ import Configuration
25+
from galileo.__future__.collaborator import CollaboratorRole
2526
from galileo.__future__.configuration import _CONFIGURATION_KEYS
2627
from galileo.config import GalileoPythonConfig
2728
from galileo.resources.models.messages_list_item import MessagesListItem
@@ -223,3 +224,18 @@ def mock_integration() -> MagicMock:
223224
mock_int.is_selected = True
224225
mock_int.permissions = ["read", "update"]
225226
return mock_int
227+
228+
229+
@pytest.fixture
230+
def mock_collaborator() -> MagicMock:
231+
"""Create a mock collaborator object for testing."""
232+
mock_collab = MagicMock()
233+
mock_collab.id = str(uuid4())
234+
mock_collab.user_id = str(uuid4())
235+
mock_collab.role = CollaboratorRole.VIEWER
236+
mock_collab.created_at = None
237+
mock_collab.email = "collaborator@test.com"
238+
mock_collab.first_name = "Test"
239+
mock_collab.last_name = "Collaborator"
240+
mock_collab.permissions = []
241+
return mock_collab

tests/future/test_project.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytest
55

66
from galileo.__future__ import Project
7+
from galileo.__future__.collaborator import Collaborator, CollaboratorRole
78
from galileo.__future__.shared.base import SyncState
89
from galileo.__future__.shared.exceptions import APIError, ValidationError
910

@@ -302,3 +303,61 @@ def test_repr_representation(self, reset_configuration: None) -> None:
302303

303304
assert "Test Project" in repr(project)
304305
assert "test-id-123" in repr(project)
306+
307+
308+
class TestProjectCollaborators:
309+
"""Test suite for Project collaborator management methods."""
310+
311+
@patch("galileo.__future__.project.Projects")
312+
def test_add_update_remove_collaborator(
313+
self,
314+
mock_projects_class: MagicMock,
315+
reset_configuration: None,
316+
mock_project: MagicMock,
317+
mock_collaborator: MagicMock,
318+
) -> None:
319+
"""Test add, update, and remove collaborator return Collaborator instances."""
320+
mock_service = MagicMock()
321+
mock_projects_class.return_value = mock_service
322+
mock_service.get.return_value = mock_project
323+
mock_service.share_project_with_user.return_value = mock_collaborator
324+
mock_service.update_user_project_collaborator.return_value = mock_collaborator
325+
326+
project = Project.get(id=mock_project.id)
327+
328+
added = project.add_collaborator(user_id=mock_collaborator.user_id)
329+
assert isinstance(added, Collaborator)
330+
331+
updated = project.update_collaborator(user_id=mock_collaborator.user_id, role=CollaboratorRole.EDITOR)
332+
assert isinstance(updated, Collaborator)
333+
334+
project.remove_collaborator(user_id=mock_collaborator.user_id)
335+
mock_service.unshare_project_with_user.assert_called_once()
336+
337+
@patch("galileo.__future__.project.Projects")
338+
def test_collaborators_property_returns_same_as_list_method(
339+
self,
340+
mock_projects_class: MagicMock,
341+
reset_configuration: None,
342+
mock_project: MagicMock,
343+
mock_collaborator: MagicMock,
344+
) -> None:
345+
"""Test collaborators property returns equivalent results to list_collaborators()."""
346+
mock_service = MagicMock()
347+
mock_projects_class.return_value = mock_service
348+
mock_service.get.return_value = mock_project
349+
mock_service.list_user_project_collaborators.return_value = [mock_collaborator]
350+
351+
project = Project.get(id=mock_project.id)
352+
353+
assert project.collaborators[0] == project.list_collaborators()[0]
354+
355+
def test_collaborator_methods_require_synced_project(self, reset_configuration: None) -> None:
356+
"""Test collaborator methods raise ValueError for local-only projects."""
357+
project = Project(name="Test Project")
358+
359+
with pytest.raises(ValueError, match="Project ID is not set"):
360+
project.list_collaborators()
361+
362+
with pytest.raises(ValueError, match="Project ID is not set"):
363+
project.add_collaborator(user_id="user-123")

0 commit comments

Comments
 (0)