feat: 完善策略优选项目工作流
This commit is contained in:
1 parent
a26fd32eba
commit
5d6627af50
45 files changed
+7235
-768
No files matched your search
@@ -0,0 +1,72 @@
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
from fastapi import HTTPException
|
||||
|
||||
from app.gateway.routers import system_settings as system_settings_router
|
||||
from deerflow.config.system_settings import SystemSettings
|
||||
|
||||
|
||||
def test_strategy_project_demo_is_hidden_by_default() -> None:
|
||||
assert SystemSettings().strategy_projects.taiwan_strait_demo_enabled is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_non_admin_cannot_update_strategy_project_settings(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
async def ordinary_user(_request):
|
||||
return SimpleNamespace(system_role="user")
|
||||
|
||||
monkeypatch.setattr(
|
||||
system_settings_router,
|
||||
"get_optional_user_from_request",
|
||||
ordinary_user,
|
||||
)
|
||||
|
||||
with pytest.raises(HTTPException) as error:
|
||||
await system_settings_router.update_strategy_project_settings(
|
||||
system_settings_router.StrategyProjectSettingsUpdateRequest(
|
||||
taiwan_strait_demo_enabled=True,
|
||||
),
|
||||
SimpleNamespace(),
|
||||
)
|
||||
|
||||
assert error.value.status_code == 403
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_admin_can_update_strategy_project_settings(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
current = SystemSettings()
|
||||
saved: list[SystemSettings] = []
|
||||
|
||||
async def admin_user(_request):
|
||||
return SimpleNamespace(system_role="admin")
|
||||
|
||||
monkeypatch.setattr(
|
||||
system_settings_router,
|
||||
"get_optional_user_from_request",
|
||||
admin_user,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
system_settings_router,
|
||||
"load_system_settings",
|
||||
lambda: current,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
system_settings_router,
|
||||
"save_system_settings",
|
||||
lambda settings: saved.append(settings) or settings,
|
||||
)
|
||||
|
||||
response = await system_settings_router.update_strategy_project_settings(
|
||||
system_settings_router.StrategyProjectSettingsUpdateRequest(
|
||||
taiwan_strait_demo_enabled=True,
|
||||
),
|
||||
SimpleNamespace(),
|
||||
)
|
||||
|
||||
assert response.taiwan_strait_demo_enabled is True
|
||||
assert saved[0].strategy_projects.taiwan_strait_demo_enabled is True
|
||||
Reference in new issue
Block a user