Files
pricing_review/CostReview/app/tests/test_api_group.py
lianjianwei2024 dd6bd24018 feat(price): 信息价/市场价重设计——目录树+行内编辑+只收标准模板+导出一份数据(决策42)
- schema: 新增 price_dirs 目录树(批次级单根/多级/仅叶挂行),prices.dir_id;Class 冗余完整路径文本
- 导入只收标准模板 xlsx:表头严格校验(HTML/别名/多sheet拆批退役);名称默认=文件名可改;期次从文件名认
- 后台明细页重做:左树行内增删改名/上下移(↑↓✕两段式确认、选中按钮常显),右表行内新增/编辑(重算比对键即刻生效)
- 导出 zip = 价格明细.xlsx(目录路径+批次信息页签)+ 附件原件,导入可复原
- 壳/跨页跳转带版本参数根治 WebView2 旧缓存;导入弹框文件框只收 .xlsx
- 附 P0/P1 接口测试夹具与价格重设计回归(新增 test_price_redesign 等 8 件,全套 148 项绿)
2026-10-13 08:35:34 +08:00

102 lines
4.7 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""类似清单分组 v2 管线测试:条数守恒、名称层字集并组、关键词层(规则表)、
组价不一致。全部经真实接口(/api/session/similar、/api/session/inconsistent)。"""
import json
import sqlite3
from api_harness import fixture_file, get, post, server # noqa: F401
BILLS = [
("010101001001", "镀锌钢管DN25", "1、螺纹连接", "m", 10, 100),
("010101002001", "镀锌钢管DN25", "1、螺纹连接", "m", 20, 150),
("010101003001", "镀锌钢管DN32", "1、螺纹连接", "m", 5, 120),
("020202001001", "钢筋混凝土", "C30泵送", "t", 3, 4000),
("020202002001", "混凝土钢筋", "C30泵送", "t", 2, 4200),
("030303001001", "欧姆龙PLC模块", "", "台", 1, 800),
] # 6 条可比(+1 条无定额措施项 → 被视图层排除)
def _q(db, sql, args=()):
con = sqlite3.connect("file:%s?mode=ro" % db, uri=True)
try:
return con.execute(sql, args).fetchall()
finally:
con.close()
def _setup(server):
pa = fixture_file(server, "grp.cos4", "分组工程G", BILLS)
sid = post(server, "/api/audit",
{"path": str(pa), "name": "分组工程G", "province": "广东省",
"city": "珠海市", "district": "香洲区",
"period_from": 2026 * 12 + 7, "file_kind": 1})["session_id"]
return sid
def _all_ids(resp):
return [row[0] for part in (resp["groups"] + resp["extra"])
for row in part["rows"]]
def test_group_conservation_and_name_layer(server):
sid = _setup(server)
rows = get(server, "/api/session/rows", session_id=sid, type="bill")
assert rows["total"] == 7 # 6 可比 + 1 措施(单位=项被视图层滤掉)
resp = get(server, "/api/session/similar", session_id=sid)
ids = _all_ids(resp)
assert len(ids) == 6 and len(set(ids)) == 6 # 条数守恒:不多、不少、不重复
# 名称层:钢筋混凝土 与 混凝土钢筋(字集等价)同组
grp_rebar = [g for g in resp["groups"]
if any(r[2] == "钢筋混凝土" for r in g["rows"])]
assert len(grp_rebar) == 1 and grp_rebar[0]["n"] == 2
assert {r[2] for r in grp_rebar[0]["rows"]} == {"钢筋混凝土", "混凝土钢筋"}
# 名称近似的三条钢管并为一组(DN25×2 + DN32)
grp_pipe = [g for g in resp["groups"] if g["n"] == 3]
assert len(grp_pipe) == 1 and grp_pipe[0]["spread"] > 0
# 落单的 PLC 进「其他」组,固定殿后
assert resp["extra"] and resp["extra"][0]["cat"] == "其他"
assert resp["extra"][0]["n"] == 1
assert resp["extra"][0]["rows"][0][2] == "欧姆龙PLC模块"
# 组排序:按合计合价降序(钢筋组 8200 > 钢管组 370)
assert resp["groups"][0]["tsum"] >= resp["groups"][-1]["tsum"]
def test_group_keyword_layer(server):
"""分组设置表(global.grp_rules):关键词首匹配 + 排除词 + <2 条不成组。"""
_setup(server) # 确保会话存在(同名原地续用)
con = sqlite3.connect(server["sessdb"]) # 直写设置表(设置无独立写接口)
try:
con.execute("""INSERT INTO s_settings(scope,k,v) VALUES('global','grp_rules',?)
ON CONFLICT(scope,k) DO UPDATE SET v=excluded.v""",
(json.dumps([{"seq": 1, "name": "钢管组",
"keywords": "钢管 镀锌", "exclude": "塑料"}],
ensure_ascii=False),))
con.commit()
finally:
con.close()
resp = get(server, "/api/session/similar", session_id=_sid(server))
kw = [g for g in resp["groups"] if g.get("cat") == "钢管组"]
assert len(kw) == 1 and kw[0]["n"] == 3 # 关键词层优先收走三条钢管
assert {r[2] for r in kw[0]["rows"]} == {"镀锌钢管DN25", "镀锌钢管DN32"}
assert len(set(_all_ids(resp))) == len(_all_ids(resp)) == 6
# 清掉规则,不影响其他用例
con = sqlite3.connect(server["sessdb"])
try:
con.execute("DELETE FROM s_settings WHERE scope='global' AND k='grp_rules'")
con.commit()
finally:
con.close()
def _sid(server):
return _q(server["sessdb"], "SELECT id FROM sessions WHERE name='分组工程G'")[0][0]
def test_inconsistent_same_spec_diff_price(server):
"""组价不一致:同名同特征、单价不同 → 一组,差% 按组统计。"""
sid = _setup(server)
resp = get(server, "/api/session/inconsistent", session_id=sid)
# 镀锌钢管DN25 两条同名同特征(100 vs 150)→ 一组,差 50%
g = [x for x in resp["groups"] if x["n"] == 2 and x["pmin"] == 100]
assert len(g) == 1 and g[0]["spread"] == 50.0