blob: 623f072c6a40b7ef387c16eea9247d6dd9cf200a [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
17
18from unittest.mock import Mock
19
20import asynctest
21from osm_common.dataclasses.temporal_dataclasses import GetVnfRecordIdsInput
22from osm_common.dbbase import DbException
23from temporalio.testing import ActivityEnvironment
24
25from osm_lcm.temporal.ns_activities import NsOperations
26
27ns_uuid = "00000000-0000-0000-0000-000000000000"
28get_vnf_record_ids_input = GetVnfRecordIdsInput(ns_uuid=ns_uuid)
29
30
31class TestGetModelInfo(asynctest.TestCase):
32 def setUp(self):
33 self.db = Mock()
34 self.env = ActivityEnvironment()
35 self.ns_operations_activity = NsOperations(self.db)
36
37 async def test_get_vnfr_ids(self):
38 self.db.get_list.return_value = [
39 {"id": "00000000-0000-0000-0000-000000000000"},
40 {"id": "00000000-0000-0000-0000-000000000000"},
41 ]
42 result = await self.env.run(
43 self.ns_operations_activity.get_vnf_record_ids, get_vnf_record_ids_input
44 )
45
46 assert result.vnfr_ids == [
47 "00000000-0000-0000-0000-000000000000",
48 "00000000-0000-0000-0000-000000000000",
49 ]
50
51 self.db.get_list.assert_called_with("vnfrs", {"nsr-id-ref": ns_uuid})
52
53 async def test_activity_raises_db_exception(self):
54 self.db.get_list.side_effect = DbException("not found")
55 with self.assertRaises(DbException):
56 await self.env.run(
57 self.ns_operations_activity.get_vnf_record_ids, get_vnf_record_ids_input
58 )