-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
53 lines (46 loc) · 1.62 KB
/
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
import json
import requests
host = "127.0.0.1:9000"
with open("docs/swagger.json", 'r') as f:
temp = json.loads(f.read())
dict = temp["paths"]
for k, v in dict.items():
url = host + k
data = {}
method = ""
if "get" in v.keys():
method = "GET"
else:
method = "POST"
print(method)
for k2, v2 in v.items():
for k3,v3 in v2.items():
list = v2["parameters"]
dict3 = list[0]
print(dict3)
name = dict3["default"]
data[name] = name
print(data)
resp = {}
if v2["consumes"] == "multipart/form-data":
resp = requests.request(method=method, url=url, data=data)
elif v2["consumes"] == ".../json":
resp = requests.request(method=method, url=url, json=data)
print(resp)
#
# for p in v["parameters"]:
# data[p[name]] = p["name"]
# print(p)
# print(data)
# if v["consumes"] == "multipart/form-data":
# requests.request(method=method, url=url, data=data)
# elif v["consumes"] == ".../json":
# requests.request(method=method, url=url, json=data)
# resp = requests.request(method=method, url=url, data=data, headers={"Content_Type" : v["consumes"]})
# print(v["summary"], "status_code is", resp.status_code)
#
# if v["produces"] == "json":
# try:
# resp.json()
# except:
# print(k, "response is error")