1 # Copyright (C) 2018 Verizon. All Rights Reserved
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
18 from django.test import TestCase, Client
19 from rest_framework import status
21 from lcm.pub.database.models import VNFLcmOpOccModel
22 from .const import single_vnf_lcm_op
23 from .const import vnflcmop_with_exclude_default
24 from .const import multiple_vnf_lcm_op
27 class TestVNFLcmOpOccs(TestCase):
29 self.client = Client()
30 self.vnf_lcm_op_occ_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
31 VNFLcmOpOccModel.objects.all().delete()
32 self.test_single_vnf_lcm_op = single_vnf_lcm_op
33 self.test_vnflcmop_with_exclude_default = vnflcmop_with_exclude_default
34 self.test_multiple_vnf_lcm_op = copy.copy(multiple_vnf_lcm_op)
35 self.test_multiple_vnf_lcm_op.append(self.test_single_vnf_lcm_op)
40 def test_get_vnflcmopoccs(self):
41 lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
42 vnf_instance_id = "cd552c9c-ab6f-11e8-b354-236c32aa91a1"
45 operation_state="STARTING",
46 state_entered_time="2018-07-09",
47 start_time="2018-07-09",
48 vnf_instance_id=vnf_instance_id,
51 is_automatic_invocation=False,
52 operation_params='{}',
53 is_cancel_pending=False,
56 resource_changes=None,
57 changed_ext_connectivity=None,
64 response = self.client.get(
65 "/api/vnflcm/v1/vnf_lcm_op_occs",
73 [self.test_single_vnf_lcm_op],
77 def test_get_vnflcmopoccs_with_id_not_exist(self):
78 response = self.client.get(
79 "/api/vnflcm/v1/vnf_lcm_op_occs?id=dummy",
84 status.HTTP_500_INTERNAL_SERVER_ERROR
88 "detail": "LCM Operation Occurances do not exist"
95 def test_get_vnflcmopoccs_with_filters(self):
96 lcm_op_id = "a6b9415c-ab99-11e8-9d37-dbb5e0378955"
97 vnf_instance_id = "cd552c9c-ab6f-11e8-b354-236c32aa91a1"
100 operation_state="STARTING",
101 state_entered_time="2018-07-09",
102 start_time="2018-07-09",
103 vnf_instance_id=vnf_instance_id,
105 operation="INSTANTIATE",
106 is_automatic_invocation=False,
107 operation_params='{}',
108 is_cancel_pending=False,
111 resource_changes=None,
112 changed_ext_connectivity=None,
117 "vnfInstance": "demo"
120 lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
123 operation_state="STARTING",
124 state_entered_time="2018-07-09",
125 start_time="2018-07-09",
126 vnf_instance_id=vnf_instance_id,
129 is_automatic_invocation=False,
130 operation_params='{}',
131 is_cancel_pending=False,
134 resource_changes=None,
135 changed_ext_connectivity=None,
140 "vnfInstance": "demo"
142 response = self.client.get(
143 "/api/vnflcm/v1/vnf_lcm_op_occs",
147 response.status_code,
151 self.test_multiple_vnf_lcm_op,
156 response = self.client.get(
157 "/api/vnflcm/v1/vnf_lcm_op_occs?operation=SCALE",
161 response.status_code,
165 [self.test_single_vnf_lcm_op],
169 response = self.client.get(
170 "/api/vnflcm/v1/vnf_lcm_op_occs?vnfInstanceId=%s" % vnf_instance_id,
174 response.status_code,
178 self.test_multiple_vnf_lcm_op,
182 def test_get_vnflcmopoccs_with_extra_flags(self):
183 lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
184 vnf_instance_id = "cd552c9c-ab6f-11e8-b354-236c32aa91a1"
187 operation_state="STARTING",
188 state_entered_time="2018-07-09",
189 start_time="2018-07-09",
190 vnf_instance_id=vnf_instance_id,
193 is_automatic_invocation=False,
194 operation_params='{}',
195 is_cancel_pending=False,
198 resource_changes=None,
199 changed_ext_connectivity=None,
204 "vnfInstance": "demo"
206 response = self.client.get(
207 "/api/vnflcm/v1/vnf_lcm_op_occs?exclude_default",
211 response.status_code,
215 self.test_vnflcmop_with_exclude_default,
219 def test_get_vnflcmopocc_with_id(self):
220 lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
221 vnf_instance_id = "cd552c9c-ab6f-11e8-b354-236c32aa91a1"
224 operation_state="STARTING",
225 state_entered_time="2018-07-09",
226 start_time="2018-07-09",
227 vnf_instance_id=vnf_instance_id,
230 is_automatic_invocation=False,
231 operation_params='{}',
232 is_cancel_pending=False,
235 resource_changes=None,
236 changed_ext_connectivity=None,
241 "vnfInstance": "demo"
243 response = self.client.get(
244 "/api/vnflcm/v1/vnf_lcm_op_occs/%s" % lcm_op_id,
248 response.status_code,
252 self.test_single_vnf_lcm_op,
256 def test_single_vnflcmopocc_with_unknown_id(self):
257 lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
258 response = self.client.get(
259 "/api/vnflcm/v1/vnf_lcm_op_occs/%s" % lcm_op_id,
263 response.status_code,
264 status.HTTP_500_INTERNAL_SERVER_ERROR
268 "detail": "LCM Operation Occurance does not exist"