diff options
Diffstat (limited to 'components/pm-subscription-handler/tests/test_subscription_handler.py')
-rw-r--r-- | components/pm-subscription-handler/tests/test_subscription_handler.py | 49 |
1 files changed, 19 insertions, 30 deletions
diff --git a/components/pm-subscription-handler/tests/test_subscription_handler.py b/components/pm-subscription-handler/tests/test_subscription_handler.py index a6611666..bf72382a 100644 --- a/components/pm-subscription-handler/tests/test_subscription_handler.py +++ b/components/pm-subscription-handler/tests/test_subscription_handler.py @@ -15,50 +15,39 @@ # # SPDX-License-Identifier: Apache-2.0 # ============LICENSE_END===================================================== -import json -import os -from test.support import EnvironmentVarGuard -from unittest import TestCase -from unittest.mock import patch +from unittest.mock import patch, Mock -from mod import create_app, db from mod.network_function import NetworkFunction -from mod.pmsh_utils import AppConfig from mod.subscription import AdministrativeState from mod.subscription_handler import SubscriptionHandler +from tests.base_setup import BaseClassSetup -class SubscriptionHandlerTest(TestCase): +class SubscriptionHandlerTest(BaseClassSetup): @classmethod def setUpClass(cls): - cls.env = EnvironmentVarGuard() - cls.env.set('AAI_SERVICE_PORT', '8443') - cls.env.set('LOGGER_CONFIG', os.path.join(os.path.dirname(__file__), 'log_config.yaml')) - cls.nfs = [NetworkFunction(nf_name='pnf_1'), NetworkFunction(nf_name='pnf_2')] + super().setUpClass() - @patch('mod.get_db_connection_url') - @patch('mod.update_logging_config') - @patch('mod.pmsh_utils.AppConfig._get_pmsh_config') @patch('mod.pmsh_utils._MrPub') - @patch('mod.pmsh_utils.PeriodicTask') - def setUp(self, mock_periodic_task, mock_mr_pub, mock_get_pmsh_config, mock_update_config, - mock_get_db_url): - mock_get_db_url.return_value = 'sqlite://' - with open(os.path.join(os.path.dirname(__file__), 'data/cbs_data_1.json'), 'r') as data: - self.cbs_data = json.load(data) - mock_get_pmsh_config.return_value = self.cbs_data + def setUp(self, mock_mr_pub): + super().setUp() + self.nfs = [NetworkFunction(nf_name='pnf_1', + model_invariant_id='some-id', + model_version_id='some-id'), + NetworkFunction(nf_name='pnf_2', + model_invariant_id='some-id', + model_version_id='some-id')] self.mock_mr_pub = mock_mr_pub - self.mock_aai_event_thread = mock_periodic_task - self.mock_policy_event_thread = mock_periodic_task - self.app = create_app() - self.app.app_context().push() - db.create_all() - self.app_conf = AppConfig() + self.mock_aai_event_thread = Mock() + self.mock_policy_event_thread = Mock() def tearDown(self): - db.drop_all() - db.session.remove() + super().tearDown() + + @classmethod + def tearDownClass(cls): + super().tearDownClass() @patch('mod.subscription.Subscription.get_local_sub_admin_state') @patch('mod.logger.info') |