- 访谈:新增 interview_state_hints,联动 orchestrator 与提示词 - 回忆录:story_pipeline_sync/state/memory/post_commit 与 Celery 任务调整 - 基建:开发用 celery broker、compose/development 脚本、依赖注入 - eval-web:移除数据集/实验/版本等页面与流式轮询,突出 Playground - 文档与单测同步
70 lines
2.0 KiB
Python
70 lines
2.0 KiB
Python
"""内部路由在未配密钥时应 503。"""
|
|
|
|
import pytest
|
|
from httpx import ASGITransport, AsyncClient
|
|
|
|
from app.features.evaluation.internal_auth import get_internal_eval_principal
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_internal_eval_list_fixtures_requires_config(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
):
|
|
from fastapi import FastAPI
|
|
|
|
monkeypatch.setattr(
|
|
"app.core.config.settings.internal_eval_api_key",
|
|
"",
|
|
raising=False,
|
|
)
|
|
from app.features.evaluation.router import router
|
|
|
|
app = FastAPI()
|
|
app.include_router(router, prefix="/internal/api/evaluation")
|
|
transport = ASGITransport(app=app)
|
|
async with AsyncClient(transport=transport, base_url="http://t") as client:
|
|
r = await client.get("/internal/api/evaluation/fixtures/user-exports")
|
|
assert r.status_code == 503
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_internal_eval_with_override_lists_fixtures(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
):
|
|
from fastapi import FastAPI
|
|
|
|
monkeypatch.setattr(
|
|
"app.core.config.settings.internal_eval_api_key",
|
|
"secret",
|
|
raising=False,
|
|
)
|
|
def _empty_fixtures() -> list[str]:
|
|
return []
|
|
|
|
monkeypatch.setattr(
|
|
"app.features.evaluation.admin_service.list_user_export_md_filenames",
|
|
_empty_fixtures,
|
|
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.get(
|
|
"/internal/api/evaluation/fixtures/user-exports",
|
|
headers={"X-Internal-Eval-Key": "secret"},
|
|
)
|
|
assert r.status_code == 200
|
|
assert r.json() == {"items": []}
|