新增征信员工HTML样本并改造Mock解析

This commit is contained in:
wkc
2026-03-23 20:35:52 +08:00
parent 27aab7f9bc
commit 823e9f75a9
1016 changed files with 16400 additions and 9 deletions

View File

@@ -87,4 +87,22 @@ def sample_inner_flow_request():
@pytest.fixture
def sample_credit_html_file():
"""示例征信 HTML 文件。"""
return ("credit.html", b"<html></html>", "text/html")
html = """
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="ccdi-staff-name" content="测试员工" />
<meta name="ccdi-staff-id-card" content="320101199001010030" />
<title>征信解析员工样本</title>
</head>
<body>
<main>
<h1>征信解析员工样本</h1>
<p>姓名:测试员工</p>
<p>身份证号320101199001010030</p>
</main>
</body>
</html>
"""
return ("credit.html", html.encode("utf-8"), "text/html")

View File

@@ -10,6 +10,8 @@ def test_html_eval_should_return_credit_payload(client, sample_credit_html_file)
assert data["status_code"] == "0"
assert data["message"] == "成功"
assert "lx_header" in data["payload"]
assert data["payload"]["lx_header"]["query_cust_name"] == "测试员工"
assert data["payload"]["lx_header"]["query_cert_no"] == "320101199001010030"
def test_html_eval_should_return_err_99999_for_missing_model(client, sample_credit_html_file):

View File

@@ -0,0 +1,19 @@
from services.credit_html_identity_service import CreditHtmlIdentityService
def test_extract_identity_should_read_generated_html_meta_fields():
service = CreditHtmlIdentityService()
html = """
<html>
<head>
<meta name="ccdi-staff-name" content="王五" />
<meta name="ccdi-staff-id-card" content="330101198801010011" />
</head>
<body></body>
</html>
"""
identity = service.extract_identity(html)
assert identity["staff_name"] == "王五"
assert identity["staff_id_card"] == "330101198801010011"

View File

@@ -3,22 +3,30 @@ from services.credit_payload_service import CreditPayloadService
def test_generate_payload_should_be_stable_for_same_input():
service = CreditPayloadService("config/credit_feature_schema.json")
identity = {
"staff_name": "张三",
"staff_id_card": "330101198801010011",
}
payload1 = service.generate_payload(
model="LXCUSTALL",
h_type="PERSON",
filename="credit-report-a.html",
subject_identity=identity,
)
payload2 = service.generate_payload(
model="LXCUSTALL",
h_type="PERSON",
filename="credit-report-a.html",
subject_identity=identity,
)
assert payload1 == payload2
assert set(payload1.keys()) == {"lx_header", "lx_debt", "lx_publictype"}
assert len(payload1["lx_debt"]) == 21
assert len(payload1["lx_publictype"]) == 6
assert payload1["lx_header"]["query_cust_name"] == "张三"
assert payload1["lx_header"]["query_cert_no"] == "330101198801010011"
def test_generate_payload_should_use_schema_type_rules():
@@ -28,6 +36,10 @@ def test_generate_payload_should_use_schema_type_rules():
model="LXCUSTALL",
h_type="ENTERPRISE",
filename="credit-report-b.html",
subject_identity={
"staff_name": "李四",
"staff_id_card": "330101199001010022",
},
)
assert payload["lx_debt"]["uncle_bank_house_state"] in {"正常", "逾期", "不良"}

View File

@@ -0,0 +1,26 @@
from services.staff_credit_html_export_service import StaffCreditHtmlExportService
class FakeStaffRepository:
def select_active_staff_identities(self):
return [
{"staff_name": "张三", "staff_id_card": "110101199001010011"},
{"staff_name": "李四", "staff_id_card": "110101199202023456"},
]
def test_export_should_write_one_html_per_staff(tmp_path):
service = StaffCreditHtmlExportService(FakeStaffRepository())
generated_files = service.export(tmp_path)
assert len(generated_files) == 2
first_html = generated_files[0].read_text(encoding="utf-8")
second_html = generated_files[1].read_text(encoding="utf-8")
assert generated_files[0].name == "0001_张三_0011.html"
assert generated_files[1].name == "0002_李四_3456.html"
assert 'meta name="ccdi-staff-name" content="张三"' in first_html
assert 'meta name="ccdi-staff-id-card" content="110101199001010011"' in first_html
assert "姓名:李四" in second_html
assert "身份证号110101199202023456" in second_html