-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
94 lines (75 loc) · 3.11 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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python3
import requests
import sys
def check_requests(requests, uid, expected):
response = requests.get('http://' + address + '/v1/' + str(uid))
assert response.status_code == 200
assert expected == response.json()
if __name__ == '__main__':
address = str(sys.argv[1])
test_data = {'testint': 3, 'teststring': 'hi', 'testobj': {'inside': True}}
bad_data = '}}}}}}}}}}'
print("")
print("Make sure the get request works on the root.")
assert requests.get('http://' + address + '/v1/').status_code == 200
print("")
print("Make sure getting from a non-existing uid doesn't work.")
assert requests.get('http://' + address + '/v1/' + 'badtest').status_code == 404
print("")
print("Attempt to post to the root to create a UID.")
response = requests.post('http://' + address + '/v1/')
assert response.status_code == 200
uid = response.json()['uid']
print("Success.")
print("")
print("Attempt to put non-JSON data to the UID, expecting failure.")
assert requests.put('http://' + address + '/v1/' + str(uid), data=bad_data).status_code == 400
print("Success.")
print("")
print("Put legitimate JSON data into the provided UID.")
assert requests.put('http://' + address + '/v1/' + str(uid), json=test_data).status_code == 200
print("Success.")
print("")
print("Ensure it was updated correctly.")
check_requests(requests, uid, test_data)
print("Success.")
print("")
print("Delete the UID before testing post.")
assert requests.delete('http://' + address + '/v1/' + str(uid)).status_code == 200
print("Success.")
print("")
print("Attempt to post to a deleted UID.")
assert requests.post('http://' + address + '/v1/' + str(uid), json=test_data).status_code == 404
print("Success.")
print("")
print("Attempt to post to the root to create a UID.")
response = requests.post('http://' + address + '/v1/')
assert response.status_code == 200
uid = response.json()['uid']
print("Success.")
print("")
print("Attempt to post non-JSON data to the UID, expecting failure.")
assert requests.post('http://' + address + '/v1/' + str(uid), data=bad_data).status_code == 400
print("Success.")
print("")
print("Post legitimate JSON data into the provided UID.")
assert requests.post('http://' + address + '/v1/' + str(uid), json=test_data).status_code == 200
print("Success.")
print("")
print("Ensure it was updated correctly.")
check_requests(requests, uid, test_data)
print("Success.")
print("")
print("Delete the POST test UID.")
assert requests.delete('http://' + address + '/v1/' + str(uid)).status_code == 200
print("Success.")
print("")
print("Try to delete a non-existing UID.")
assert requests.delete('http://' + address + '/v1/' + str(uid)).status_code == 404
print("Success.")
print("")
print("Attempt to get from a non-existing UID that existed before.")
assert requests.get('http://' + address + '/v1/' + str(uid)).status_code == 404
print("Success.")
print("")
print("All tests passed.")