75 lines
2.4 KiB
Python
75 lines
2.4 KiB
Python
|
|
"""回放 / 评审路由参数校验(最小 HTTP)。"""
|
|||
|
|
|
|||
|
|
import pytest
|
|||
|
|
from httpx import ASGITransport, AsyncClient
|
|||
|
|
|
|||
|
|
from app.features.evaluation.internal_auth import get_internal_eval_principal
|
|||
|
|
|
|||
|
|
|
|||
|
|
@pytest.mark.asyncio
|
|||
|
|
async def test_replay_conversation_requires_fixture_or_utterances(
|
|||
|
|
monkeypatch: pytest.MonkeyPatch,
|
|||
|
|
) -> None:
|
|||
|
|
from fastapi import FastAPI
|
|||
|
|
|
|||
|
|
monkeypatch.setattr(
|
|||
|
|
"app.core.config.settings.internal_eval_api_key",
|
|||
|
|
"secret",
|
|||
|
|
raising=False,
|
|||
|
|
)
|
|||
|
|
from app.features.evaluation.router import router
|
|||
|
|
|
|||
|
|
app = FastAPI()
|
|||
|
|
app.include_router(router, prefix="/internal/api/evaluation")
|
|||
|
|
|
|||
|
|
async def _override_auth():
|
|||
|
|
from app.features.evaluation.internal_auth import InternalEvalPrincipal
|
|||
|
|
|
|||
|
|
return InternalEvalPrincipal()
|
|||
|
|
|
|||
|
|
app.dependency_overrides[get_internal_eval_principal] = _override_auth
|
|||
|
|
transport = ASGITransport(app=app)
|
|||
|
|
async with AsyncClient(transport=transport, base_url="http://t") as client:
|
|||
|
|
r = await client.post(
|
|||
|
|
"/internal/api/evaluation/replay/conversation",
|
|||
|
|
headers={"X-Internal-Eval-Key": "secret"},
|
|||
|
|
json={"conversation_id": "00000000-0000-0000-0000-000000000001"},
|
|||
|
|
)
|
|||
|
|
assert r.status_code == 400
|
|||
|
|
|
|||
|
|
|
|||
|
|
@pytest.mark.asyncio
|
|||
|
|
async def test_replay_conversation_rejects_both_fixture_and_utterances(
|
|||
|
|
monkeypatch: pytest.MonkeyPatch,
|
|||
|
|
) -> None:
|
|||
|
|
from fastapi import FastAPI
|
|||
|
|
|
|||
|
|
monkeypatch.setattr(
|
|||
|
|
"app.core.config.settings.internal_eval_api_key",
|
|||
|
|
"secret",
|
|||
|
|
raising=False,
|
|||
|
|
)
|
|||
|
|
from app.features.evaluation.router import router
|
|||
|
|
|
|||
|
|
app = FastAPI()
|
|||
|
|
app.include_router(router, prefix="/internal/api/evaluation")
|
|||
|
|
|
|||
|
|
async def _override_auth():
|
|||
|
|
from app.features.evaluation.internal_auth import InternalEvalPrincipal
|
|||
|
|
|
|||
|
|
return InternalEvalPrincipal()
|
|||
|
|
|
|||
|
|
app.dependency_overrides[get_internal_eval_principal] = _override_auth
|
|||
|
|
transport = ASGITransport(app=app)
|
|||
|
|
async with AsyncClient(transport=transport, base_url="http://t") as client:
|
|||
|
|
r = await client.post(
|
|||
|
|
"/internal/api/evaluation/replay/conversation",
|
|||
|
|
headers={"X-Internal-Eval-Key": "secret"},
|
|||
|
|
json={
|
|||
|
|
"conversation_id": "00000000-0000-0000-0000-000000000001",
|
|||
|
|
"fixture_filename": "x.md",
|
|||
|
|
"user_utterances": ["a"],
|
|||
|
|
},
|
|||
|
|
)
|
|||
|
|
assert r.status_code == 400
|