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===================================================== |
| 18 | import json |
| 19 | import os |
| 20 | from unittest import TestCase |
| 21 | from unittest.mock import patch, MagicMock |
| 22 | |
| 23 | from mod import create_app, db |
shivasubedi | 9aa0b66 | 2021-01-18 13:59:18 +0000 | [diff] [blame] | 24 | from mod.network_function import NetworkFunctionFilter |
efiacor | 0080fa4 | 2020-09-08 16:26:50 +0100 | [diff] [blame] | 25 | from mod.pmsh_utils import AppConfig |
ajay_dp001 | 053579b | 2021-08-25 13:53:27 +0530 | [diff] [blame] | 26 | from mod.pmsh_config import AppConfig as NewAppConfig |
efiacor | 0080fa4 | 2020-09-08 16:26:50 +0100 | [diff] [blame] | 27 | |
| 28 | |
shivasubedi | 9aa0b66 | 2021-01-18 13:59:18 +0000 | [diff] [blame] | 29 | def 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: |
efiacor | 0080fa4 | 2020-09-08 16:26:50 +0100 | [diff] [blame] | 31 | return json.load(data) |
| 32 | |
| 33 | |
| 34 | class 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() |
shivasubedi | 9aa0b66 | 2021-01-18 13:59:18 +0000 | [diff] [blame] | 53 | self.app_conf.nf_filter = NetworkFunctionFilter(**self.app_conf.subscription.nfFilter) |
efiacor | 0080fa4 | 2020-09-08 16:26:50 +0100 | [diff] [blame] | 54 | |
ajay_dp001 | 053579b | 2021-08-25 13:53:27 +0530 | [diff] [blame] | 55 | @patch('mod.pmsh_config.AppConfig._get_config', MagicMock(return_value=get_pmsh_config())) |
| 56 | def setUpAppConf(self): |
| 57 | self.pmsh_app_conf = NewAppConfig() |
| 58 | |
efiacor | 0080fa4 | 2020-09-08 16:26:50 +0100 | [diff] [blame] | 59 | def tearDown(self): |
| 60 | db.drop_all() |
| 61 | |
| 62 | @classmethod |
| 63 | def tearDownClass(cls): |
| 64 | db.session.remove() |