Files
37duAutomation/tests/hrbp/test_07_confirm_abnormal.py
T
puddy 9d067c0646 refactor(workflows): 统一替换 yingdao 目录引用为 workflows
1.  将所有文档、代码中对 `yingdao/` 目录的引用替换为 `workflows/`,统一影刀版代码的命名空间
2.  调整 workflows/share 模块内的路径引用与文档注释,确保一致性
3.  同步更新测试代码与配置文件中的旧目录引用
2026-09-08 16:16:35 +08:00

114 lines
4.5 KiB
Python

# -*- coding: utf-8 -*-
"""
@Module: tests.hrbp.test_07_confirm_abnormal
@FileName: test_07_confirm_abnormal.py
@Author: 小布丁
@CreateTime: 2026-08-24
@Description: 周考勤异常「确认异常」功能测试:
拉取上周未调整异常 → 展示列表供人工挑选一条 → 确认无误后调用确认接口提交
→ 重查验证该条已从「未调整」列表消失。
注意:确认异常为真实写操作(type=1 自动确认异常),提交后无法撤销,
请务必人工核对所选记录无误后再确认。
@Version: 1.0.0
"""
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
from tests.hrbp._helpers import setup_logging, get_logger # noqa: E402
setup_logging()
logger = get_logger("tests.hrbp.test_07_confirm_abnormal")
def fetch_unadjusted():
"""构建会话并拉取当月未调整考勤异常,返回 (session, data)。"""
from app.service.hrbp.ehr.attendance.attendance_abnormal import (
build_hr_session,
_validate_session,
fetch_all_attendance_abnormal,
last_week_range,
IS_ADJUSTED,
)
session = build_hr_session()
session, user_id, treecode = _validate_session(session)
begin, end = last_week_range()
logger.info("查询范围:%s ~ %s,状态:未调整(%s)", begin, end, IS_ADJUSTED)
data = fetch_all_attendance_abnormal(session, user_id, treecode, begin, end, IS_ADJUSTED)
return session, data
def show_list(data):
"""按行展示未调整异常,返回序号 → abnormal_id 的映射。"""
print("\n===== 上周未调整考勤异常清单 =====")
print(f"{'序号':<4}{'abnormal_id':<34}{'工号':<10}{'姓名':<10}{'日期':<12}{'班次':<10}{'异常类型':<14}{'时长'}")
for i, it in enumerate(data, 1):
print(
f"{i:<4}{str(it.get('abnormal_id', '')):<34}"
f"{str(it.get('base_code', '')):<10}{str(it.get('STAFF_NAME', '')):<10}"
f"{str(it.get('work_day', '')):<12}{str(it.get('bc_name', '')):<10}"
f"{str(it.get('abnormal', '')):<14}{str(it.get('abnormal_minute', '') or 0)}"
)
print(f"共 {len(data)} 条\n")
return {i: it.get("abnormal_id") for i, it in enumerate(data, 1)}
def main():
session, data = fetch_unadjusted()
if not data:
logger.warning("上周无未调整考勤异常,无需测试")
return
mapping = show_list(data)
raw = input("请输入要确认的异常序号(Enter 取消):").strip()
if not raw:
logger.info("已取消,未提交任何确认")
return
try:
idx = int(raw)
except ValueError:
logger.error("输入无效:%s", raw)
return
if idx not in mapping:
logger.error("序号 %d 不在清单范围内", idx)
return
abnormal_id = mapping[idx]
logger.warning("即将对 abnormal_id=%s 调用确认接口(type=1,真实提交,不可撤销)", abnormal_id)
again = input("再次确认无误?输入 y 提交,其他取消:").strip().lower()
if again != "y":
logger.info("已取消,未提交")
return
from app.service.hrbp.ehr.attendance.attendance_abnormal import confirm_abnormal
result = confirm_abnormal(abnormal_id, session=session)
logger.info("确认接口返回:%s", result)
if result.get("state") != "1":
logger.error("确认失败:%s", result.get("meg") or result)
return
# 重查验证:该条应从「未调整」列表消失
_, data_after = fetch_unadjusted()
remaining = [it for it in data_after if str(it.get("abnormal_id", "")) == str(abnormal_id)]
if remaining:
logger.error("验证失败:abnormal_id=%s 仍在未调整列表中", abnormal_id)
else:
logger.info("[通过] abnormal_id=%s 已确认成功,不再出现在未调整列表(剩余 %d 条)",
abnormal_id, len(data_after))
# 影刀单文件版静态就绪校验(不发起真实请求)
import importlib
workflows = importlib.import_module("workflows.hr.attendance_abnormal")
assert callable(workflows.confirm_abnormal), "影刀版缺少 confirm_abnormal"
assert callable(workflows.adjust_abnormal), "影刀版缺少 adjust_abnormal"
assert workflows.ATTENDANCE_ADJUST_URL.endswith("KqCountAbnormal.mc"), "影刀版确认接口地址异常"
logger.info("[通过] 影刀单文件版 confirm_abnormal 已就绪(未发请求)")
if __name__ == "__main__":
main()