| Daniel Arndt | 0d2142a | 2023-04-20 17:14:58 -0300 | [diff] [blame] | 1 | ####################################################################################### |
| 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 | |
| 18 | from unittest.mock import Mock |
| 19 | |
| 20 | import asynctest |
| 21 | from osm_common.dataclasses.temporal_dataclasses import GetVnfRecordIdsInput |
| 22 | from osm_common.dbbase import DbException |
| 23 | from temporalio.testing import ActivityEnvironment |
| 24 | |
| 25 | from osm_lcm.temporal.ns_activities import NsOperations |
| 26 | |
| 27 | ns_uuid = "00000000-0000-0000-0000-000000000000" |
| 28 | get_vnf_record_ids_input = GetVnfRecordIdsInput(ns_uuid=ns_uuid) |
| 29 | |
| 30 | |
| 31 | class 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 | ) |