blob: 833f440c534a0e6e9d6f7a8475b64a7bdecbfd8a [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
Dario Faccinf5d65b52023-06-19 12:35:33 +020019from osm_lcm.temporal.ns_activities import GetNsRecordImpl, GetVnfDetailsImpl
Daniel Arndt0d2142a2023-04-20 17:14:58 -030020from osm_common.dbbase import DbException
21from temporalio.testing import ActivityEnvironment
Gulsum Atici50d12e02023-04-27 16:41:43 +030022from unittest.mock import Mock
Daniel Arndt0d2142a2023-04-20 17:14:58 -030023
24ns_uuid = "00000000-0000-0000-0000-000000000000"
Dario Faccinf5d65b52023-06-19 12:35:33 +020025get_vnf_details_input = GetVnfDetailsImpl.Input(ns_uuid=ns_uuid)
Gulsum Atici50d12e02023-04-27 16:41:43 +030026sample_vnf_details = [
27 {
28 "id": "00000000-0000-0000-0000-000000000000",
29 "member-vnf-index-ref": "vnf1",
30 },
31 {
32 "id": "00000000-0000-0000-0000-000000000000",
33 "member-vnf-index-ref": "vnf2",
34 },
35]
36sample_nsr = {
37 "_id": ns_uuid,
38 "name": "sol006_juju24",
39 "name-ref": "sol006_juju24",
40 "short-name": "sol006_juju24",
41 "admin-status": "ENABLED",
42 "nsState": "NOT_INSTANTIATED",
43 "currentOperation": "IDLE",
44}
Daniel Arndt0d2142a2023-04-20 17:14:58 -030045
46
Gulsum Atici50d12e02023-04-27 16:41:43 +030047class TestException(Exception):
48 pass
49
50
51class TestGetVnfDetails(asynctest.TestCase):
Daniel Arndt0d2142a2023-04-20 17:14:58 -030052 def setUp(self):
53 self.db = Mock()
54 self.env = ActivityEnvironment()
Dario Faccinf5d65b52023-06-19 12:35:33 +020055 self.get_vnf_details_impl = GetVnfDetailsImpl(self.db)
Daniel Arndt0d2142a2023-04-20 17:14:58 -030056
Gulsum Atici50d12e02023-04-27 16:41:43 +030057 async def test_activity__succeded__get_expected_result(self):
58 self.db.get_list.return_value = sample_vnf_details
Dario Faccinf5d65b52023-06-19 12:35:33 +020059 result = await self.env.run(self.get_vnf_details_impl, get_vnf_details_input)
Daniel Arndt0d2142a2023-04-20 17:14:58 -030060
Gulsum Atici50d12e02023-04-27 16:41:43 +030061 self.assertEqual(
62 result.vnf_details,
63 [
64 ("00000000-0000-0000-0000-000000000000", "vnf1"),
65 ("00000000-0000-0000-0000-000000000000", "vnf2"),
66 ],
67 )
Daniel Arndt0d2142a2023-04-20 17:14:58 -030068
Gulsum Atici50d12e02023-04-27 16:41:43 +030069 async def test_activity__failed__raise_db_exception(self):
70 self.db.get_list.side_effect = DbException("not found.")
Daniel Arndt0d2142a2023-04-20 17:14:58 -030071 with self.assertRaises(DbException):
Dario Faccinf5d65b52023-06-19 12:35:33 +020072 await self.env.run(self.get_vnf_details_impl, get_vnf_details_input)
Gulsum Atici50d12e02023-04-27 16:41:43 +030073
74
75class TestGetNsRecord(asynctest.TestCase):
76 async def setUp(self):
77 self.db = Mock()
78 self.env = ActivityEnvironment()
Dario Faccinf5d65b52023-06-19 12:35:33 +020079 self.get_ns_record_impl = GetNsRecordImpl(self.db)
Gulsum Atici50d12e02023-04-27 16:41:43 +030080
81 async def test_activity__succeeded__get_expected_result(self):
82 self.db.get_one.return_value = sample_nsr
83 activity_result = await self.env.run(
Dario Faccinf5d65b52023-06-19 12:35:33 +020084 self.get_ns_record_impl,
85 GetNsRecordImpl.Input(nsr_uuid=sample_nsr["_id"]),
Gulsum Atici50d12e02023-04-27 16:41:43 +030086 )
87 self.assertEqual(activity_result.nsr, sample_nsr)
88
89 async def test_activity__failed__raise_test_exception(self):
90 self.db.get_one.side_effect = TestException("Can not connect to Database.")
91 with self.assertRaises(TestException):
92 await self.env.run(
Dario Faccinf5d65b52023-06-19 12:35:33 +020093 self.get_ns_record_impl,
94 GetNsRecordImpl.Input(nsr_uuid=sample_nsr["_id"]),
Daniel Arndt0d2142a2023-04-20 17:14:58 -030095 )