-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.py
More file actions
72 lines (58 loc) · 2.45 KB
/
Copy pathtest_api.py
File metadata and controls
72 lines (58 loc) · 2.45 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
import requests
def check_home_page(_url):
response_home_page = requests.get(_url)
if response_home_page.status_code == 200:
print("Homepage is Fine!")
return 200
else:
print("Homepage is Down!!!")
return 300
def check_add_users(_url):
response_add_user = requests.post(_url, json={'user-id':'9999','user-name':'testuser','user-email':'testuser@test.com','user-password':'testpass'})
if response_add_user.status_code == 200:
print("Adding user didn't fail , now checking if the user exists")
return_value = check_if_user_added('http://localhost:5000/ListUsers/9999')
if return_value == 200:
return 200
else:
return 300
else:
print("Adding user FAILED with status code = " + str(response_add_user.status_code))
return 300
def check_if_user_added(_url):
response_check_created_user = requests.get(_url)
if str(response_check_created_user.json()) == "[[9999, 'testuser', 'testuser@test.com', 'testpass']]":
print("User Created Successfully!")
return 200
else:
print("User is not created successfully!!!")
return 300
def check_modify_user(_url):
response_modify_user = requests.put(_url, json={'user-id':'9999', 'user-name':'changed', 'user-email':'changed', 'user-password':'changed'})
if response_modify_user.status_code == 200:
print ("Modifying user didn't fail, checking if actually changed")
if str(requests.get('http://localhost:5000/ListUsers/9999').json()) == "[[9999, 'changed', 'changed', 'changed']]":
print ("User Successfully changed!!")
return 200
else:
return 300
else:
return 300
def check_delete_users(_url):
response_delete_user = requests.delete(_url)
if str(response_delete_user.json()) == 'User Deleted Successfully':
print ("User Deleted Successfully")
return 200
else:
return 300
def test_api():
_url = 'http://localhost:5000'
homepage_status = check_home_page(_url)
adduser_status = check_add_users(_url + '/' + 'AddUser')
modifyuser_status = check_modify_user(_url + '/' + 'ModifyUser')
deleteuser_status = check_delete_users(_url + '/' + 'DeleteUser/9999')
if homepage_status == 300 or adduser_status == 300 or modifyuser_status == 300 or deleteuser_status == 300:
print ("Test failed")
else:
print ("Test succeeded")
test_api()