Files
plane-gptproto-integration/ai-agent/tests/test_data_projects.py
T
carlandCursor 0136c15274 Initial commit: Plane 自部署与 gptproto AI 集成
包含本地/远程部署脚本、AI Agent 服务、Dashboard 与 QA 验证。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-21 11:37:41 +08:00

63 lines
2.0 KiB
Python

import httpx
import pytest
import respx
PROJECTS_RESPONSE = [
{"id": "proj-1", "name": "后端服务", "identifier": "BE", "description": ""},
{"id": "proj-2", "name": "前端应用", "identifier": "FE", "description": ""},
]
@pytest.mark.asyncio
@respx.mock
async def test_projects_returns_list(client):
respx.get("http://api:8000/api/v1/workspaces/ws-demo/projects/").mock(
return_value=httpx.Response(200, json={"results": PROJECTS_RESPONSE})
)
resp = await client.get("/data/projects", params={"workspace_slug": "ws-demo"})
assert resp.status_code == 200
body = resp.json()
assert isinstance(body, list)
assert len(body) == 2
@pytest.mark.asyncio
@respx.mock
async def test_projects_fields(client):
respx.get("http://api:8000/api/v1/workspaces/ws-demo/projects/").mock(
return_value=httpx.Response(200, json={"results": PROJECTS_RESPONSE})
)
resp = await client.get("/data/projects", params={"workspace_slug": "ws-demo"})
proj = resp.json()[0]
assert "id" in proj
assert "name" in proj
assert "identifier" in proj
@pytest.mark.asyncio
@respx.mock
async def test_projects_sends_api_key(client):
route = respx.get("http://api:8000/api/v1/workspaces/ws-demo/projects/").mock(
return_value=httpx.Response(200, json={"results": PROJECTS_RESPONSE})
)
await client.get("/data/projects", params={"workspace_slug": "ws-demo"})
assert route.called
assert route.calls[0].request.headers.get("x-api-key") == "test-plane-token"
@pytest.mark.asyncio
@respx.mock
async def test_projects_plane_error_returns_502(client):
respx.get("http://api:8000/api/v1/workspaces/ws-demo/projects/").mock(
return_value=httpx.Response(403, json={"detail": "forbidden"})
)
resp = await client.get("/data/projects", params={"workspace_slug": "ws-demo"})
assert resp.status_code == 502
@pytest.mark.asyncio
async def test_projects_missing_slug_returns_422(client):
resp = await client.get("/data/projects")
assert resp.status_code == 422