efiacor | 0080fa4 | 2020-09-08 16:26:50 +0100 | [diff] [blame] | 1 | # ============LICENSE_START=================================================== |
ajay_dp001 | 053579b | 2021-08-25 13:53:27 +0530 | [diff] [blame] | 2 | # Copyright (C) 2020-2021 Nordix Foundation. |
efiacor | 0080fa4 | 2020-09-08 16:26:50 +0100 | [diff] [blame] | 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 implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | # SPDX-License-Identifier: Apache-2.0 |
| 17 | # ============LICENSE_END===================================================== |
raviteja.karumuri | 86f4eb2 | 2021-11-09 17:30:03 +0000 | [diff] [blame^] | 18 | import copy |
efiacor | 0080fa4 | 2020-09-08 16:26:50 +0100 | [diff] [blame] | 19 | import json |
| 20 | import os |
| 21 | from unittest import TestCase |
| 22 | from unittest.mock import patch, MagicMock |
| 23 | |
| 24 | from mod import create_app, db |
raviteja.karumuri | 86f4eb2 | 2021-11-09 17:30:03 +0000 | [diff] [blame^] | 25 | from mod.api.db_models import NetworkFunctionFilterModel, MeasurementGroupModel, SubscriptionModel |
shivasubedi | 9aa0b66 | 2021-01-18 13:59:18 +0000 | [diff] [blame] | 26 | from mod.network_function import NetworkFunctionFilter |
efiacor | 0080fa4 | 2020-09-08 16:26:50 +0100 | [diff] [blame] | 27 | from mod.pmsh_utils import AppConfig |
ajay_dp001 | 053579b | 2021-08-25 13:53:27 +0530 | [diff] [blame] | 28 | from mod.pmsh_config import AppConfig as NewAppConfig |
efiacor | 0080fa4 | 2020-09-08 16:26:50 +0100 | [diff] [blame] | 29 | |
| 30 | |
shivasubedi | 9aa0b66 | 2021-01-18 13:59:18 +0000 | [diff] [blame] | 31 | def get_pmsh_config(file_path='data/cbs_data_1.json'): |
| 32 | with open(os.path.join(os.path.dirname(__file__), file_path), 'r') as data: |
efiacor | 0080fa4 | 2020-09-08 16:26:50 +0100 | [diff] [blame] | 33 | return json.load(data) |
| 34 | |
| 35 | |
raviteja.karumuri | 86f4eb2 | 2021-11-09 17:30:03 +0000 | [diff] [blame^] | 36 | def subscription_data(subscription_name): |
| 37 | nf_filter = NetworkFunctionFilterModel(subscription_name, '{^pnf.*,^vnf.*}', |
| 38 | '{}', '{}', '{}') |
| 39 | mg_first = MeasurementGroupModel(subscription_name, 'MG1', 'UNLOCKED', 15, '/pm/pm.xml', |
| 40 | '[{ "measurementType": "countera" }, ' |
| 41 | '{ "measurementType": "counterb" }]', |
| 42 | '[{ "DN":"dna"},{"DN":"dnb"}]') |
| 43 | mg_second = copy.deepcopy(mg_first) |
| 44 | mg_second.measurement_group_name = 'MG2' |
| 45 | mg_second.administrative_state = 'LOCKED' |
| 46 | mg_list = [mg_first, mg_second] |
| 47 | subscription_model = SubscriptionModel(subscription_name, 'pmsh_operational_policy', |
| 48 | 'pmsh_control_loop_name', 'LOCKED') |
| 49 | subscription_model.network_filter = nf_filter |
| 50 | subscription_model.measurement_groups = mg_list |
| 51 | return subscription_model |
| 52 | |
| 53 | |
efiacor | 0080fa4 | 2020-09-08 16:26:50 +0100 | [diff] [blame] | 54 | class BaseClassSetup(TestCase): |
| 55 | app = None |
| 56 | app_context = None |
| 57 | |
| 58 | @classmethod |
| 59 | @patch('mod.get_db_connection_url', MagicMock(return_value='sqlite://')) |
| 60 | @patch('mod.update_logging_config', MagicMock()) |
| 61 | def setUpClass(cls): |
| 62 | os.environ['LOGGER_CONFIG'] = os.path.join(os.path.dirname(__file__), 'log_config.yaml') |
| 63 | os.environ['LOGS_PATH'] = '.' |
| 64 | cls.app = create_app() |
| 65 | cls.app_context = cls.app.app_context() |
| 66 | cls.app_context.push() |
| 67 | |
| 68 | @patch('mod.pmsh_utils.AppConfig._get_pmsh_config', MagicMock(return_value=get_pmsh_config())) |
| 69 | def setUp(self): |
| 70 | os.environ['AAI_SERVICE_PORT'] = '8443' |
| 71 | db.create_all() |
| 72 | self.app_conf = AppConfig() |
shivasubedi | 9aa0b66 | 2021-01-18 13:59:18 +0000 | [diff] [blame] | 73 | self.app_conf.nf_filter = NetworkFunctionFilter(**self.app_conf.subscription.nfFilter) |
efiacor | 0080fa4 | 2020-09-08 16:26:50 +0100 | [diff] [blame] | 74 | |
ajay_dp001 | 053579b | 2021-08-25 13:53:27 +0530 | [diff] [blame] | 75 | @patch('mod.pmsh_config.AppConfig._get_config', MagicMock(return_value=get_pmsh_config())) |
| 76 | def setUpAppConf(self): |
| 77 | self.pmsh_app_conf = NewAppConfig() |
| 78 | |
efiacor | 0080fa4 | 2020-09-08 16:26:50 +0100 | [diff] [blame] | 79 | def tearDown(self): |
| 80 | db.drop_all() |
| 81 | |
| 82 | @classmethod |
| 83 | def tearDownClass(cls): |
| 84 | db.session.remove() |