blob: b12693b0392442fad30c70c29cf81afc3fa7506b [file] [log] [blame]
Patricia Reinoso911946d2023-04-12 15:54:43 +00001#######################################################################################
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 ModelInfo, NsInstantiateInput
20from osm_common.dbbase import DbException
21from osm_lcm.temporal.ns_activities import NsDbActivity
22from temporalio.testing import ActivityEnvironment
23from unittest.mock import Mock
24
25
26vim_id = "some-vim-uuid"
27ns_id = "0123456789-9876543210"
28nsr = {
29 "_id": ns_id,
30 "datacenter": vim_id,
31}
32input = NsInstantiateInput(ns_id, "op_id")
33expected_namespace = "9-9876543210-ome-vim-uuid"
34expected_model_info = ModelInfo(vim_id, expected_namespace)
35
36
37class TestGetModelInfo(asynctest.TestCase):
38 def setUp(self):
39 self.db = Mock()
40 self.env = ActivityEnvironment()
41 self.ns_db_activity = NsDbActivity(self.db)
42
43 async def test_nominal_case(self):
44 self.db.get_one.return_value = nsr
45 model_info = await self.env.run(self.ns_db_activity.get_model_info, input)
46 self.assertEqual(model_info, expected_model_info)
47
48 async def test_db_raises_exception(self):
49 self.db.get_one.side_effect = DbException("not found")
50 with self.assertRaises(DbException):
51 model_info = await self.env.run(self.ns_db_activity.get_model_info, input)
52 self.assertIsNone(model_info)
53
54 async def test_no_datacenter_raises_exception(self):
55 nsr = {"_id": ns_id}
56 self.db.get_one.return_value = nsr
57 with self.assertRaises(TypeError):
58 model_info = await self.env.run(self.ns_db_activity.get_model_info, input)
59 self.assertIsNone(model_info)