1 # -------------------------------------------------------------------------
2 # Copyright (C) 2020 Wipro Limited.
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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 implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # -------------------------------------------------------------------------
20 from mock import patch
22 from apps.pci.optimizers.solver.ml_model import MlModel
23 from osdf.adapters.dcae.des import DESException
24 import osdf.config.loader as config_loader
25 from osdf.utils.interfaces import json_from_file
26 from osdf.utils.programming_utils import DotDict
29 class TestMlModel(unittest.TestCase):
32 "deployment": "config/osdf_config.yaml",
33 "core": "config/common_config.yaml"
35 self.osdf_config = DotDict(config_loader.all_configs(**self.config_spec))
40 def test_ml_model(self):
41 des_result_file = 'test/apps/pci_optimization/des_result.json'
42 results = json_from_file(des_result_file)
49 'NUM_SECOND_LEVEL_NEIGHBORS': 1,
50 'SECOND_LEVEL_NEIGHBORS': [],
51 'PCI_UNCHANGEABLE_CELLS': [],
69 self.patcher_req = patch('osdf.adapters.dcae.des.extract_data', side_effect=results)
70 self.Mock_req = self.patcher_req.start()
72 mlmodel.get_additional_inputs(dzn_data, network_cell_info)
73 self.assertEqual(['Chn0001'], dzn_data['PCI_UNCHANGEABLE_CELLS'])
74 self.patcher_req.stop()
76 dzn_data['PCI_UNCHANGEABLE_CELLS'] = []
77 self.patcher_req = patch('osdf.adapters.dcae.des.extract_data', side_effect=DESException('error'))
78 self.Mock_req = self.patcher_req.start()
79 mlmodel.get_additional_inputs(dzn_data, network_cell_info)
80 self.assertEqual([], dzn_data['PCI_UNCHANGEABLE_CELLS'])
81 self.patcher_req.stop()
83 self.patcher_req = patch('osdf.adapters.dcae.des.extract_data', return_value=[])
84 self.Mock_req = self.patcher_req.start()
85 mlmodel.get_additional_inputs(dzn_data, network_cell_info)
86 self.assertEqual([], dzn_data['PCI_UNCHANGEABLE_CELLS'])
87 self.patcher_req.stop()