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.
17 from django.test import TestCase, Client
18 from rest_framework import status
20 from lcm.pub.database.models import VNFLcmOpOccModel
23 class TestVNFLcmOpOccs(TestCase):
25 self.client = Client()
26 self.vnf_lcm_op_occ_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
27 VNFLcmOpOccModel.objects.all().delete()
28 self.test_single_vnf_lcm_op = [{
29 "id": "99442b18-a5c7-11e8-998c-bf1755941f16",
30 "operationState": "STARTING",
31 "stateEnteredTime": "2018-07-09",
32 "startTime": "2018-07-09",
33 "vnfInstanceId": "cd552c9c-ab6f-11e8-b354-236c32aa91a1",
36 "isAutomaticInvocation": False,
37 "operationParams": {},
38 "isCancelPending": False,
41 "resourceChanges": None,
43 "changedExtConnectivity": None,
49 self.test_vnflcmop_with_exclude_default = [{
50 "id": "99442b18-a5c7-11e8-998c-bf1755941f16",
51 "operationState": "STARTING",
52 "stateEnteredTime": "2018-07-09",
53 "startTime": "2018-07-09",
54 "vnfInstanceId": "cd552c9c-ab6f-11e8-b354-236c32aa91a1",
57 "isAutomaticInvocation": False,
58 "isCancelPending": False,
66 self.test_multiple_vnf_lcm_op = [{
67 "id": "a6b9415c-ab99-11e8-9d37-dbb5e0378955",
68 "operationState": "STARTING",
69 "stateEnteredTime": "2018-07-09",
70 "startTime": "2018-07-09",
71 "vnfInstanceId": "cd552c9c-ab6f-11e8-b354-236c32aa91a1",
73 "operation": "INSTANTIATE",
74 "isAutomaticInvocation": False,
75 "operationParams": {},
76 "isCancelPending": False,
79 "resourceChanges": None,
81 "changedExtConnectivity": None,
87 self.test_multiple_vnf_lcm_op.append(
88 self.test_single_vnf_lcm_op[0])
93 def test_get_vnflcmopocc(self):
94 lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
95 vnf_instance_id = "cd552c9c-ab6f-11e8-b354-236c32aa91a1"
96 VNFLcmOpOccModel(id=lcm_op_id, operation_state="STARTING",
97 state_entered_time="2018-07-09", start_time="2018-07-09",
98 vnf_instance_id=vnf_instance_id,
99 grant_id=None, operation="SCALE", is_automatic_invocation=False,
100 operation_params='{}', is_cancel_pending=False, cancel_mode=None,
101 error=None, resource_changes=None, changed_ext_connectivity=None,
102 links=json.dumps({"self": "demo", "vnfInstance": "demo"})).save()
103 response = self.client.get("/api/vnflcm/v1/vnf_lcm_op_occs", format='json')
104 self.assertEqual(response.status_code, status.HTTP_200_OK)
105 self.assertEqual(self.test_single_vnf_lcm_op, response.data)
107 def test_get_vnflcmopocc_with_id_not_exist(self):
108 response = self.client.get("/api/vnflcm/v1/vnf_lcm_op_occs?id=dummy", format='json')
109 self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
112 "detail": "LCM Operation Occurances do not exist"
114 self.assertEqual(expected_data, response.data)
116 def test_get_vnflcmopocc_with_filters(self):
117 lcm_op_id = "a6b9415c-ab99-11e8-9d37-dbb5e0378955"
118 vnf_instance_id = "cd552c9c-ab6f-11e8-b354-236c32aa91a1"
119 VNFLcmOpOccModel(id=lcm_op_id, operation_state="STARTING",
120 state_entered_time="2018-07-09", start_time="2018-07-09",
121 vnf_instance_id=vnf_instance_id,
122 grant_id=None, operation="INSTANTIATE", is_automatic_invocation=False,
123 operation_params='{}', is_cancel_pending=False, cancel_mode=None,
124 error=None, resource_changes=None, changed_ext_connectivity=None,
125 links=json.dumps({"self": "demo", "vnfInstance": "demo"})).save()
127 lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
128 VNFLcmOpOccModel(id=lcm_op_id, operation_state="STARTING",
129 state_entered_time="2018-07-09", start_time="2018-07-09",
130 vnf_instance_id=vnf_instance_id,
131 grant_id=None, operation="SCALE", is_automatic_invocation=False,
132 operation_params='{}', is_cancel_pending=False, cancel_mode=None,
133 error=None, resource_changes=None, changed_ext_connectivity=None,
134 links=json.dumps({"self": "demo", "vnfInstance": "demo"})).save()
135 response = self.client.get("/api/vnflcm/v1/vnf_lcm_op_occs", format='json')
136 self.assertEqual(response.status_code, status.HTTP_200_OK)
137 self.assertEqual(self.test_multiple_vnf_lcm_op, response.data)
139 response = self.client.get("/api/vnflcm/v1/vnf_lcm_op_occs?operation=SCALE", format='json')
140 self.assertEqual(response.status_code, status.HTTP_200_OK)
141 self.assertEqual(self.test_single_vnf_lcm_op, response.data)
143 response = self.client.get("/api/vnflcm/v1/vnf_lcm_op_occs?vnfInstanceId=%s" % vnf_instance_id, format='json')
144 self.assertEqual(response.status_code, status.HTTP_200_OK)
145 self.assertEqual(self.test_multiple_vnf_lcm_op, response.data)
147 def test_get_vnflcmopocc_with_extra_flags(self):
148 lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
149 vnf_instance_id = "cd552c9c-ab6f-11e8-b354-236c32aa91a1"
150 VNFLcmOpOccModel(id=lcm_op_id, operation_state="STARTING",
151 state_entered_time="2018-07-09", start_time="2018-07-09",
152 vnf_instance_id=vnf_instance_id,
153 grant_id=None, operation="SCALE", is_automatic_invocation=False,
154 operation_params='{}', is_cancel_pending=False, cancel_mode=None,
155 error=None, resource_changes=None, changed_ext_connectivity=None,
156 links=json.dumps({"self": "demo", "vnfInstance": "demo"})).save()
157 response = self.client.get("/api/vnflcm/v1/vnf_lcm_op_occs?exclude_default", format='json')
158 self.assertEqual(response.status_code, status.HTTP_200_OK)
159 self.assertEqual(self.test_vnflcmop_with_exclude_default, response.data)