blob: 989a647cd6b7e7f8f43f26fa9901330b6e28847c [file] [log] [blame]
Dario Faccin39301762023-04-17 16:56:37 +02001#######################################################################################
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
18import asynctest
19from osm_common.dataclasses.temporal_dataclasses import VnfInstantiateInput
20from osm_common.dbbase import DbException
21from osm_lcm.temporal.vnf_activities import VnfDbActivity
22from temporalio.testing import ActivityEnvironment
23from unittest.mock import Mock
24
25
26vnfr_uuid = "d08d2da5-2120-476c-8538-deaeb4e88b3e"
27model_name = "a-model-name"
28vnf_instantiate_input = VnfInstantiateInput(vnfr_uuid=vnfr_uuid, model_name=model_name)
29
30
31class 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 )