efiacor | 0080fa4 | 2020-09-08 16:26:50 +0100 | [diff] [blame^] | 1 | # ============LICENSE_START=================================================== |
| 2 | # Copyright (C) 2020 Nordix Foundation. |
| 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 |
| 24 | from mod.pmsh_utils import AppConfig |
| 25 | |
| 26 | |
| 27 | def get_pmsh_config(): |
| 28 | with open(os.path.join(os.path.dirname(__file__), 'data/cbs_data_1.json'), 'r') as data: |
| 29 | return json.load(data) |
| 30 | |
| 31 | |
| 32 | class BaseClassSetup(TestCase): |
| 33 | app = None |
| 34 | app_context = None |
| 35 | |
| 36 | @classmethod |
| 37 | @patch('mod.get_db_connection_url', MagicMock(return_value='sqlite://')) |
| 38 | @patch('mod.update_logging_config', MagicMock()) |
| 39 | def setUpClass(cls): |
| 40 | os.environ['LOGGER_CONFIG'] = os.path.join(os.path.dirname(__file__), 'log_config.yaml') |
| 41 | os.environ['LOGS_PATH'] = '.' |
| 42 | cls.app = create_app() |
| 43 | cls.app_context = cls.app.app_context() |
| 44 | cls.app_context.push() |
| 45 | |
| 46 | @patch('mod.pmsh_utils.AppConfig._get_pmsh_config', MagicMock(return_value=get_pmsh_config())) |
| 47 | def setUp(self): |
| 48 | os.environ['AAI_SERVICE_PORT'] = '8443' |
| 49 | db.create_all() |
| 50 | self.app_conf = AppConfig() |
| 51 | |
| 52 | def tearDown(self): |
| 53 | db.drop_all() |
| 54 | |
| 55 | @classmethod |
| 56 | def tearDownClass(cls): |
| 57 | db.session.remove() |