64 lines
2.2 KiB
Python
64 lines
2.2 KiB
Python
"""人格提议列表 API 测试(api-spec §11,审批墙数据源)。"""
|
|
|
|
from collections.abc import AsyncGenerator
|
|
|
|
import pytest
|
|
from httpx import ASGITransport, AsyncClient
|
|
|
|
from app.main import app
|
|
|
|
|
|
@pytest.fixture
|
|
async def client(auth_headers: dict[str, str]) -> AsyncGenerator[AsyncClient, None]:
|
|
transport = ASGITransport(app=app)
|
|
async with AsyncClient(
|
|
transport=transport, base_url="http://test", headers=auth_headers
|
|
) as http_client:
|
|
yield http_client
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_proposals_empty(client: AsyncClient) -> None:
|
|
resp = await client.get("/api/v1/personality/proposals")
|
|
assert resp.status_code == 200
|
|
body = resp.json()
|
|
assert body["total"] == 0
|
|
assert body["items"] == []
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_proposals_filter_by_status(client: AsyncClient) -> None:
|
|
proposed = await client.post(
|
|
"/api/v1/personality/propose-update",
|
|
json={"fields": {"identity_profile": "更新的身份画像"}, "reason": "测试提议"},
|
|
)
|
|
assert proposed.status_code == 201
|
|
proposal_id = proposed.json()["proposal_id"]
|
|
|
|
listed = await client.get("/api/v1/personality/proposals")
|
|
assert listed.status_code == 200
|
|
body = listed.json()
|
|
assert body["total"] == 1
|
|
assert body["items"][0]["proposal_id"] == proposal_id
|
|
assert body["items"][0]["status"] == "pending"
|
|
|
|
pending = await client.get("/api/v1/personality/proposals?status=pending")
|
|
assert pending.json()["total"] == 1
|
|
|
|
approved = await client.get("/api/v1/personality/proposals?status=approved")
|
|
assert approved.json()["total"] == 0
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_proposals_pagination(client: AsyncClient) -> None:
|
|
for i in range(3):
|
|
await client.post(
|
|
"/api/v1/personality/propose-update",
|
|
json={"fields": {"identity_profile": f"v{i}"}, "reason": f"r{i}"},
|
|
)
|
|
page1 = await client.get("/api/v1/personality/proposals?page=1&page_size=2")
|
|
assert page1.json()["total"] == 3
|
|
assert len(page1.json()["items"]) == 2
|
|
page2 = await client.get("/api/v1/personality/proposals?page=2&page_size=2")
|
|
assert len(page2.json()["items"]) == 1
|