Files
37duAutomation/tests/hrbp/test_03_attendance.py
T
puddy 249088614d feat(hrbp): 完成HRBP加班审批系统全链路开发
新增:
1.  新增依赖包chinese_calendar,完善.gitignore会话存储配置
2.  新增完整测试套件与项目初始化文件
3.  实现延时/休息日/法定假日加班审批规则(参考aa.md文档)
4.  新增排班、打卡、请假数据获取与解析工具
5.  完善会话管理与持久化存储逻辑
6.  实现格式化审批报告生成功能

修改:
1.  调整请假校验函数签名以传入会话对象
2.  更新审批流程调用逻辑适配新校验函数
3.  重构cookie存储路径与目录创建逻辑
4.  优化日志输出级别与调试信息
2026-08-06 21:03:20 +08:00

74 lines
2.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""
@Module: tests.hrbp.test_03_attendance
@FileName: test_03_attendance.py
@Author: 小布丁
@CreateTime: 2026-08-06 10:45
@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 get_logged_in_session, logger # noqa: E402
# 测试用员工(黄俊林),可按需改成环境变量或从待办单据动态获取
TEST_STAFF_ID = "572e6cce-7a9f-11ec-b449-000c296f9469"
TEST_DATE = "2026-08-02"
def test_attendance_html(session, staff_id: str, year: int, month: int):
"""测试:排班 HTML 接口 + 解析"""
from app.service.hrbp.oa.common.oa_api import get_attendance_html
from app.service.hrbp.oa.common.parser import parse_attendance_html
html = get_attendance_html(session, staff_id, year, month)
assert html, "排班 HTML 为空"
attendance = parse_attendance_html(html)
assert isinstance(attendance, dict), "排班解析结果非字典"
logger.info("[通过] 排班接口正常,当月解析到 %d 天班次", len(attendance))
for date, shift in list(attendance.items())[:5]:
logger.info(" %s: %s", date, shift)
return attendance
def test_punch_records(session, staff_id: str, start_date: str, end_date: str):
"""测试:打卡明细接口 + 按日汇总(迁移自原 test.py)"""
from app.service.hrbp.oa.common.oa_api import get_attendance_records
from app.service.hrbp.oa.common.parser import summarize_attendance_records
# 1. 拉取原始打卡明细
records = get_attendance_records(session, staff_id, start_date, end_date)
assert isinstance(records, list), "打卡明细格式异常"
logger.info("[通过] 打卡明细接口正常,返回 %d 条原始记录", len(records))
# 2. 按日汇总:每日最早上班 / 最晚下班
summary = summarize_attendance_records(records)
logger.info("[通过] 打卡汇总完成,共 %d 天", len(summary))
for row in summary:
logger.info(" %s | %s | 最早:%s | 最晚:%s",
row.get("attend_date"),
row.get("staff_name"),
row.get("first_check_in") or "无",
row.get("last_check_out") or "无")
return summary
if __name__ == "__main__":
logger.info("========== 测试③:排班 + 打卡明细 ==========")
browser, session = get_logged_in_session(subject="加班")
year = int(TEST_DATE[:4])
month = int(TEST_DATE[5:7])
test_attendance_html(session, TEST_STAFF_ID, year, month)
# 打卡查询范围:当天 + 次日(覆盖跨天凌晨下班)
from datetime import datetime, timedelta
end = (datetime.strptime(TEST_DATE, "%Y-%m-%d") + timedelta(days=1)).strftime("%Y-%m-%d")
test_punch_records(session, TEST_STAFF_ID, TEST_DATE, end)
logger.info("========== 测试③结束 ==========")