This repository has been archived by the owner on Feb 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_osm.py
226 lines (177 loc) · 9.44 KB
/
test_osm.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!flask/bin/python
# Copyright 2019 CNIT, Francesco Lombardo, Matteo Pergolesi
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest
from urllib.parse import urlparse
from jsonschema import validate
from jsonschema.exceptions import ValidationError, SchemaError
from adaptation_layer import create_app
from .request_mock import mock_ns, mock_ns_scale
from .response_schemas import ns_lcm_op_occ_schema, ns_list_schema, ns_schema, \
ns_lcm_op_occ_list_schema
class OSMTestCase(unittest.TestCase):
client = None
@classmethod
def setUpClass(cls):
"""Define test variables and initialize app."""
cls.client = create_app().test_client
# Check status codes 201, 401, 404, headers and payload for create_ns()
def test_create_ns_201(self):
res = self.client().post('/nfvo/1/ns_instances?__code=201', json=mock_ns)
self.assertEqual(201, res.status_code)
self.assertIn('Location', res.headers)
validate_url = urlparse(res.headers["Location"])
self.assertTrue(all([validate_url.scheme, validate_url.netloc, validate_url.path]))
try:
validate(res.json, ns_schema)
except (ValidationError, SchemaError) as e:
self.fail(msg=e.message)
# Check status codes 201, 401, 404, headers and payload for create_ns()
def test_create_ns_201_with_vim(self):
mock_ns_vim = mock_ns.copy()
mock_ns_vim['vimAccountId'] = '76782dbd-eaa1-48ba-bdc7-a6cbbe5d4e2e'
res = self.client().post('/nfvo/1/ns_instances?__code=201', json=mock_ns_vim)
self.assertEqual(201, res.status_code)
self.assertIn('Location', res.headers)
validate_url = urlparse(res.headers["Location"])
self.assertTrue(all([validate_url.scheme, validate_url.netloc, validate_url.path]))
try:
validate(res.json, ns_schema)
except (ValidationError, SchemaError) as e:
self.fail(msg=e.message)
def test_create_ns_400(self):
res = self.client().post('/nfvo/1/ns_instances?__code=400', json=mock_ns)
self.assertEqual(400, res.status_code)
def test_create_ns_401(self):
res = self.client().post('/nfvo/1/ns_instances?__code=401', json=mock_ns)
self.assertEqual(401, res.status_code)
# Check status codes 200, 401, 404, headers and payload for get_ns_list()
def test_get_ns_list_200(self):
res = self.client().get('/nfvo/1/ns_instances?__code=200')
self.assertEqual(200, res.status_code)
try:
validate(res.json, ns_list_schema)
except (ValidationError, SchemaError) as e:
self.fail(msg=e.message)
def test_get_ns_list_401(self):
res = self.client().get('/nfvo/1/ns_instances?__code=401')
self.assertEqual(401, res.status_code)
# Check status codes 200, 401, 404, headers and payload for get_ns()
def test_get_ns_200(self):
res = self.client().get('/nfvo/1/ns_instances/49ccb6a2-5bcd-4f35-a2cf-7728c54e48b7?__code=200')
self.assertEqual(200, res.status_code)
try:
validate(res.json, ns_schema)
except (ValidationError, SchemaError) as e:
self.fail(msg=e.message)
def test_get_ns_404(self):
res = self.client().get('/nfvo/1/ns_instances/49ccb6a2-5bcd-4f35-a2cf-7728c54e48b7?__code=404')
self.assertEqual(404, res.status_code)
def test_get_ns_401(self):
res = self.client().get('/nfvo/1/ns_instances/49ccb6a2-5bcd-4f35-a2cf-7728c54e48b7?__code=401')
self.assertEqual(401, res.status_code)
# Check status codes 204, 401, 404, headers and payload for delete_ns()
def test_delete_ns_204(self):
res = self.client().delete('/nfvo/1/ns_instances/49ccb6a2-5bcd-4f35-a2cf-7728c54e48b7?__code=204')
self.assertEqual(204, res.status_code)
def test_delete_ns_404(self):
res = self.client().delete('/nfvo/1/ns_instances/49ccb6a2-5bcd-4f35-a2cf-7728c54e48b7?__code=404')
self.assertEqual(404, res.status_code)
def test_delete_ns_401(self):
res = self.client().delete('/nfvo/1/ns_instances/49ccb6a2-5bcd-4f35-a2cf-7728c54e48b7?__code=401')
self.assertEqual(401, res.status_code)
# Check status codes 202, 401, 404, headers and payload for instantiate_ns()
def test_instantiate_ns_202(self):
res = self.client().post('/nfvo/1/ns_instances/49ccb6a2-5bcd-4f35-a2cf-7728c54e48b7/instantiate?__code=202')
self.assertEqual(202, res.status_code)
self.assertIn('Location', res.headers)
validate_url = urlparse(res.headers["Location"])
self.assertTrue(all([validate_url.scheme, validate_url.netloc, validate_url.path]))
def test_instantiate_ns_400(self):
res = self.client().post('/nfvo/1/ns_instances/49ccb6a2-5bcd-4f35-a2cf-7728c54e48b7/instantiate?__code=400')
self.assertEqual(400, res.status_code)
def test_instantiate_ns_401(self):
res = self.client().post('/nfvo/1/ns_instances/49ccb6a2-5bcd-4f35-a2cf-7728c54e48b7/instantiate?__code=401')
self.assertEqual(401, res.status_code)
def test_instantiate_ns_404(self):
res = self.client().post('/nfvo/1/ns_instances/49ccb6a2-5bcd-4f35-a2cf-7728c54e48b7/instantiate?__code=404')
self.assertEqual(404, res.status_code)
# Check status codes 202, 401, 404, headers and payload for terminate_ns()
def test_terminate_ns_202(self):
res = self.client().post(
'/nfvo/1/ns_instances/49ccb6a2-5bcd-4f35-a2cf-7728c54e48b7/terminate?__code=202')
self.assertEqual(202, res.status_code)
self.assertIn('Location', res.headers)
validate_url = urlparse(res.headers["Location"])
self.assertTrue(
all([validate_url.scheme, validate_url.netloc, validate_url.path]))
def test_terminate_ns_404(self):
res = self.client().post(
'/nfvo/1/ns_instances/49ccb6a2-5bcd-4f35-a2cf-7728c54e48b7/terminate?__code=404')
self.assertEqual(404, res.status_code)
def test_terminate_ns_401(self):
res = self.client().post(
'/nfvo/1/ns_instances/49ccb6a2-5bcd-4f35-a2cf-7728c54e48b7/terminate?__code=401')
self.assertEqual(401, res.status_code)
# Check status codes 202, 401, 404, headers and payload for scale_ns()
def test_scale_ns_202(self):
res = self.client().post('/nfvo/1/ns_instances/49ccb6a2-5bcd-4f35-a2cf-7728c54e48b7/scale?__code=202',
json=mock_ns_scale)
self.assertEqual(202, res.status_code)
self.assertIn('Location', res.headers)
validate_url = urlparse(res.headers["Location"])
self.assertTrue(all([validate_url.scheme, validate_url.netloc, validate_url.path]))
def test_scale_ns_404(self):
res = self.client().post('/nfvo/1/ns_instances/49ccb6a2-5bcd-4f35-a2cf-7728c54e48b7/scale?__code=404',
json=mock_ns_scale)
self.assertEqual(404, res.status_code)
def test_scale_ns_401(self):
res = self.client().post('/nfvo/1/ns_instances/49ccb6a2-5bcd-4f35-a2cf-7728c54e48b7/scale?__code=401',
json=mock_ns_scale)
self.assertEqual(401, res.status_code)
# Check status codes 200, 401, headers and payload for get_ns_lcm_op_occs_list()
def test_get_ns_lcm_op_occs_list_200(self):
res = self.client().get('/nfvo/1/ns_lcm_op_occs?__code=200')
self.assertEqual(200, res.status_code)
try:
validate(res.json, ns_lcm_op_occ_list_schema)
except (ValidationError, SchemaError) as e:
self.fail(msg=e.message)
def test_get_ns_lcm_op_occs_list_200_filter(self):
res = self.client().get('/nfvo/1/ns_lcm_op_occs?nsInstanceId=1de0e9c3-b238-44da-b01b-b249a7784b03&__code=200')
self.assertEqual(200, res.status_code)
try:
validate(res.json, ns_lcm_op_occ_list_schema)
except (ValidationError, SchemaError) as e:
self.fail(msg=e.message)
def test_get_ns_lcm_op_occs_list_401(self):
res = self.client().get('/nfvo/1/ns_lcm_op_occs?__code=401')
self.assertEqual(401, res.status_code)
# Check status codes 200, 401, 404, headers and payload for get_ns_lcm_op_occs_()
def test_get_ns_lcm_op_occs_200(self):
res = self.client().get('/nfvo/1/ns_lcm_op_occs/49ccb6a2-5bcd-4f35-a2cf-7728c54c48b7?__code=200')
self.assertEqual(200, res.status_code)
try:
validate(res.json, ns_lcm_op_occ_schema)
except (ValidationError, SchemaError) as e:
self.fail(msg=e.message)
self.assertEqual(200, res.status_code)
def test_get_ns_lcm_op_occs_404(self):
res = self.client().get('/nfvo/1/ns_lcm_op_occs/49ccb6a2-5bcd-4f35-a2cf-7728c54c48b7?__code=404')
self.assertEqual(404, res.status_code)
def test_get_ns_lcm_op_occs_401(self):
res = self.client().get('/nfvo/1/ns_lcm_op_occs/49ccb6a2-5bcd-4f35-a2cf-7728c54c48b7?__code=401')
self.assertEqual(401, res.status_code)
if __name__ == '__main__':
unittest.main()