-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi-test.py
63 lines (48 loc) · 1.81 KB
/
api-test.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
import requests
url = "http://127.0.0.1:6880/api"
user = "admin"
password = "12345678"
# workaround cookie domain restrain when testing
cookie = None
def print_res(res):
print(res.status_code)
print(f"\n {res.text}")
def get_info():
res = requests.get(url + "/user/info", cookies=cookie)
print_res(res)
def create_admin():
res = requests.post(url + "/admin/create_admin", json={"Name": user, "Password": password})
print_res(res)
def login():
global cookie
res = requests.post(url + "/login", json={"Name": user, "Password": password})
if res.status_code % 100 == 2:
cookie = {'token': res.cookies.get('token')}
print_res(res)
def get_all_items():
res = requests.get(url + "/user/all_items", cookies=cookie)
print_res(res)
def create_stockpile(location: str, code: str):
res = requests.post(url+ "/user/create_stockpile", cookies=cookie, json={"code": code, "name": location})
print_res(res)
# negative size means retrieval
def update_item(item: str, size: int, location: str):
res = requests.post(url + "/user/update_item", json={"item": item, "size": size, "location": location}, cookies=cookie)
print_res(res)
def get_all_stockpiles():
res = requests.get(url + "/user/all_stockpiles", cookies=cookie)
print_res(res)
def get_clan_invitation():
import json
res = requests.get(url + "/clan/invitation", cookies=cookie)
body = json.loads(res.text)
print(body)
res = requests.post(url + "/register", cookies={"token": body["token"]}, json={"Name": "clanman", "Password": "123456789123456789"})
print_res(res)
def invite_clan():
import json
res = requests.get(url + "/admin/invite_clan", cookies=cookie)
print_res(res)
def check_name(name):
res = requests.post(url + "/check_name", json={"name": name})
print_res(res)