-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestonebotuser.py
67 lines (53 loc) · 1.48 KB
/
testonebotuser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import asyncio
import json
from flask import Flask, request
import websockets
import requests
EVENT_DATA = {
"user_id": "12234",
"self_id": "123234",
"messsage": "sajghds",
"type": "message",
"detail_type": "",
"sub_type": "",
"extended": {"data": "blah"},
}
ACTION_DATA1 = {
"action": "send_message",
"params": {"user_id": "123", "message": "abcc"},
"echo": {"id": "1"},
}
ACTION_DATA2 = {
"action": "qq_group_system_message",
"params": {"group_id": "123", "message": [{"type": "text"}, {"type": "text"}]},
"echo": {"id": "2"},
}
ACTION_RESULT1 = {
"status": "ok",
"retcode": 0,
"data": {},
"echo": ACTION_DATA1["echo"],
}
ACTION_RESULT2 = {
"status": "ok",
"retcode": 0,
"data": {},
"echo": ACTION_DATA2["echo"],
}
onebot_user = Flask("user")
@onebot_user.route("/", methods=["POST"])
def event():
print(f"Event received {str(request.json)}")
# assert dict(request.json) == EVENT_DATA
return {}
async def onebot_user_ws_test():
async with websockets.connect("ws://127.0.0.1:8081/ws") as onebot_user_ws:
while True:
print(await onebot_user_ws.recv())
def onebot_user_http_test():
result = requests.post("http://127.0.0.1:8080", json=ACTION_DATA1)
assert result.json() == ACTION_RESULT1
result = requests.post("http://127.0.0.1:8080", json=ACTION_DATA2)
assert result.json() == ACTION_RESULT2
if __name__ == "__main__":
onebot_user.run(host="127.0.0.1", port=5700)