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.
17 from rest_framework.test import APIClient
18 from django.test import TestCase
19 from rest_framework import status
20 from lcm.pub.database.models import NSLcmOpOccModel
21 from lcm.ns.tests import OCCURRENCE_DICT, NSLCMOP_WITH_EXCLUDE_DEFAULT_DICT
24 class TestNSLcmOpOccs(TestCase):
26 self.client = APIClient()
27 self.multiple_ns_lcm_op = OCCURRENCE_DICT
28 self.single_ns_lcm_op = self.multiple_ns_lcm_op[0]
29 self.nslcmop_with_exclude_default = NSLCMOP_WITH_EXCLUDE_DEFAULT_DICT
30 NSLcmOpOccModel.objects.all().delete()
35 def test_get_nslcmopoccs(self):
36 lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
37 ns_instance_id = "cd552c9c-ab6f-11e8-b354-236c32aa91a1"
40 operation_state="STARTING",
41 state_entered_time="2019-01-01",
42 start_time="2019-01-01",
43 ns_instance_id=ns_instance_id,
45 is_automatic_invocation=False,
46 operation_params='{}',
47 is_cancel_pending=False,
50 resource_changes=None,
51 links=json.dumps({"self": {"href": "demo"}, "nsInstance": "demo"})).save()
52 response = self.client.get("/api/nslcm/v1/ns_lcm_op_occs", format='json')
53 self.assertEqual(response.status_code, status.HTTP_200_OK)
55 def test_get_nslcmopoccs_with_id_not_exist(self):
56 response = self.client.get("/api/nslcm/v1/ns_lcm_op_occs?id=dummy", format='json')
57 self.assertEqual(response.status_code, status.HTTP_200_OK)
59 def test_get_nslcmopoccs_with_filters(self):
60 lcm_op_id = "a6b9415c-ab99-11e8-9d37-dbb5e0378955"
61 ns_instance_id = "cd552c9c-ab6f-11e8-b354-236c32aa91a1"
64 operation_state="STARTING",
65 state_entered_time="2019-01-01",
66 start_time="2019-01-01",
67 ns_instance_id=ns_instance_id,
68 operation="INSTANTIATE",
69 is_automatic_invocation=False,
70 operation_params='{}',
71 is_cancel_pending=False,
74 resource_changes=None,
75 links=json.dumps({"self": {"href": "demo"}, "nsInstance": "demo"})).save()
76 lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
79 operation_state="STARTING",
80 state_entered_time="2019-01-01",
81 start_time="2019-01-01",
82 ns_instance_id=ns_instance_id,
84 is_automatic_invocation=False,
85 operation_params='{}',
86 is_cancel_pending=False,
89 resource_changes=None,
90 links=json.dumps({"self": {"href": "demo"}, "nsInstance": "demo"})).save()
91 response = self.client.get("/api/nslcm/v1/ns_lcm_op_occs", format='json')
92 self.assertEqual(response.status_code, status.HTTP_200_OK)
93 response = self.client.get("/api/nslcm/v1/ns_lcm_op_occs?operation=SCALE", format='json')
94 self.assertEqual(response.status_code, status.HTTP_200_OK)
95 response = self.client.get("/api/nslcm/v1/ns_lcm_op_occs?nsInstanceId=%s" % ns_instance_id, format='json')
96 self.assertEqual(response.status_code, status.HTTP_200_OK)
98 def test_get_nslcmopoccs_with_extra_flags(self):
99 lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
100 ns_instance_id = "cd552c9c-ab6f-11e8-b354-236c32aa91a1"
103 operation_state="STARTING",
104 state_entered_time="2019-01-01",
105 start_time="2019-01-01",
106 ns_instance_id=ns_instance_id,
108 is_automatic_invocation=False,
109 operation_params='{}',
110 is_cancel_pending=False,
113 resource_changes=None,
114 links=json.dumps({"self": {"href": "demo"}, "nsInstance": "demo"})).save()
115 response = self.client.get("/api/nslcm/v1/ns_lcm_op_occs?exclude_default", format='json')
116 self.assertEqual(response.status_code, status.HTTP_200_OK)
118 def test_get_nslcmopocc_with_id(self):
119 lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
120 ns_instance_id = "cd552c9c-ab6f-11e8-b354-236c32aa91a1"
123 operation_state="STARTING",
124 state_entered_time="2019-01-01",
125 start_time="2019-01-01",
126 ns_instance_id=ns_instance_id,
128 is_automatic_invocation=False,
129 operation_params='{}',
130 is_cancel_pending=False,
133 resource_changes=None,
134 links=json.dumps({"self": {"href": "demo"}, "nsInstance": "demo"})).save()
135 response = self.client.get("/api/nslcm/v1/ns_lcm_op_occs/" + lcm_op_id, format='json')
136 self.assertEqual(response.status_code, status.HTTP_200_OK)
137 self.assertEqual(self.single_ns_lcm_op['id'], response.data['id'])
139 def test_single_nslcmopocc_with_unknown_id(self):
140 lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
141 response = self.client.get("/api/nslcm/v1/ns_lcm_op_occs/" + lcm_op_id, format='json')
142 self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
145 "detail": "LCM Operation Occurance does not exist"
147 self.assertEqual(expected_data, response.data)