实现lsfx-mock全命中SQL对齐
This commit is contained in:
@@ -8,8 +8,13 @@ from services.file_service import FileService
|
||||
from services.statement_service import StatementService
|
||||
from services.statement_rule_samples import (
|
||||
DEFAULT_LARGE_TRANSACTION_THRESHOLDS,
|
||||
build_fixed_counterparty_transfer_samples,
|
||||
build_large_transaction_seed_statements,
|
||||
build_low_income_relative_large_transaction_samples,
|
||||
build_monthly_fixed_income_samples,
|
||||
build_seed_statements_for_rule_plan,
|
||||
build_special_amount_transaction_samples,
|
||||
build_suspicious_income_keyword_samples,
|
||||
)
|
||||
|
||||
|
||||
@@ -409,3 +414,100 @@ def test_get_bank_statement_contains_large_transaction_hit_samples(monkeypatch):
|
||||
assert any(amount > 50000001 for amount in income_amounts.values())
|
||||
assert any(count >= 6 for count in cash_deposit_daily_counter.values())
|
||||
assert has_large_transfer
|
||||
|
||||
|
||||
def test_special_amount_transaction_samples_should_use_sql_supported_amounts():
|
||||
statements = build_special_amount_transaction_samples(
|
||||
group_id=1000,
|
||||
log_id=20001,
|
||||
)
|
||||
|
||||
assert statements
|
||||
assert {item["transAmount"] for item in statements}.issubset({520.0, 1314.0})
|
||||
|
||||
|
||||
def test_monthly_fixed_income_samples_should_cover_at_least_six_months():
|
||||
statements = build_monthly_fixed_income_samples(
|
||||
group_id=1000,
|
||||
log_id=20001,
|
||||
)
|
||||
|
||||
income_months = {item["trxDate"][:7] for item in statements}
|
||||
|
||||
assert len(income_months) >= 6
|
||||
|
||||
|
||||
def test_suspicious_income_keyword_samples_should_hit_sql_keyword_set():
|
||||
statements = build_suspicious_income_keyword_samples(
|
||||
group_id=1000,
|
||||
log_id=20001,
|
||||
)
|
||||
|
||||
assert statements
|
||||
assert any(
|
||||
any(keyword in item["userMemo"] for keyword in ("工资", "分红", "红利", "奖金", "劳务费", "绩效"))
|
||||
or any(keyword in item["cashType"] for keyword in ("工资", "劳务费", "代发"))
|
||||
for item in statements
|
||||
)
|
||||
|
||||
|
||||
def test_fixed_counterparty_transfer_samples_should_use_staff_identity():
|
||||
statements = build_fixed_counterparty_transfer_samples(
|
||||
group_id=1000,
|
||||
log_id=20001,
|
||||
staff_id_card="320101199001010030",
|
||||
family_id_cards=["320101199201010051", "320101199301010052"],
|
||||
)
|
||||
|
||||
assert statements
|
||||
assert {item["cretNo"] for item in statements} == {"320101199001010030"}
|
||||
|
||||
|
||||
def test_low_income_relative_large_transaction_samples_should_exceed_total_threshold():
|
||||
statements = build_low_income_relative_large_transaction_samples(
|
||||
group_id=1000,
|
||||
log_id=20001,
|
||||
staff_id_card="320101199001010030",
|
||||
family_id_cards=["320101199201010051", "320101199301010052"],
|
||||
)
|
||||
|
||||
assert statements
|
||||
assert len({item["cretNo"] for item in statements}) == 1
|
||||
assert sum(item["crAmount"] + item["drAmount"] for item in statements) > 100000
|
||||
|
||||
|
||||
def test_generate_statements_should_keep_all_mode_noise_as_safe_debits(monkeypatch):
|
||||
file_service = FileService(staff_identity_repository=FakeStaffIdentityRepository())
|
||||
statement_service = StatementService(file_service=file_service)
|
||||
|
||||
monkeypatch.setattr("services.file_service.settings.RULE_HIT_MODE", "all")
|
||||
|
||||
response = file_service.fetch_inner_flow(
|
||||
{
|
||||
"groupId": 1001,
|
||||
"customerNo": "customer_safe_noise",
|
||||
"dataChannelCode": "test_code",
|
||||
"requestDateId": 20240101,
|
||||
"dataStartDateId": 20240101,
|
||||
"dataEndDateId": 20240131,
|
||||
"uploadUserId": 902001,
|
||||
}
|
||||
)
|
||||
log_id = response["data"][0]
|
||||
record = file_service.file_records[log_id]
|
||||
record.large_transaction_hit_rules = []
|
||||
record.phase1_hit_rules = []
|
||||
record.phase2_statement_hit_rules = [
|
||||
"MONTHLY_FIXED_INCOME",
|
||||
"FIXED_COUNTERPARTY_TRANSFER",
|
||||
]
|
||||
|
||||
statements = statement_service._generate_statements(group_id=1001, log_id=log_id, count=30)
|
||||
noise_statements = [
|
||||
item
|
||||
for item in statements
|
||||
if item["userMemo"] not in {"月度稳定兼职收入", "季度稳定兼职收入"}
|
||||
]
|
||||
|
||||
assert noise_statements
|
||||
assert all(item["drAmount"] > 0 and item["crAmount"] == 0 for item in noise_statements)
|
||||
|
||||
Reference in New Issue
Block a user