fix: 设备验收预警优化

This commit is contained in:
sophie committed 2026-10-13 15:52:09 +08:00
1 parent 7e7bcbd388
commit b8cc0cbe77
25 files changed
+1398 -193

No files matched your search

@@ -0,0 +1,58 @@
"""
tests/test_equipment_acceptance_alert_notice.py
用途:锁定设备验收企微汇总文案和 Excel 列。
依赖:alert_notice、openpyxl。
逻辑:不连数据库,不发企业微信。卡片只写张数。工作簿含申请人,不写主送。
"""
from io import BytesIO
import pytest
from openpyxl import load_workbook
pytestmark = pytest.mark.pure_unit
from app.services.equipment_acceptance.alert_notice import (
NOTICE_HEADERS,
build_notice_workbook,
summary_message,
)
def test_summary_counts_rounds_without_listing_orders():
"""第一行写已逾期张数。正文不出现验收单号,也不写主送。"""
text = summary_message([
{"threshold_days": 30},
{"threshold_days": 30},
{"threshold_days": 37},
])
assert text == "共 3 张验收单已逾期。\n超过 30 天 2 张,超过 37 天 1 张。\n明细见下一条文件。"
assert "主送" not in text
assert "20260210" not in text
def test_workbook_includes_applicant_and_identity():
"""Excel 列与原型一致。通知身份保留角色名,停留天数为空时写横线。"""
data = build_notice_workbook([{
"acceptance_no": "20260210000001",
"purchase_order_no": "1111",
"applicant": "孙浩",
"threshold_days": 30,
"dwell_days": None,
"node_name": "使用部门担当",
"handlers": "吴敏",
"identity": "直接主管",
}])
sheet = load_workbook(BytesIO(data)).active
assert [cell.value for cell in sheet[1]] == list(NOTICE_HEADERS)
assert [cell.value for cell in sheet[2]] == [
"20260210000001",
"1111",
"孙浩",
"超过 30 天",
"—",
"使用部门担当",
"吴敏",
"直接主管",
]
@@ -30,6 +30,7 @@ def test_due_tiers_use_strictly_greater_than_threshold():
assert due_tiers(31, _DAYS) == [1]
assert due_tiers(51, _DAYS) == [1, 2, 3]
assert due_tiers(52, _DAYS) == [1, 2, 3, 4]
assert due_tiers(52, _DAYS, max_tier=3) == [1, 2, 3]
def test_tier_one_keeps_missing_supervisor_as_failure():
@@ -1,15 +1,15 @@
"""
tests/test_equipment_acceptance_config.py
用途:锁定设备验收预警四档天数的保存前校验。
依赖:config_service.validate_reminder_days、ValidationError。
逻辑:不连数据库。默认 30/37/44/51 通过;相等、倒序、非整数和空岗位以外的天数形状被拒绝。
用途:锁定设备验收预警四档天数和第 4 轮开关的保存前校验。
依赖:config_service.validate_reminder_days、parse_round_4_enabled、ValidationError。
逻辑:不连数据库。默认 30/37/44/51 通过;相等、倒序、非整数和空岗位以外的天数形状被拒绝。第 4 轮缺省关闭。
"""
import pytest
from app.core.errors import ValidationError
from app.services.equipment_acceptance.config_service import validate_reminder_days
from app.services.equipment_acceptance.config_service import parse_round_4_enabled, validate_reminder_days
def test_default_reminder_days_pass():
@@ -30,3 +30,13 @@ def test_days_reject_bool_and_wrong_length():
validate_reminder_days([True, 37, 44, 51])
with pytest.raises(ValidationError):
validate_reminder_days([30, 37, 44])
def test_round_4_defaults_off_and_rejects_non_bool():
"""未传开关时按关闭处理。数字 1 不能当成启用,避免误通知总经理。"""
assert parse_round_4_enabled(None) is False
assert parse_round_4_enabled(False) is False
assert parse_round_4_enabled(True) is True
with pytest.raises(ValidationError) as caught:
parse_round_4_enabled(1)
assert caught.value.code == "EQUIPMENT_ACCEPTANCE.SETTINGS_INVALID"