本次提交主要包含以下内容: 1. 归档tests/hrbp目录下的旧版测试文件至tests/_app_蓝图版归档目录 2. 新增tests/_app_蓝图版归档/hrbp目录下的新版测试辅助脚本和测试用例 3. 新增雇主险场景下的WPS COM可行性验证脚本 4. 更新README.md中关于tests目录的说明,明确各子目录用途 5. 更新XQ0035工作流相关文件中的操作人UnionID,更换为人资专用号 6. 修复试用期变更脚本中日期转换的问题,确保AI表格时间戳正确转换为日期格式 7. 归档XQ0035工作流下的旧版测试脚本至测试归档目录
136 lines
5.9 KiB
Python
136 lines
5.9 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""
|
||
@FileName: test_mode_check.py
|
||
@Description: XQ0035 测试模式(只读)——校验「人资专用号」登录态与各台账查询权限。
|
||
全程仅调用查询接口,不发起流程、不改数据、不回填:
|
||
1) getCurUserInfo 确认当前登录账号身份,并与 trial_period_change.py
|
||
内硬编码操作人(CURRENT_USER_ID/CURRENT_STAFF_ID)比对
|
||
2) 试用期人员 / 合同台账-生效中合同 / 变更转正三 Tab 按工号只读查询
|
||
3) WeProcess 流程待办查询(改签离职电子签)
|
||
用法:.venv\\Scripts\\python.exe test_mode_check.py [工号1 工号2 ...]
|
||
(默认查询 37036273 本人)
|
||
"""
|
||
import importlib.util
|
||
import json
|
||
import os
|
||
import sys
|
||
|
||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||
# 本脚本已归档至 测试归档/ 子目录,主脚本在上级目录
|
||
MODULE_PATH = os.path.join(os.path.dirname(HERE), "trial_period_change.py")
|
||
GET_CUR_USER_INFO_URL = ("https://hr.37du.co/RedseaPlatform/"
|
||
"PtUsers.mc?method=getCurUserInfo")
|
||
|
||
|
||
def _load_module(name, path):
|
||
spec = importlib.util.spec_from_file_location(name, path)
|
||
m = importlib.util.module_from_spec(spec)
|
||
sys.modules[name] = m
|
||
spec.loader.exec_module(m)
|
||
return m
|
||
|
||
|
||
def _pick_identity_fields(obj, out, depth=0):
|
||
"""递归摘取身份相关字段(name/code/id 类),便于人工核对当前账号。"""
|
||
if depth > 4 or len(out) > 20:
|
||
return
|
||
if isinstance(obj, dict):
|
||
for k, v in obj.items():
|
||
kl = str(k).lower()
|
||
if isinstance(v, str) and any(t in kl for t in ("name", "code", "id", "account")):
|
||
out.append(f"{k}={v}")
|
||
else:
|
||
_pick_identity_fields(v, out, depth + 1)
|
||
elif isinstance(obj, list):
|
||
for v in obj[:5]:
|
||
_pick_identity_fields(v, out, depth + 1)
|
||
|
||
|
||
def main():
|
||
tpc = _load_module("trial_period_change", MODULE_PATH)
|
||
session = tpc._build_session()
|
||
print("共享 cookies 文件:", tpc.SHARED_HR_COOKIE_FILE)
|
||
print()
|
||
|
||
# ---------- 1) 当前登录身份 ----------
|
||
print("=" * 60)
|
||
print("1) 当前登录身份(getCurUserInfo)")
|
||
print("=" * 60)
|
||
try:
|
||
resp = session.post(GET_CUR_USER_INFO_URL, data={}, timeout=15)
|
||
text = resp.text
|
||
if not text.lstrip().startswith(("{", "[")):
|
||
print("❌ 登录态已失效(返回非 JSON)。请先运行「37duHR登录」指令重新登录后重试。")
|
||
print("返回内容片段:", text[:200])
|
||
return
|
||
info = resp.json()
|
||
fields = []
|
||
_pick_identity_fields(info, fields)
|
||
print("身份字段:", "; ".join(fields) if fields else json.dumps(info, ensure_ascii=False)[:500])
|
||
uid_ok = tpc.CURRENT_USER_ID in text
|
||
sid_ok = tpc.CURRENT_STAFF_ID in text
|
||
print()
|
||
print(f"脚本硬编码 CURRENT_USER_ID={tpc.CURRENT_USER_ID} 在当前登录态响应中: "
|
||
f"{'✅ 命中' if uid_ok else '⚠️ 未命中'}")
|
||
print(f"脚本硬编码 CURRENT_STAFF_ID={tpc.CURRENT_STAFF_ID} 在当前登录态响应中: "
|
||
f"{'✅ 命中' if sid_ok else '⚠️ 未命中'}")
|
||
if not (uid_ok and sid_ok):
|
||
print("⚠️ 硬编码操作人与当前登录账号可能不一致:写操作(发起流程/确认)会以别人身份提交,")
|
||
print(" 正式使用前需把 trial_period_change.py 内三个 CURRENT_* 常量更新为当前账号的值。")
|
||
except Exception as e:
|
||
print(f"❌ 身份查询异常:{e}")
|
||
return
|
||
|
||
# ---------- 2) 各台账 Tab 只读查询 ----------
|
||
codes = [c for c in (sys.argv[1:] or ["37036273", "37036361"]) if c.strip()]
|
||
for code in codes:
|
||
print()
|
||
print("=" * 60)
|
||
print(f"2) 工号 {code} 只读查询")
|
||
print("=" * 60)
|
||
try:
|
||
staff = tpc.query_trial_staff(session, code)
|
||
if staff:
|
||
print(f" 试用期人员: ✅ 命中 {staff.get('hr_staff_base.staff_name', '')} "
|
||
f"(base_id={staff.get('hr_staff_base.base_id', '')})")
|
||
else:
|
||
print(" 试用期人员: 无记录(接口可查,无该工号数据)")
|
||
except Exception as e:
|
||
print(f" 试用期人员: ❌ {e}")
|
||
try:
|
||
contract = tpc.query_active_contract(session, code)
|
||
if contract:
|
||
print(f" 生效中合同: ✅ 命中 contract_id={contract['contract_id']} "
|
||
f"({contract.get('staff_name', '')},到期 {contract.get('contract_end_date') or '未知'})")
|
||
else:
|
||
print(" 生效中合同: 无记录(接口可查,无该工号数据)")
|
||
except Exception as e:
|
||
print(f" 生效中合同: ❌ {e}")
|
||
try:
|
||
stage, rec = tpc.check_processed_stage(session, code)
|
||
print(f" 变更三Tab(已生效/待确认/待生效): {stage or '均无记录'}")
|
||
except Exception as e:
|
||
print(f" 变更三Tab: ❌ {e}")
|
||
|
||
# ---------- 3) 流程待办 ----------
|
||
print()
|
||
print("=" * 60)
|
||
print("3) 流程待办查询(改签离职电子签,WeProcess)")
|
||
print("=" * 60)
|
||
try:
|
||
wf = tpc.query_transfer_workflow(session)
|
||
if wf:
|
||
print(f" ✅ 命中:{wf['title']}(发起人={wf.get('create_user')},时间={wf.get('create_time')})")
|
||
print(f" 详情链接: {wf['url']}")
|
||
else:
|
||
print(" 无记录(接口可查,暂无该类流程实例)")
|
||
except Exception as e:
|
||
print(f" ❌ {e}")
|
||
|
||
print()
|
||
print("测试模式(只读)执行完毕:以上均为查询接口,未做任何写操作。")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|