blob: e422ceac60d1e62e5b8e8d0ea7c079071b05f1d0 [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=====================================================
18import json
19import os
20from unittest import TestCase
21from unittest.mock import patch, MagicMock
22
23from mod import create_app, db
shivasubedi9aa0b662021-01-18 13:59:18 +000024from mod.network_function import NetworkFunctionFilter
efiacor0080fa42020-09-08 16:26:50 +010025from mod.pmsh_utils import AppConfig
ajay_dp001053579b2021-08-25 13:53:27 +053026from mod.pmsh_config import AppConfig as NewAppConfig
efiacor0080fa42020-09-08 16:26:50 +010027
28
shivasubedi9aa0b662021-01-18 13:59:18 +000029def get_pmsh_config(file_path='data/cbs_data_1.json'):
30 with open(os.path.join(os.path.dirname(__file__), file_path), 'r') as data:
efiacor0080fa42020-09-08 16:26:50 +010031 return json.load(data)
32
33
34class BaseClassSetup(TestCase):
35 app = None
36 app_context = None
37
38 @classmethod
39 @patch('mod.get_db_connection_url', MagicMock(return_value='sqlite://'))
40 @patch('mod.update_logging_config', MagicMock())
41 def setUpClass(cls):
42 os.environ['LOGGER_CONFIG'] = os.path.join(os.path.dirname(__file__), 'log_config.yaml')
43 os.environ['LOGS_PATH'] = '.'
44 cls.app = create_app()
45 cls.app_context = cls.app.app_context()
46 cls.app_context.push()
47
48 @patch('mod.pmsh_utils.AppConfig._get_pmsh_config', MagicMock(return_value=get_pmsh_config()))
49 def setUp(self):
50 os.environ['AAI_SERVICE_PORT'] = '8443'
51 db.create_all()
52 self.app_conf = AppConfig()
shivasubedi9aa0b662021-01-18 13:59:18 +000053 self.app_conf.nf_filter = NetworkFunctionFilter(**self.app_conf.subscription.nfFilter)
efiacor0080fa42020-09-08 16:26:50 +010054
ajay_dp001053579b2021-08-25 13:53:27 +053055 @patch('mod.pmsh_config.AppConfig._get_config', MagicMock(return_value=get_pmsh_config()))
56 def setUpAppConf(self):
57 self.pmsh_app_conf = NewAppConfig()
58
efiacor0080fa42020-09-08 16:26:50 +010059 def tearDown(self):
60 db.drop_all()
61
62 @classmethod
63 def tearDownClass(cls):
64 db.session.remove()