init
This commit is contained in:
53
tests/test_transfer_flow.py
Normal file
53
tests/test_transfer_flow.py
Normal file
@@ -0,0 +1,53 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""测试转人工流程:设计师在线查询 + 派单 + 无人在线时企微提醒"""
|
||||
import asyncio
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
# 测试用 API 地址(文档中的)
|
||||
os.environ.setdefault("DESIGNER_ROSTER_API", "http://huichang.online:8001/online")
|
||||
|
||||
|
||||
async def main():
|
||||
from utils.designer_roster import poll_and_update_roster
|
||||
from db.designer_roster_db import list_designers, get_transfer_group_for_shop
|
||||
|
||||
print("1. 查询并同步设计师在线状态...")
|
||||
await poll_and_update_roster()
|
||||
print(" OK")
|
||||
|
||||
print("\n2. 当前设计师状态:")
|
||||
for d in list_designers():
|
||||
status = "在线" if d["is_online"] else "离线"
|
||||
print(f" - {d['name']} ({d['wechat_user_id']}): {status}")
|
||||
|
||||
print("\n3. 派单测试 (店铺: 小威哥1216):")
|
||||
shop_id = "小威哥1216"
|
||||
group_id = get_transfer_group_for_shop(shop_id)
|
||||
if group_id:
|
||||
print(f" 派单成功 -> group_id={group_id}")
|
||||
else:
|
||||
print(" 无人在线,将回退到静态配置")
|
||||
print(" (转人工时会发企微「谁在线啊」)")
|
||||
|
||||
print("\n4. 静态回退:")
|
||||
from config.config import CONFIG_DIR
|
||||
import json
|
||||
cfg_path = CONFIG_DIR / "transfer_groups.json"
|
||||
default = "20252916034"
|
||||
if cfg_path.exists():
|
||||
with open(cfg_path, "r", encoding="utf-8") as f:
|
||||
cfg = json.load(f)
|
||||
fallback = cfg.get(shop_id, cfg.get("default", default))
|
||||
else:
|
||||
fallback = default
|
||||
print(f" 回退分组: {fallback}")
|
||||
|
||||
print("\n测试完成")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user