修复风控预警记录查询与准备脚本

This commit is contained in:
zhangshy
2026-09-11 16:40:15 +08:00
parent d2cdbbac01
commit a122f7afba
4 changed files with 32 additions and 4 deletions
+5 -1
View File
@@ -146,7 +146,11 @@ class RiskQueryService:
page=page_request,
)
elif source == "alerts":
alert_page = await repository.list_alerts(keyword=query.keyword, page=page_request)
alert_page = await repository.list_alerts(
keyword=query.keyword,
open_only=False,
page=page_request,
)
return self._page(alert_page, binding=binding)
elif source == "notifications":
page = await repository.list_notifications(
@@ -73,6 +73,10 @@ class RecordingRepository(FakeRepository):
self.calls.append(("notifications", kwargs))
return self.page
async def list_alerts(self, **kwargs) -> FundPage:
self.calls.append(("alerts", kwargs))
return self.page
def context(**updates) -> RequestContext:
values = {
@@ -205,3 +209,14 @@ async def test_evidence_time_filters_are_interpreted_as_local_time(source: str)
assert repository.calls[0][0] == source
assert repository.calls[0][1]["start_time"] == datetime(2026, 9, 10, 4, 0)
assert repository.calls[0][1]["end_time"] == datetime(2026, 9, 10, 5, 0)
@pytest.mark.asyncio
async def test_evidence_alert_records_include_closed_alerts() -> None:
repository = RecordingRepository()
service = RiskQueryService(None, repository=repository)
await service.list_evidence(context(), "alerts", RiskEvidencePageQuery())
assert repository.calls[0][0] == "alerts"
assert repository.calls[0][1]["open_only"] is False
+6 -1
View File
@@ -36,10 +36,15 @@
import asyncio
import datetime as dt
import sys
from pathlib import Path
import asyncmy
from app.core.config import get_settings
PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from app.core.config import get_settings # noqa: E402
# (permission_code, resource, action, 授予的角色)
PERMISSIONS: tuple[tuple[str, str, str, tuple[str, ...]], ...] = (
+6 -2
View File
@@ -31,8 +31,12 @@ import asyncmy
import httpx
import jwt
from app.core.config import get_settings
from app.main import create_app
PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from app.core.config import get_settings # noqa: E402
from app.main import create_app # noqa: E402
ADMIN = "9003"
AGENT_TYPE = "risk"