-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPI_Requests.py
More file actions
78 lines (58 loc) · 1.92 KB
/
Copy pathAPI_Requests.py
File metadata and controls
78 lines (58 loc) · 1.92 KB
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
68
69
70
71
72
73
74
75
76
77
78
import requests
import json
import datetime
import Helpers as hp
base_uri = "http://127.0.0.1:8088"
class stat:
# this variable are static variables
post_status = ""
shutdown_status = ""
def base_url():
return base_uri
def get_post_response(file_name):
# read input
url = base_uri + "/hash"
input_data = open(hp.get_root_path() + '/TestData/' + file_name, 'r')
request_body = json.dumps(json.load(input_data))
headers = {'Accept': 'application/json'}
# print(datetime.datetime.now())
response = requests.post(url, headers=headers, data=request_body)
stat.post_status = response.status_code
return response
def get_encoded_password(job_id):
url = base_uri + "/hash/" + job_id
print("sending get request{}")
print(datetime.datetime.now())
return requests.get(url)
def get_stats(sub_url=""):
# default: sub_url = "/stats"
if sub_url == "":
sub_url = "/stats"
url = base_uri + sub_url
return requests.get(url)
def shutdown():
url = base_uri + "/hash"
data = 'shutdown'
print('shutting down')
print(datetime.datetime.now())
shut_down = requests.post(url, data=data)
stat.shutdown_status = shut_down.status_code
return shut_down
def delete(job_id):
url = base_uri + "/hash/" + job_id
del_resp = requests.delete(url)
return del_resp
def put(file_name):
url = base_uri + "/hash"
input_data = open(hp.get_root_path() + '/TestData/' + file_name, 'r')
request_body = json.dumps(json.load(input_data))
response = requests.put(url, data=request_body)
stat.post_status = response.status_code
return response
def patch(file_name):
url = base_uri + "/hash"
input_data = open(hp.get_root_path() + '/TestData/' + file_name, 'r')
request_body = json.dumps(json.load(input_data))
response = requests.patch(url, data=request_body)
stat.post_status = response.status_code
return response