Files
zkxw/backend/tests/test_qc_task_result_batch.py
T
zlwuandCursor 1b339247d3
continuous-integration/drone/tag Build is passing
perf(qc): 填写结果弹窗改为批量/并行加载,减少 N+1 接口 (#185)
第三方合填由 2N 次 detail+results 改为 1 次批量 results;单任务打开时 detail 与 results 并行请求。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-12-02 18:50:52 +08:00

42 lines
1.2 KiB
Python

"""list_results_by_task_ids / merge helpers (no DB)."""
from app.crud.qc_task_result import _merge_saved_into_template
def test_merge_saved_into_template_prefers_param_id():
templates = [
{
"id": "p1",
"paramName": "浓度",
"paramCode": "conc",
"paramUnit": "mg/L",
"paramType": "number",
"options": "",
"defaultValue": "",
"requiredFlag": "1",
}
]
saved = [{"paramId": "p1", "paramCode": "conc", "paramValue": "1.2"}]
out = _merge_saved_into_template(templates, saved)
assert len(out) == 1
assert out[0]["paramId"] == "p1"
assert out[0]["paramValue"] == "1.2"
assert out[0]["requiredFlag"] == "1"
def test_merge_select_uses_default_when_empty():
templates = [
{
"id": "p2",
"paramName": "判定",
"paramCode": "judge",
"paramUnit": "",
"paramType": "select",
"options": '["合格","不合格"]',
"defaultValue": "合格",
"requiredFlag": "0",
}
]
out = _merge_saved_into_template(templates, [])
assert out[0]["paramValue"] == "合格"