-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_test.py
81 lines (69 loc) · 2.34 KB
/
my_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
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
#test dellle funzioni CRUD del microservizio
#urllib3 ==> 1.26.7
import requests
import json
def read_all_test():
try:
r = requests.get('http://localhost:8000/book')
except requests.exceptions.ConnectionError:
print("connection failed!")
return False
if r.status_code == 200:
print("Read all successful, status code: ", r.status_code)
return True
else:
print("Something is wrong")
def create_test():
jtest = open('microservice/books/sample_test.json')
try:
r = requests.post('http://localhost:8000/book', json =json.load(jtest))
except requests.exceptions.ConnectionError:
print("connection failed!")
return False
if r.status_code == 200:
print("Create successful, status code: " , r.status_code)
return True
else:
print("Something is wrong, status code: ", r.status_code)
def update_test():
jtest = open('microservice/books/sample_update_test.json')
try:
r = requests.put('http://localhost:8000/book/Test', json =json.load(jtest))
except requests.exceptions.ConnectionError:
print("connection failed!")
return False
if r.status_code == 200:
print("Update successful, status code: " , r.status_code)
return True
else:
print("Something is wrong, status code: ", r.status_code)
def read_one_test():
try:
r = requests.get('http://localhost:8000/book/Test')
except requests.exceptions.ConnectionError:
print("connection failed!")
return False
if r.status_code == 200:
print("Read one successful, status code: ", r.status_code)
return True
else:
print("Something is wrong")
def delete_test():
try:
r = requests.delete('http://localhost:8000/book/Test')
except requests.exceptions.ConnectionError:
print("connection failed!")
return False
if r.status_code == 200:
print("Delete successful, status code: ", r.status_code)
return True
else:
print("Something is wrong")
def my_test():
if read_all_test() and create_test() and update_test() and read_one_test() and delete_test():
print("\U0001f600")
return True
else:
print("\U0001f622")
return False
print("Test result: ", my_test())