1 # Copyright (c) 2019, CMCC Technologies Co., Ltd.
2 # Copyright (c) 2019 ZTE Corporation.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
18 from rest_framework.test import APIClient
19 from django.test import TestCase
20 from rest_framework import status
21 from lcm.pub.database.models import NSLcmOpOccModel
22 from lcm.pub.utils import fileutil
25 class TestNSLcmOpOccs(TestCase):
27 self.client = APIClient()
28 self.cur_path = os.path.dirname(os.path.abspath(__file__))
29 self.multiple_ns_lcm_op = fileutil.read_json_file(self.cur_path + '/data/occurrence.json')
30 self.single_ns_lcm_op = self.multiple_ns_lcm_op[0]
31 self.nslcmop_with_exclude_default = fileutil.read_json_file(self.cur_path + '/data/occurrence_exclude_default.json')
32 NSLcmOpOccModel.objects.all().delete()
37 def test_get_nslcmopoccs(self):
38 lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
39 ns_instance_id = "cd552c9c-ab6f-11e8-b354-236c32aa91a1"
42 operation_state="STARTING",
43 state_entered_time="2019-01-01",
44 start_time="2019-01-01",
45 ns_instance_id=ns_instance_id,
47 is_automatic_invocation=False,
48 operation_params='{}',
49 is_cancel_pending=False,
52 resource_changes=None,
53 links=json.dumps({"self": {"href": "demo"}, "nsInstance": "demo"})).save()
54 response = self.client.get("/api/nslcm/v1/ns_lcm_op_occs", format='json')
55 self.assertEqual(response.status_code, status.HTTP_200_OK)
57 def test_get_nslcmopoccs_with_id_not_exist(self):
58 response = self.client.get("/api/nslcm/v1/ns_lcm_op_occs?id=dummy", format='json')
59 self.assertEqual(response.status_code, status.HTTP_200_OK)
61 def test_get_nslcmopoccs_with_filters(self):
62 lcm_op_id = "a6b9415c-ab99-11e8-9d37-dbb5e0378955"
63 ns_instance_id = "cd552c9c-ab6f-11e8-b354-236c32aa91a1"
66 operation_state="STARTING",
67 state_entered_time="2019-01-01",
68 start_time="2019-01-01",
69 ns_instance_id=ns_instance_id,
70 operation="INSTANTIATE",
71 is_automatic_invocation=False,
72 operation_params='{}',
73 is_cancel_pending=False,
76 resource_changes=None,
77 links=json.dumps({"self": {"href": "demo"}, "nsInstance": "demo"})).save()
78 lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
81 operation_state="STARTING",
82 state_entered_time="2019-01-01",
83 start_time="2019-01-01",
84 ns_instance_id=ns_instance_id,
86 is_automatic_invocation=False,
87 operation_params='{}',
88 is_cancel_pending=False,
91 resource_changes=None,
92 links=json.dumps({"self": {"href": "demo"}, "nsInstance": "demo"})).save()
93 response = self.client.get("/api/nslcm/v1/ns_lcm_op_occs", format='json')
94 self.assertEqual(response.status_code, status.HTTP_200_OK)
95 response = self.client.get("/api/nslcm/v1/ns_lcm_op_occs?operation=SCALE", format='json')
96 self.assertEqual(response.status_code, status.HTTP_200_OK)
97 response = self.client.get("/api/nslcm/v1/ns_lcm_op_occs?nsInstanceId=%s" % ns_instance_id, format='json')
98 self.assertEqual(response.status_code, status.HTTP_200_OK)
100 def test_get_nslcmopoccs_with_extra_flags(self):
101 lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
102 ns_instance_id = "cd552c9c-ab6f-11e8-b354-236c32aa91a1"
105 operation_state="STARTING",
106 state_entered_time="2019-01-01",
107 start_time="2019-01-01",
108 ns_instance_id=ns_instance_id,
110 is_automatic_invocation=False,
111 operation_params='{}',
112 is_cancel_pending=False,
115 resource_changes=None,
116 links=json.dumps({"self": {"href": "demo"}, "nsInstance": "demo"})).save()
117 response = self.client.get("/api/nslcm/v1/ns_lcm_op_occs?exclude_default", format='json')
118 self.assertEqual(response.status_code, status.HTTP_200_OK)
120 def test_get_nslcmopocc_with_id(self):
121 lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
122 ns_instance_id = "cd552c9c-ab6f-11e8-b354-236c32aa91a1"
125 operation_state="STARTING",
126 state_entered_time="2019-01-01",
127 start_time="2019-01-01",
128 ns_instance_id=ns_instance_id,
130 is_automatic_invocation=False,
131 operation_params='{}',
132 is_cancel_pending=False,
135 resource_changes=None,
136 links=json.dumps({"self": {"href": "demo"}, "nsInstance": "demo"})).save()
137 response = self.client.get("/api/nslcm/v1/ns_lcm_op_occs/" + lcm_op_id, format='json')
138 self.assertEqual(response.status_code, status.HTTP_200_OK)
139 self.assertEqual(self.single_ns_lcm_op['id'], response.data['id'])
141 def test_single_nslcmopocc_with_unknown_id(self):
142 lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
143 response = self.client.get("/api/nslcm/v1/ns_lcm_op_occs/" + lcm_op_id, format='json')
144 self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
147 "detail": "LCM Operation Occurance does not exist"
149 self.assertEqual(expected_data, response.data)