| ####################################################################################### |
| # Copyright ETSI Contributors and Others. |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| # implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| |
| from unittest.mock import Mock |
| |
| import asynctest |
| from osm_common.dataclasses.temporal_dataclasses import GetVnfRecordIdsInput |
| from osm_common.dbbase import DbException |
| from temporalio.testing import ActivityEnvironment |
| |
| from osm_lcm.temporal.ns_activities import NsOperations |
| |
| ns_uuid = "00000000-0000-0000-0000-000000000000" |
| get_vnf_record_ids_input = GetVnfRecordIdsInput(ns_uuid=ns_uuid) |
| |
| |
| class TestGetModelInfo(asynctest.TestCase): |
| def setUp(self): |
| self.db = Mock() |
| self.env = ActivityEnvironment() |
| self.ns_operations_activity = NsOperations(self.db) |
| |
| async def test_get_vnfr_ids(self): |
| self.db.get_list.return_value = [ |
| {"id": "00000000-0000-0000-0000-000000000000"}, |
| {"id": "00000000-0000-0000-0000-000000000000"}, |
| ] |
| result = await self.env.run( |
| self.ns_operations_activity.get_vnf_record_ids, get_vnf_record_ids_input |
| ) |
| |
| assert result.vnfr_ids == [ |
| "00000000-0000-0000-0000-000000000000", |
| "00000000-0000-0000-0000-000000000000", |
| ] |
| |
| self.db.get_list.assert_called_with("vnfrs", {"nsr-id-ref": ns_uuid}) |
| |
| async def test_activity_raises_db_exception(self): |
| self.db.get_list.side_effect = DbException("not found") |
| with self.assertRaises(DbException): |
| await self.env.run( |
| self.ns_operations_activity.get_vnf_record_ids, get_vnf_record_ids_input |
| ) |