| Dario Faccin | 3930176 | 2023-04-17 16:56:37 +0200 | [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 | import asynctest |
| 19 | from osm_common.dataclasses.temporal_dataclasses import VnfInstantiateInput |
| 20 | from osm_common.dbbase import DbException |
| 21 | from osm_lcm.temporal.vnf_activities import VnfDbActivity |
| 22 | from temporalio.testing import ActivityEnvironment |
| 23 | from unittest.mock import Mock |
| 24 | |
| 25 | |
| 26 | vnfr_uuid = "d08d2da5-2120-476c-8538-deaeb4e88b3e" |
| 27 | model_name = "a-model-name" |
| 28 | vnf_instantiate_input = VnfInstantiateInput(vnfr_uuid=vnfr_uuid, model_name=model_name) |
| 29 | |
| 30 | |
| 31 | class TestVnfDbActivity(asynctest.TestCase): |
| 32 | def setUp(self): |
| 33 | self.db = Mock() |
| 34 | self.env = ActivityEnvironment() |
| 35 | self.vnf_db_activity = VnfDbActivity(self.db) |
| 36 | |
| 37 | async def test_set_vnf_model(self): |
| 38 | await self.env.run(self.vnf_db_activity.set_vnf_model, vnf_instantiate_input) |
| 39 | self.db.set_one.assert_called_with( |
| 40 | "vnfrs", {"_id": vnfr_uuid}, {"namespace": model_name} |
| 41 | ) |
| 42 | |
| 43 | async def test_db_raises_exception(self): |
| 44 | self.db.set_one.side_effect = DbException("not found") |
| 45 | with self.assertRaises(DbException): |
| 46 | await self.env.run( |
| 47 | self.vnf_db_activity.set_vnf_model, vnf_instantiate_input |
| 48 | ) |