Files
aios/scripts/run_wechat_behavior_simulation.py
T

21 lines
1.4 KiB
Python

#!/usr/bin/env python3
import urllib.request, urllib.parse, json, http.cookiejar, os, sys
base=os.environ.get('AIOS_WEBOPS_BASE','http://127.0.0.1:18081')
cj=http.cookiejar.CookieJar(); opener=urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
def form(path,data):
req=urllib.request.Request(base+path,data=urllib.parse.urlencode(data).encode(),headers={'Content-Type':'application/x-www-form-urlencoded'},method='POST')
return opener.open(req,timeout=10).read().decode()
def post(path,data):
req=urllib.request.Request(base+path,data=json.dumps(data).encode(),headers={'Content-Type':'application/json'},method='POST')
return json.loads(opener.open(req,timeout=10).read().decode())
form('/login',{'username':'admin','password':'bootstrap-change-me'})
cases=[('text','你好','text'),('quote_text','看一下这个方案','text'),('image','识别图片','vision'),('quote_image','这张图是什么','vision'),('file_pdf','总结一下文件','file'),('file_excel','看一下表格','file'),('quote_file','这个文件有什么问题','file')]
bad=[]
for typ,msg,expect in cases:
r=post('/api/simulation/wechat',{'username':'sample-user','message_type':typ,'content':msg})
print(typ, r)
if r.get('route_target')!=expect: bad.append((typ,expect,r))
if bad:
print('WECHAT_SIM_FAIL',bad); sys.exit(2)
print('WECHAT_BEHAVIOR_SIMULATION_PASS')