本次提交主要包含以下内容: 1. 归档tests/hrbp目录下的旧版测试文件至tests/_app_蓝图版归档目录 2. 新增tests/_app_蓝图版归档/hrbp目录下的新版测试辅助脚本和测试用例 3. 新增雇主险场景下的WPS COM可行性验证脚本 4. 更新README.md中关于tests目录的说明,明确各子目录用途 5. 更新XQ0035工作流相关文件中的操作人UnionID,更换为人资专用号 6. 修复试用期变更脚本中日期转换的问题,确保AI表格时间戳正确转换为日期格式 7. 归档XQ0035工作流下的旧版测试脚本至测试归档目录
120 lines
5.0 KiB
Python
120 lines
5.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
@Module: tests.hrbp.test_04_parsers
|
|
@FileName: test_04_parsers.py
|
|
@Author: 小布丁
|
|
@CreateTime: 2026-08-06 10:50
|
|
@Description: 连通性测试④——纯解析函数(无需登录,离线测试)
|
|
@Version: 1.0.0
|
|
"""
|
|
import os
|
|
import sys
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
|
|
|
|
from tests.hrbp._helpers import logger # noqa: E402
|
|
|
|
|
|
def test_attendance_daily_work_days():
|
|
"""测试:排班数据 → 实际上班天数统计(休息日/无记录不计)"""
|
|
from unittest.mock import MagicMock, patch
|
|
from app.service.hrbp.oa.leave.validator import _get_work_days_count
|
|
|
|
shift = [
|
|
{
|
|
"2026-08-10_bc_name": "经营正班A",
|
|
"2026-08-11_bc_name": "经营正班A",
|
|
"2026-08-12_bc_name": "休息",
|
|
"2026-08-13_bc_name": "经营正班A",
|
|
},
|
|
]
|
|
hr_ctx = (MagicMock(), "user-001")
|
|
|
|
with patch("app.service.hrbp.oa.leave.validator._get_hr_context",
|
|
return_value=hr_ctx), \
|
|
patch("app.service.hrbp.oa.leave.validator.fetch_all_shift",
|
|
return_value=shift):
|
|
count = _get_work_days_count("S001", "2026-08-10", "2026-08-13")
|
|
assert count == 3, f"实际上班天数错误: {count}"
|
|
|
|
# 区间内无排班的日期(休息日)也视为休息
|
|
with patch("app.service.hrbp.oa.leave.validator._get_hr_context",
|
|
return_value=hr_ctx), \
|
|
patch("app.service.hrbp.oa.leave.validator.fetch_all_shift",
|
|
return_value=shift):
|
|
count2 = _get_work_days_count("S001", "2026-08-10", "2026-08-16")
|
|
assert count2 == 3, f"含无记录日期的实际上班天数错误: {count2}"
|
|
|
|
logger.info("[通过] 排班上班天数统计: 休息日/无记录均不计入")
|
|
|
|
|
|
def test_attendance_daily_merge():
|
|
"""测试:考勤逐日四种状态(休息/正常/未打卡/异常)各查一次后合并去重"""
|
|
from unittest.mock import MagicMock, patch
|
|
from app.service.hrbp.oa.common.oa_api.attendance import get_attendance_daily
|
|
|
|
session = MagicMock()
|
|
normal = [{"work_day": "2026-08-14", "bc_name": "经营正班A", "xb_dk_time": "18:05:58"}]
|
|
abnormal = [{"work_day": "2026-08-15", "bc_name": "维护早班", "bc_begin_time": "08:00",
|
|
"bc_end_time": "17:00", "xb_dk_time2": "19:49:49"}]
|
|
|
|
def fake_request(session, method, url, params, desc):
|
|
# 按 kq_status_total 参数返回对应状态的数据
|
|
status = params.get("kq_status_total")
|
|
if status == "1":
|
|
return {"data": normal}
|
|
if status == "11":
|
|
return {"data": abnormal}
|
|
return {"data": []}
|
|
|
|
with patch("app.service.hrbp.oa.common.oa_api.attendance.oa_request_json",
|
|
side_effect=fake_request) as m:
|
|
records = get_attendance_daily(session, "S001", "2026-08-14", "2026-08-15")
|
|
|
|
# 四种状态各请求一次
|
|
assert m.call_count == 4, f"应请求4次,实际{m.call_count}"
|
|
# 合并去重后按日期升序
|
|
assert [r["work_day"] for r in records] == ["2026-08-14", "2026-08-15"], \
|
|
f"合并顺序错误: {records}"
|
|
# 异常班记录保留班次与打卡
|
|
ab_rec = records[1]
|
|
assert ab_rec["bc_name"] == "维护早班"
|
|
assert ab_rec["bc_end_time"] == "17:00"
|
|
assert ab_rec["xb_dk_time2"] == "19:49:49"
|
|
logger.info("[通过] 考勤逐日状态合并: 休息/正常/未打卡/异常各查一次,合并去重保留班次与打卡")
|
|
|
|
|
|
def test_overtime_form_parse():
|
|
"""测试:加班表单解析 + 类型映射"""
|
|
from app.service.hrbp.oa.work_overtime.parser import parse_overtime_form
|
|
|
|
form_data = {
|
|
"staff_id": "572e6cce-7a9f-11ec-b449-000c296f9469",
|
|
"staff_name": "黄俊林",
|
|
"dept_org_name": "网络项目小组",
|
|
"ot_type": "1", # → 延时加班
|
|
"subsidy_type": "2", # → 转补贴
|
|
"ot_date": "2026-08-02",
|
|
"start_time": "2026-08-02 18:00",
|
|
"end_time": "2026-08-03 00:00",
|
|
"ot_hour": 6.0,
|
|
"judge_ot_hour": 6.0,
|
|
"judge_start_time": "2026-08-02 18:00:00",
|
|
"judge_end_time": "2026-08-03 00:00:00",
|
|
"file": "ccc1d3ef-175a-4105-a8a8-0e63ed88d7bd",
|
|
}
|
|
info = parse_overtime_form(form_data)
|
|
assert info["加班人员ID"] == "572e6cce-7a9f-11ec-b449-000c296f9469"
|
|
assert info["加班类型"] == "延时加班", f"类型映射错误: {info['加班类型']}"
|
|
assert info["补贴类型"] == "转补贴"
|
|
assert info["系统判定加班时间"] == "2026-08-02 18:00:00 至 2026-08-03 00:00:00"
|
|
logger.info("[通过] 加班表单解析 + 类型映射: %s", info["加班类型"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
logger.info("========== 测试④:纯解析函数(离线) ==========")
|
|
test_attendance_daily_work_days()
|
|
test_attendance_daily_merge()
|
|
test_overtime_form_parse()
|
|
logger.info("========== 测试④结束 ==========")
|