|
| 1 | +"""Integration tests for WorkspaceResource.""" |
| 2 | + |
| 3 | +import uuid |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from deepset_mcp.api.client import AsyncDeepsetClient |
| 8 | +from deepset_mcp.api.exceptions import ResourceNotFoundError |
| 9 | +from deepset_mcp.api.workspace.models import Workspace, WorkspaceList |
| 10 | + |
| 11 | +pytestmark = pytest.mark.integration |
| 12 | + |
| 13 | + |
| 14 | +class TestWorkspaceResourceIntegration: |
| 15 | + """Integration tests for WorkspaceResource.""" |
| 16 | + |
| 17 | + @pytest.mark.asyncio |
| 18 | + async def test_list_workspaces(self) -> None: |
| 19 | + """Test listing workspaces.""" |
| 20 | + async with AsyncDeepsetClient() as client: |
| 21 | + workspaces = await client.workspaces().list() |
| 22 | + assert isinstance(workspaces, WorkspaceList) |
| 23 | + assert isinstance(workspaces.data, list) |
| 24 | + assert workspaces.total >= 0 |
| 25 | + |
| 26 | + # If we have workspaces, verify their structure |
| 27 | + if workspaces.data: |
| 28 | + workspace = workspaces.data[0] |
| 29 | + assert isinstance(workspace, Workspace) |
| 30 | + assert isinstance(workspace.name, str) |
| 31 | + assert isinstance(workspace.workspace_id, uuid.UUID) |
| 32 | + assert isinstance(workspace.languages, dict) |
| 33 | + assert isinstance(workspace.default_idle_timeout_in_seconds, int) |
| 34 | + |
| 35 | + @pytest.mark.asyncio |
| 36 | + async def test_get_workspace_not_found(self) -> None: |
| 37 | + """Test getting a non-existent workspace.""" |
| 38 | + async with AsyncDeepsetClient() as client: |
| 39 | + with pytest.raises(ResourceNotFoundError): |
| 40 | + await client.workspaces().get("definitely-does-not-exist-workspace") |
| 41 | + |
| 42 | + @pytest.mark.asyncio |
| 43 | + async def test_create_get_and_delete_workspace(self) -> None: |
| 44 | + """Tests creating, getting and deleting a workspace.""" |
| 45 | + workspace_name = f"test-workspace-{uuid.uuid4()}" |
| 46 | + async with AsyncDeepsetClient() as client: |
| 47 | + # Create a new workspace |
| 48 | + create_response = await client.workspaces().create(workspace_name) |
| 49 | + assert create_response.success is True |
| 50 | + assert create_response.message == "Workspace created successfully." |
| 51 | + |
| 52 | + # Get the workspace |
| 53 | + workspace = await client.workspaces().get(workspace_name) |
| 54 | + assert isinstance(workspace, Workspace) |
| 55 | + assert workspace.name == workspace_name |
| 56 | + |
| 57 | + # Delete the workspace |
| 58 | + delete_response = await client.workspaces().delete(workspace_name) |
| 59 | + assert delete_response.success is True |
| 60 | + assert delete_response.message == "Workspace deleted successfully." |
| 61 | + |
| 62 | + # Verify the workspace is deleted |
| 63 | + with pytest.raises(ResourceNotFoundError): |
| 64 | + await client.workspaces().get(workspace_name) |
0 commit comments