-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
50 lines (40 loc) · 1.63 KB
/
main.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
import sys
import random
import string
import requests
PIPES = 3
def main():
server_addr = sys.argv[1] if 1 < len(sys.argv) else "127.0.0.1:8080"
api_url = f"http://{server_addr}/api"
token = sys.argv[2] if 2 < len(sys.argv) else ''.join(
random.choice(string.ascii_lowercase) for _ in range(16))
def collect():
pipe = random.randint(1, PIPES)
response = requests.put(f"{api_url}/pipe/{pipe}",
headers={"Authorization": f"Bearer {token}"})
assert response.status_code == 200
print("Collect pipe", pipe, "=", response.json())
def value():
pipe = random.randint(1, PIPES)
response = requests.get(f"{api_url}/pipe/{pipe}/value",
headers={"Authorization": f"Bearer {token}"})
assert response.status_code == 200
print("Pipe", pipe, "=", response.json())
def modifier():
pipe = random.randint(1, PIPES)
type = random.choice(
["slow", "double", "min", "shuffle", "reverse"])
response = requests.post(f"{api_url}/pipe/{pipe}/modifier",
json={"type": type},
headers={"Authorization": f"Bearer {token}"})
if response.status_code == 200:
print("Applied modifier", type, "to pipe", pipe)
elif response.status_code == 422:
print("Failed to apply modifier")
else:
raise Exception(
f"Unexpected status code {response.status_code}")
while True:
random.choice([collect, value, modifier])()
if __name__ == "__main__":
main()