blob: 4328f59c5ea34e15ed9413054aa27d20074903f5 [file] [log] [blame]
efiacor0080fa42020-09-08 16:26:50 +01001# ============LICENSE_START===================================================
ajay_dp001053579b2021-08-25 13:53:27 +05302# Copyright (C) 2020-2021 Nordix Foundation.
efiacor0080fa42020-09-08 16:26:50 +01003# ============================================================================
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.karumuri86f4eb22021-11-09 17:30:03 +000018import copy
efiacor0080fa42020-09-08 16:26:50 +010019import json
20import os
21from unittest import TestCase
22from unittest.mock import patch, MagicMock
23
24from mod import create_app, db
raviteja.karumuri86f4eb22021-11-09 17:30:03 +000025from mod.api.db_models import NetworkFunctionFilterModel, MeasurementGroupModel, SubscriptionModel
shivasubedi9aa0b662021-01-18 13:59:18 +000026from mod.network_function import NetworkFunctionFilter
efiacor0080fa42020-09-08 16:26:50 +010027from mod.pmsh_utils import AppConfig
ajay_dp001053579b2021-08-25 13:53:27 +053028from mod.pmsh_config import AppConfig as NewAppConfig
efiacor0080fa42020-09-08 16:26:50 +010029
30
shivasubedi9aa0b662021-01-18 13:59:18 +000031def 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:
efiacor0080fa42020-09-08 16:26:50 +010033 return json.load(data)
34
35
raviteja.karumuri86f4eb22021-11-09 17:30:03 +000036def 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
efiacor0080fa42020-09-08 16:26:50 +010054class 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()
shivasubedi9aa0b662021-01-18 13:59:18 +000073 self.app_conf.nf_filter = NetworkFunctionFilter(**self.app_conf.subscription.nfFilter)
efiacor0080fa42020-09-08 16:26:50 +010074
ajay_dp001053579b2021-08-25 13:53:27 +053075 @patch('mod.pmsh_config.AppConfig._get_config', MagicMock(return_value=get_pmsh_config()))
76 def setUpAppConf(self):
77 self.pmsh_app_conf = NewAppConfig()
78
efiacor0080fa42020-09-08 16:26:50 +010079 def tearDown(self):
80 db.drop_all()
81
82 @classmethod
83 def tearDownClass(cls):
84 db.session.remove()