blob: be7d1b8f54639f6952464a55d85c5ef50e2ccab0 [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'):
raviteja.karumuri7e304212021-11-24 13:10:09 +000032 """
33 Gets PMSH config from the JSON file
34
35 Args:
36 file_path (String): Name of the file with path
37
38 Returns
39 dict: Dictionary representation of the the service configuration
40 """
shivasubedi9aa0b662021-01-18 13:59:18 +000041 with open(os.path.join(os.path.dirname(__file__), file_path), 'r') as data:
efiacor0080fa42020-09-08 16:26:50 +010042 return json.load(data)
43
44
raviteja.karumuri7e304212021-11-24 13:10:09 +000045def create_subscription_data(subscription_name):
46 """
47 Creates subscription model object
48
49 Args:
50 subscription_name (String): Name of the Subscription
51
52 Returns
53 SubscriptionModel: single subscription model object
54 """
raviteja.karumuri86f4eb22021-11-09 17:30:03 +000055 nf_filter = NetworkFunctionFilterModel(subscription_name, '{^pnf.*,^vnf.*}',
56 '{}', '{}', '{}')
57 mg_first = MeasurementGroupModel(subscription_name, 'MG1', 'UNLOCKED', 15, '/pm/pm.xml',
58 '[{ "measurementType": "countera" }, '
59 '{ "measurementType": "counterb" }]',
60 '[{ "DN":"dna"},{"DN":"dnb"}]')
61 mg_second = copy.deepcopy(mg_first)
62 mg_second.measurement_group_name = 'MG2'
63 mg_second.administrative_state = 'LOCKED'
64 mg_list = [mg_first, mg_second]
65 subscription_model = SubscriptionModel(subscription_name, 'pmsh_operational_policy',
66 'pmsh_control_loop_name', 'LOCKED')
67 subscription_model.network_filter = nf_filter
68 subscription_model.measurement_groups = mg_list
69 return subscription_model
70
71
raviteja.karumuri7e304212021-11-24 13:10:09 +000072def create_multiple_subscription_data(subscription_names):
73 """
74 Creates a list of subscription model objects
75
76 Args:
77 subscription_names (List): Name of the Subscriptions
78
79 Returns
80 list (SubscriptionModel): of subscription model objects
81 """
82 subscriptions = []
83 for subscription_name in subscription_names:
84 subscriptions.append(create_subscription_data(subscription_name))
85 return subscriptions
86
87
efiacor0080fa42020-09-08 16:26:50 +010088class BaseClassSetup(TestCase):
89 app = None
90 app_context = None
91
92 @classmethod
93 @patch('mod.get_db_connection_url', MagicMock(return_value='sqlite://'))
94 @patch('mod.update_logging_config', MagicMock())
95 def setUpClass(cls):
96 os.environ['LOGGER_CONFIG'] = os.path.join(os.path.dirname(__file__), 'log_config.yaml')
97 os.environ['LOGS_PATH'] = '.'
98 cls.app = create_app()
99 cls.app_context = cls.app.app_context()
100 cls.app_context.push()
101
102 @patch('mod.pmsh_utils.AppConfig._get_pmsh_config', MagicMock(return_value=get_pmsh_config()))
103 def setUp(self):
104 os.environ['AAI_SERVICE_PORT'] = '8443'
105 db.create_all()
106 self.app_conf = AppConfig()
shivasubedi9aa0b662021-01-18 13:59:18 +0000107 self.app_conf.nf_filter = NetworkFunctionFilter(**self.app_conf.subscription.nfFilter)
efiacor0080fa42020-09-08 16:26:50 +0100108
ajay_dp001053579b2021-08-25 13:53:27 +0530109 @patch('mod.pmsh_config.AppConfig._get_config', MagicMock(return_value=get_pmsh_config()))
110 def setUpAppConf(self):
111 self.pmsh_app_conf = NewAppConfig()
112
efiacor0080fa42020-09-08 16:26:50 +0100113 def tearDown(self):
114 db.drop_all()
115
116 @classmethod
117 def tearDownClass(cls):
118 db.session.remove()