blob: c3176eee516ff86d5cc51ba6e341c952a832ea00 [file] [log] [blame]
Daniel Arndt0d2142a2023-04-20 17:14:58 -03001#######################################################################################
2# Copyright ETSI Contributors and Others.
3#
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
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
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
13# implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
Daniel Arndt0d2142a2023-04-20 17:14:58 -030017import asynctest
Gulsum Atici50d12e02023-04-27 16:41:43 +030018
19from osm_common.dataclasses.temporal_dataclasses import (
20 GetNsRecordInput,
21 GetVnfDetailsInput,
22)
Daniel Arndt0d2142a2023-04-20 17:14:58 -030023from osm_common.dbbase import DbException
24from temporalio.testing import ActivityEnvironment
Daniel Arndt0d2142a2023-04-20 17:14:58 -030025from osm_lcm.temporal.ns_activities import NsOperations
Gulsum Atici50d12e02023-04-27 16:41:43 +030026from unittest.mock import Mock
Daniel Arndt0d2142a2023-04-20 17:14:58 -030027
28ns_uuid = "00000000-0000-0000-0000-000000000000"
Gulsum Atici50d12e02023-04-27 16:41:43 +030029get_vnf_details_input = GetVnfDetailsInput(ns_uuid=ns_uuid)
30sample_vnf_details = [
31 {
32 "id": "00000000-0000-0000-0000-000000000000",
33 "member-vnf-index-ref": "vnf1",
34 },
35 {
36 "id": "00000000-0000-0000-0000-000000000000",
37 "member-vnf-index-ref": "vnf2",
38 },
39]
40sample_nsr = {
41 "_id": ns_uuid,
42 "name": "sol006_juju24",
43 "name-ref": "sol006_juju24",
44 "short-name": "sol006_juju24",
45 "admin-status": "ENABLED",
46 "nsState": "NOT_INSTANTIATED",
47 "currentOperation": "IDLE",
48}
Daniel Arndt0d2142a2023-04-20 17:14:58 -030049
50
Gulsum Atici50d12e02023-04-27 16:41:43 +030051class TestException(Exception):
52 pass
53
54
55class TestGetVnfDetails(asynctest.TestCase):
Daniel Arndt0d2142a2023-04-20 17:14:58 -030056 def setUp(self):
57 self.db = Mock()
58 self.env = ActivityEnvironment()
59 self.ns_operations_activity = NsOperations(self.db)
60
Gulsum Atici50d12e02023-04-27 16:41:43 +030061 async def test_activity__succeded__get_expected_result(self):
62 self.db.get_list.return_value = sample_vnf_details
Daniel Arndt0d2142a2023-04-20 17:14:58 -030063 result = await self.env.run(
Gulsum Atici50d12e02023-04-27 16:41:43 +030064 self.ns_operations_activity.get_vnf_details, get_vnf_details_input
Daniel Arndt0d2142a2023-04-20 17:14:58 -030065 )
66
Gulsum Atici50d12e02023-04-27 16:41:43 +030067 self.assertEqual(
68 result.vnf_details,
69 [
70 ("00000000-0000-0000-0000-000000000000", "vnf1"),
71 ("00000000-0000-0000-0000-000000000000", "vnf2"),
72 ],
73 )
Daniel Arndt0d2142a2023-04-20 17:14:58 -030074
Gulsum Atici50d12e02023-04-27 16:41:43 +030075 async def test_activity__failed__raise_db_exception(self):
76 self.db.get_list.side_effect = DbException("not found.")
Daniel Arndt0d2142a2023-04-20 17:14:58 -030077 with self.assertRaises(DbException):
78 await self.env.run(
Gulsum Atici50d12e02023-04-27 16:41:43 +030079 self.ns_operations_activity.get_vnf_details, get_vnf_details_input
80 )
81
82
83class TestGetNsRecord(asynctest.TestCase):
84 async def setUp(self):
85 self.db = Mock()
86 self.env = ActivityEnvironment()
87 self.ns_operations_activity = NsOperations(self.db)
88
89 async def test_activity__succeeded__get_expected_result(self):
90 self.db.get_one.return_value = sample_nsr
91 activity_result = await self.env.run(
92 self.ns_operations_activity.get_ns_record,
93 GetNsRecordInput(nsr_uuid=sample_nsr["_id"]),
94 )
95 self.assertEqual(activity_result.nsr, sample_nsr)
96
97 async def test_activity__failed__raise_test_exception(self):
98 self.db.get_one.side_effect = TestException("Can not connect to Database.")
99 with self.assertRaises(TestException):
100 await self.env.run(
101 self.ns_operations_activity.get_ns_record,
102 GetNsRecordInput(nsr_uuid=sample_nsr["_id"]),
Daniel Arndt0d2142a2023-04-20 17:14:58 -0300103 )