Platform Client SDK Testing

Integration tests for the PlatformClient SDK covering authentication, workspaces, and RBAC

python
from praisonaiagents import Agent

agent = Agent(name="test-agent", instructions="Run platform client SDK tests.")
agent.start("Run the full SDK test suite and report results.")

Run integration tests against the real FastAPI app to verify every PlatformClient endpoint and RBAC rule.

bash
pip install praisonai-platform pytest pytest-asyncio httpx
pytest praisonai_platform/tests/ -v
python
import pytest
from praisonai_platform.client import PlatformClient

@pytest.mark.asyncio
async def test_register_and_workspace():
    client = PlatformClient("http://localhost:8000")
    await client.register("test@example.com", "password")
    workspace = await client.create_workspace("Test Workspace")
    assert workspace["name"] == "Test Workspace"

The user asks the agent to run SDK tests; pytest exercises every PlatformClient endpoint.

Diagram

๐Ÿงช Test Suite

๐Ÿ“ฆ PlatformClient

๐Ÿ”Œ FastAPI App

SQLite Memory

Quick Start

  1. Simple Usage

    Start the platform server, then run client tests:

    bash
    python -m praisonai_platform --port 8000 &
    pytest praisonai_platform/tests/test_client.py -v
  2. With Configuration

    Test against the in-process FastAPI app with ASGITransport โ€” no server required:

    python
    import pytest
    import httpx
    from httpx import ASGITransport
    from praisonai_platform.api.app import create_app
    from praisonai_platform.client import PlatformClient
    
    @pytest.mark.asyncio
    async def test_full_lifecycle():
        app = create_app()
        transport = ASGITransport(app=app)
    
        async with httpx.AsyncClient(transport=transport, base_url="http://test") as http:
            client = PlatformClient("http://test")
            await client.register("user@test.com", "password")
            workspace = await client.create_workspace("My Workspace")
            assert workspace["name"] == "My Workspace"

How It Works

Diagram
In-Memory DBFastAPIPlatformClientTestIn-Memory DBFastAPIPlatformClientTestregister()POST /auth/registercreate userJWT tokencreate_workspace()POST /workspaces/workspace object
LayerPurpose
pytest-asyncioAsync test runner
ASGITransportIn-memory requests against the real app
PlatformClientHTTP wrapper with auto-authentication
SQLite memoryIsolated database per test run

Test Coverage

AreaEndpointsVerification
Authentication/auth/register, /auth/login, /auth/meJWT returned, user retrieved
WorkspacesCRUD on /workspaces/Owner membership enforced
ProjectsCRUD on /workspaces/{id}/projects/Scoped to workspace
IssuesCRUD on /workspaces/{id}/issues/Issue numbers assigned
RBACAll workspace-scoped routesNon-members receive 403

RBAC enforcement test

python
import pytest
import httpx
from praisonai_platform.client import PlatformClient

@pytest.mark.asyncio
async def test_nonmember_blocked():
    member = PlatformClient("http://localhost:8000")
    await member.register("member@test.com", "password")
    workspace = await member.create_workspace("RBAC Test")

    outsider = PlatformClient("http://localhost:8000")
    await outsider.register("outsider@test.com", "password")

    with pytest.raises(httpx.HTTPStatusError) as exc:
        await outsider.get_workspace(workspace["id"])
    assert exc.value.response.status_code == 403

Best Practices

Use in-memory database for speed

Configure SQLite with :memory: in test fixtures for fast, isolated runs.

Test against the real FastAPI app

Use ASGITransport(app=create_app()) so tests exercise actual route logic and dependencies.

Verify RBAC on every workspace route

Assert 403 for non-members on projects, issues, agents, labels, and dependencies.

Isolate test data with unique emails

Use f"test-{uuid.uuid4()}@example.com" per test to avoid collisions.


Related