新增征信解析接口与错误模拟
This commit is contained in:
@@ -37,7 +37,21 @@ def reset_file_service_state():
|
||||
@pytest.fixture
|
||||
def client():
|
||||
"""创建测试客户端"""
|
||||
return TestClient(app)
|
||||
original_routes = list(app.router.routes)
|
||||
try:
|
||||
from routers import credit_api
|
||||
|
||||
if not any(route.path == "/xfeature-mngs/conversation/htmlEval" for route in app.routes):
|
||||
app.include_router(credit_api.router, tags=["征信解析接口"])
|
||||
app.openapi_schema = None
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
|
||||
try:
|
||||
yield TestClient(app)
|
||||
finally:
|
||||
app.router.routes[:] = original_routes
|
||||
app.openapi_schema = None
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -68,3 +82,9 @@ def sample_inner_flow_request():
|
||||
"dataEndDateId": 20240131,
|
||||
"uploadUserId": 902001,
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_credit_html_file():
|
||||
"""示例征信 HTML 文件。"""
|
||||
return ("credit.html", b"<html></html>", "text/html")
|
||||
|
||||
45
lsfx-mock-server/tests/test_credit_api.py
Normal file
45
lsfx-mock-server/tests/test_credit_api.py
Normal file
@@ -0,0 +1,45 @@
|
||||
def test_html_eval_should_return_credit_payload(client, sample_credit_html_file):
|
||||
response = client.post(
|
||||
"/xfeature-mngs/conversation/htmlEval",
|
||||
data={"model": "LXCUSTALL", "hType": "PERSON"},
|
||||
files={"file": sample_credit_html_file},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["status_code"] == "0"
|
||||
assert data["message"] == "成功"
|
||||
assert "lx_header" in data["payload"]
|
||||
|
||||
|
||||
def test_html_eval_should_return_err_99999_for_missing_model(client, sample_credit_html_file):
|
||||
response = client.post(
|
||||
"/xfeature-mngs/conversation/htmlEval",
|
||||
data={"hType": "PERSON"},
|
||||
files={"file": sample_credit_html_file},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json()["status_code"] == "ERR_99999"
|
||||
|
||||
|
||||
def test_html_eval_should_return_err_10003_for_invalid_h_type(client, sample_credit_html_file):
|
||||
response = client.post(
|
||||
"/xfeature-mngs/conversation/htmlEval",
|
||||
data={"model": "LXCUSTALL", "hType": "JSON"},
|
||||
files={"file": sample_credit_html_file},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json()["status_code"] == "ERR_10003"
|
||||
|
||||
|
||||
def test_html_eval_should_support_debug_error_marker(client, sample_credit_html_file):
|
||||
response = client.post(
|
||||
"/xfeature-mngs/conversation/htmlEval",
|
||||
data={"model": "error_ERR_10001", "hType": "PERSON"},
|
||||
files={"file": sample_credit_html_file},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json()["status_code"] == "ERR_10001"
|
||||
Reference in New Issue
Block a user