-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_server.py
148 lines (117 loc) · 4.55 KB
/
test_server.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import requests
import unittest
import test_server_blanks as blanks
class TestAPI(unittest.TestCase):
def test_01_add_workload(self):
response = requests.get(blanks.WORKLOADS_ENDPOINT)
self.assertEqual(response.status_code, 204)
response = requests.post(
blanks.WORKLOADS_ENDPOINT,
json=blanks.WORKLOAD_1
)
self.assertEqual(response.status_code, 201)
response = requests.post(
blanks.WORKLOADS_ENDPOINT,
json=blanks.WORKLOAD_2
)
self.assertEqual(response.status_code, 201)
response = requests.post(
blanks.WORKLOADS_ENDPOINT,
json=blanks.WORKLOAD_3
)
self.assertEqual(response.status_code, 201)
response = requests.post(
blanks.WORKLOADS_ENDPOINT,
json=blanks.WORKLOAD_4
)
self.assertEqual(response.status_code, 400)
def test_02_get_workload(self):
response = requests.get(blanks.WORKLOADS_ENDPOINT)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()[1], 3)
def test_03_modify_workload(self):
response = requests.put(
blanks.WORKLOAD_3_ENDPOINT,
json=blanks.WORKLOAD_3_MODIFIED
)
self.assertEqual(response.status_code, 200)
response = requests.put(
blanks.WORKLOAD_4_ENDPOINT,
json=blanks.WORKLOAD_3_MODIFIED
)
self.assertEqual(response.status_code, 404)
response = requests.put(
blanks.WORKLOAD_2_ENDPOINT,
json=blanks.WORKLOAD_2_NOT_MODIFIED
)
self.assertEqual(response.status_code, 304)
def test_04_delete_workload(self):
response = requests.delete(blanks.WORKLOAD_3_ENDPOINT)
self.assertEqual(response.status_code, 200)
response = requests.delete(blanks.WORKLOAD_4_ENDPOINT)
self.assertEqual(response.status_code, 404)
def test_05_add_migration(self):
response = requests.get(blanks.MIGRATIONS_ENDPOINT)
self.assertEqual(response.status_code, 204)
response = requests.post(
blanks.MIGRATIONS_ENDPOINT,
json=blanks.MIGRATION_1
)
self.assertEqual(response.status_code, 201)
response = requests.post(
blanks.MIGRATIONS_ENDPOINT,
json=blanks.MIGRATION_2
)
self.assertEqual(response.status_code, 201)
response = requests.post(
blanks.MIGRATIONS_ENDPOINT,
json=blanks.MIGRATION_3
)
self.assertEqual(response.status_code, 201)
response = requests.post(
blanks.MIGRATIONS_ENDPOINT,
json=blanks.MIGRATION_4
)
self.assertEqual(response.status_code, 400)
response = requests.post(
blanks.MIGRATIONS_ENDPOINT,
json=blanks.MIGRATION_5
)
self.assertEqual(response.status_code, 400)
def test_06_get_migration(self):
response = requests.get(blanks.MIGRATIONS_ENDPOINT)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()[1], 3)
def test_07_modify_migration(self):
response = requests.put(
blanks.MIGRATION_3_ENDPOINT,
json=blanks.MIGRATION_3_MODIFIED
)
self.assertEqual(response.status_code, 200)
response = requests.put(
blanks.MIGRATION_4_ENDPOINT,
json=blanks.MIGRATION_3_MODIFIED
)
self.assertEqual(response.status_code, 404)
response = requests.put(
blanks.MIGRATION_3_ENDPOINT,
json=blanks.MIGRATION_5
)
self.assertEqual(response.status_code, 400)
def test_08_run_migration(self):
response = requests.get(blanks.RUN_MIGRATION_1_ENDPOINT)
self.assertEqual(response.status_code, 200)
response = requests.get(blanks.RUN_MIGRATION_4_ENDPOINT)
self.assertEqual(response.status_code, 404)
def test_09_check_migration_status(self):
response = requests.get(blanks.MIGRATION_1_STATUS_ENDPOINT)
self.assertEqual(response.status_code, 200)
response = requests.get(blanks.MIGRATION_4_STATUS_ENDPOINT)
self.assertEqual(response.status_code, 404)
def test_10_delete_migration(self):
response = requests.delete(blanks.MIGRATION_3_ENDPOINT)
self.assertEqual(response.status_code, 200)
response = requests.delete(blanks.MIGRATION_4_ENDPOINT)
self.assertEqual(response.status_code, 404)
if __name__ == '__main__':
unittest.main()