# -*- 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_html_parse(): """测试:排班 HTML 解析 + 工作日计算""" from app.service.hrbp.oa.common.parser import parse_attendance_html, get_work_days_in_range html = """ 休息 正常 休息 """ result = parse_attendance_html(html) assert result == {"2026-08-01": "休息", "2026-08-02": "正常", "2026-08-03": "休息"} work_days = get_work_days_in_range(result, "2026-08-01", "2026-08-03") assert work_days == ["2026-08-02"], f"工作日计算错误: {work_days}" logger.info("[通过] 排班 HTML 解析 + 工作日计算") def test_attendance_summary(): """测试:打卡明细按日汇总(含跨天凌晨下班)""" from app.service.hrbp.oa.common.parser import summarize_attendance_records records = [ {"staff_id": "S001", "staff_name": "张三", "bc_date": "2026-08-02", "kq_time": "2026-08-02 08:50:00", "status": "1", "time_order": "1", "DEPT_ORG_NAME": "技术部", "POST_ALIAS_NAME": "工程师"}, {"staff_id": "S001", "staff_name": "张三", "bc_date": "2026-08-02", "kq_time": "2026-08-02 12:00:00", "status": "5", "time_order": "2", "DEPT_ORG_NAME": "技术部", "POST_ALIAS_NAME": "工程师"}, {"staff_id": "S001", "staff_name": "张三", "bc_date": "2026-08-02", "kq_time": "2026-08-03 00:30:00", "status": "5", "time_order": "2", "DEPT_ORG_NAME": "技术部", "POST_ALIAS_NAME": "工程师"}, {"staff_id": "S001", "staff_name": "张三", "bc_date": "2026-08-02", "kq_time": "2026-08-02 19:00:00", "status": "6", "time_order": "1", "DEPT_ORG_NAME": "技术部", "POST_ALIAS_NAME": "工程师"}, # 重复打卡,应过滤 ] summary = summarize_attendance_records(records) assert len(summary) == 1, f"汇总天数错误: {len(summary)}" row = summary[0] assert row["first_check_in"] == "2026-08-02 08:50:00" assert row["last_check_out"] == "2026-08-03 00:30:00" # 跨天最晚 logger.info("[通过] 打卡汇总(含跨天 + 过滤重复): 最早=%s, 最晚=%s", row["first_check_in"], row["last_check_out"]) 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_html_parse() test_attendance_summary() test_overtime_form_parse() logger.info("========== 测试④结束 ==========")