"""看板工作汇报页:单页 HTML 同时覆盖日常工作、自研产品、定制项目与年度财务表。""" from __future__ import annotations from app import constants from app.db import SessionLocal from app.models import CustomProject def test_看板导出完整工作汇报页(h): week = h.period(2028, 3, 2) old_week = h.period(2028, 2, 1) first = constants.period_first_day(2028, 3, 2) project = h.project("自研甲", owners=["王芳"], is_key=True) second_project = h.project("自研乙", owners=["李四"], is_key=True) h.update(project["id"], week["id"], content="完成联调", summary='
接口联调完成待确认
补充说明
', status="at_risk", risk="等文档") h.update(second_project["id"], week["id"], content="完成方案", summary="方案评审通过") h.focus("准备验收材料", period_id=week["id"], detail='

整理验收清单完成

第二行

', due_date="2028-03-20") h.focus("历史遗留任务", period_id=old_week["id"], detail="不该出现在选中周期", delayed=True) added = h.custom("新增乙", origin="华智下单", amount=100000, sign_date=first, update_date=first, project_status="进行中") accepted = h.custom("验收丙", origin="华智下单", amount=200000, update_date=first, project_status="已验收") risky = h.custom("高风险丁", origin="华智下单", amount=300000, risk_level="1.高风险") idle_risky = h.custom("高风险戊", origin="华智下单", amount=400000, risk_level="1.高风险") h.custom_update(risky["id"], week["id"], content="协调风险") # 创建接口固定写今天;把周期字段改成选中周期,对齐看板的「本期」口径 with SessionLocal() as db: for name in ("新增乙", "验收丙"): row = next(row for row in db.query(CustomProject).all() if row.name == name) row.update_date = first + " 09:00" row.sign_date = first db.commit() resp = h.admin.get("/api/export/board-report", params={"period_id": week["id"]}) assert resp.status_code == 200, resp.text assert resp.headers["content-type"].startswith("text/html") assert "attachment" in resp.headers["content-disposition"] assert ".html" in resp.headers["content-disposition"] body = resp.text for text in ("工作汇报", "一、日常工作", "二、自研产品", "三、年度任务财务情况", "四、定制项目", "准备验收材料", "新增乙", "验收丙", "计收目标(万元)"): assert text in body, text assert "高风险丁" not in body assert "高风险戊" not in body assert "本期没有重点工作" not in body assert "2028 Q1" in body assert "历史遗留任务" not in body assert body.index("自研乙") < body.index("方案评审通过") < body.index("自研甲") < body.index("联调完成") assert body.index("三、年度任务财务情况") < body.index("四、定制项目") assert "接口联调完成" in body assert '待确认' in body assert "整理" in body assert "完成" in body assert "第二行" in body filtered = h.admin.get("/api/export/board-report", params={"period_id": week["id"], "keyword": "不存在的工作"}) assert "本期没有重点工作" in filtered.text assert "接口联调完成" not in filtered.text assert "新增乙" not in filtered.text