接入异常账户基线同步触发点
This commit is contained in:
@@ -5,6 +5,7 @@ FileService 单一主绑定语义测试
|
||||
import asyncio
|
||||
import io
|
||||
|
||||
import pytest
|
||||
from fastapi import BackgroundTasks
|
||||
from fastapi.datastructures import UploadFile
|
||||
|
||||
@@ -27,6 +28,22 @@ class FakeStaffIdentityRepository:
|
||||
}
|
||||
|
||||
|
||||
class FakeAbnormalAccountBaselineService:
|
||||
def __init__(self, should_fail=False):
|
||||
self.should_fail = should_fail
|
||||
self.calls = []
|
||||
|
||||
def apply(self, staff_id_card, abnormal_accounts):
|
||||
self.calls.append(
|
||||
{
|
||||
"staff_id_card": staff_id_card,
|
||||
"abnormal_accounts": [dict(item) for item in abnormal_accounts],
|
||||
}
|
||||
)
|
||||
if self.should_fail:
|
||||
raise RuntimeError("baseline sync failed")
|
||||
|
||||
|
||||
def test_upload_file_primary_binding_response(monkeypatch):
|
||||
"""同一 logId 的主绑定必须稳定且只保留一组主体/账号信息。"""
|
||||
service = FileService(staff_identity_repository=FakeStaffIdentityRepository())
|
||||
@@ -186,6 +203,56 @@ def test_fetch_inner_flow_should_attach_abnormal_account_rule_plan():
|
||||
assert isinstance(record.abnormal_accounts, list)
|
||||
|
||||
|
||||
def test_fetch_inner_flow_should_sync_abnormal_account_baselines_before_caching():
|
||||
baseline_service = FakeAbnormalAccountBaselineService()
|
||||
service = FileService(
|
||||
staff_identity_repository=FakeStaffIdentityRepository(),
|
||||
abnormal_account_baseline_service=baseline_service,
|
||||
)
|
||||
|
||||
response = service.fetch_inner_flow(
|
||||
{
|
||||
"groupId": 1001,
|
||||
"customerNo": "customer_abnormal_baseline",
|
||||
"dataChannelCode": "test_code",
|
||||
"requestDateId": 20240101,
|
||||
"dataStartDateId": 20240101,
|
||||
"dataEndDateId": 20240131,
|
||||
"uploadUserId": 902001,
|
||||
}
|
||||
)
|
||||
|
||||
log_id = response["data"][0]
|
||||
record = service.file_records[log_id]
|
||||
|
||||
assert baseline_service.calls
|
||||
assert baseline_service.calls[0]["staff_id_card"] == record.staff_id_card
|
||||
assert baseline_service.calls[0]["abnormal_accounts"] == record.abnormal_accounts
|
||||
|
||||
|
||||
def test_fetch_inner_flow_should_not_cache_log_id_when_abnormal_account_baseline_sync_fails():
|
||||
baseline_service = FakeAbnormalAccountBaselineService(should_fail=True)
|
||||
service = FileService(
|
||||
staff_identity_repository=FakeStaffIdentityRepository(),
|
||||
abnormal_account_baseline_service=baseline_service,
|
||||
)
|
||||
|
||||
with pytest.raises(RuntimeError, match="baseline sync failed"):
|
||||
service.fetch_inner_flow(
|
||||
{
|
||||
"groupId": 1001,
|
||||
"customerNo": "customer_abnormal_baseline_fail",
|
||||
"dataChannelCode": "test_code",
|
||||
"requestDateId": 20240101,
|
||||
"dataStartDateId": 20240101,
|
||||
"dataEndDateId": 20240131,
|
||||
"uploadUserId": 902001,
|
||||
}
|
||||
)
|
||||
|
||||
assert service.file_records == {}
|
||||
|
||||
|
||||
def test_generate_log_id_should_retry_when_random_value_conflicts(monkeypatch):
|
||||
"""随机 logId 命中已存在记录时必须重试并返回未占用值。"""
|
||||
service = FileService(staff_identity_repository=FakeStaffIdentityRepository())
|
||||
|
||||
Reference in New Issue
Block a user