summaryrefslogtreecommitdiffstats
path: root/components/pm-subscription-handler/tests
diff options
context:
space:
mode:
authorefiacor <fiachra.corcoran@est.tech>2021-01-13 16:12:57 +0000
committerefiacor <fiachra.corcoran@est.tech>2021-01-26 16:47:26 +0000
commitf7be006e7cc638788164fb1028d03898138b8c16 (patch)
tree253d460ca148495d31203b9038b1e24ec209d7e9 /components/pm-subscription-handler/tests
parent2510fa240ca7395ff8a36762d5892413ab05fd68 (diff)
[PMSH] Update sub object on activate
Signed-off-by: efiacor <fiachra.corcoran@est.tech> Change-Id: Id9418301e0cb4d373339b9b3e3476f7db5770f3e Issue-ID: DCAEGEN2-2152
Diffstat (limited to 'components/pm-subscription-handler/tests')
-rw-r--r--components/pm-subscription-handler/tests/test_pmsh_utils.py7
-rw-r--r--components/pm-subscription-handler/tests/test_subscription_handler.py43
2 files changed, 22 insertions, 28 deletions
diff --git a/components/pm-subscription-handler/tests/test_pmsh_utils.py b/components/pm-subscription-handler/tests/test_pmsh_utils.py
index 1bc039d2..602253b8 100644
--- a/components/pm-subscription-handler/tests/test_pmsh_utils.py
+++ b/components/pm-subscription-handler/tests/test_pmsh_utils.py
@@ -24,7 +24,6 @@ from tenacity import RetryError
from mod import get_db_connection_url
from mod.network_function import NetworkFunction
-from mod.pmsh_utils import AppConfig
from tests.base_setup import BaseClassSetup
from tests.base_setup import get_pmsh_config
@@ -139,9 +138,7 @@ class PmshUtilsTestCase(BaseClassSetup):
@patch('mod.logger.error')
@patch('mod.pmsh_utils.get_all')
def test_refresh_config_fail(self, mock_cbs_client_get_all, mock_logger):
- mock_cbs_client_get_all.return_value = get_pmsh_config()
- self.app_conf = AppConfig()
- mock_cbs_client_get_all.side_effect = Exception
+ mock_cbs_client_get_all.side_effect = ValueError
with self.assertRaises(RetryError):
self.app_conf.refresh_config()
- mock_logger.assert_called_with('Failed to get config from CBS: ', exc_info=True)
+ mock_logger.assert_called_with('Failed to refresh PMSH AppConfig')
diff --git a/components/pm-subscription-handler/tests/test_subscription_handler.py b/components/pm-subscription-handler/tests/test_subscription_handler.py
index f77dfd10..31dd0943 100644
--- a/components/pm-subscription-handler/tests/test_subscription_handler.py
+++ b/components/pm-subscription-handler/tests/test_subscription_handler.py
@@ -1,5 +1,5 @@
# ============LICENSE_START===================================================
-# Copyright (C) 2020 Nordix Foundation.
+# Copyright (C) 2020-2021 Nordix Foundation.
# ============================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -33,11 +33,12 @@ class SubscriptionHandlerTest(BaseClassSetup):
def setUpClass(cls):
super().setUpClass()
+ @patch('mod.pmsh_utils._MrSub')
@patch('mod.pmsh_utils._MrPub')
- def setUp(self, mock_mr_pub):
+ def setUp(self, mock_mr_pub, mock_mr_sub):
super().setUp()
self.mock_mr_pub = mock_mr_pub
- self.mock_aai_event_thread = Mock()
+ self.mock_mr_sub = mock_mr_sub
self.mock_policy_event_thread = Mock()
def tearDown(self):
@@ -55,12 +56,13 @@ class SubscriptionHandlerTest(BaseClassSetup):
mock_get_sub_status.return_value = AdministrativeState.UNLOCKED.value
mock_get_aai.return_value = self.nfs
sub_handler = SubscriptionHandler(self.mock_mr_pub,
- self.app, self.app_conf,
- self.mock_aai_event_thread)
+ self.mock_mr_sub, self.app, self.app_conf)
sub_handler.execute()
mock_logger.assert_called_with('Administrative State did not change '
'in the app config: UNLOCKED')
+ @patch('mod.subscription_handler.SubscriptionHandler._start_aai_event_thread',
+ MagicMock())
@patch('mod.pmsh_utils.AppConfig.refresh_config', MagicMock(return_value=get_pmsh_config()))
@patch('mod.subscription.Subscription.get_local_sub_admin_state')
@patch('mod.subscription.Subscription.create_subscription_on_nfs')
@@ -69,10 +71,8 @@ class SubscriptionHandlerTest(BaseClassSetup):
mock_get_sub_status):
mock_get_aai.return_value = self.nfs
mock_get_sub_status.return_value = AdministrativeState.LOCKED.value
- self.mock_aai_event_thread.return_value.start.return_value = 'start_method'
- sub_handler = SubscriptionHandler(self.mock_mr_pub,
- self.app, self.app_conf,
- self.mock_aai_event_thread.return_value)
+ sub_handler = SubscriptionHandler(self.mock_mr_pub, self.mock_mr_sub, self.app,
+ self.app_conf)
sub_handler.execute()
self.assertEqual(AdministrativeState.UNLOCKED.value,
self.app_conf.subscription.administrativeState)
@@ -86,14 +86,12 @@ class SubscriptionHandlerTest(BaseClassSetup):
mock_get_sub_status.return_value = AdministrativeState.UNLOCKED.value
self.app_conf.subscription.administrativeState = AdministrativeState.LOCKED.value
self.app_conf.subscription.update_subscription_status()
- self.mock_aai_event_thread.return_value.cancel.return_value = 'cancel_method'
- sub_handler = SubscriptionHandler(self.mock_mr_pub,
- self.app, self.app_conf,
- self.mock_aai_event_thread.return_value)
+ sub_handler = SubscriptionHandler(self.mock_mr_pub, self.mock_mr_sub, self.app,
+ self.app_conf)
sub_handler.execute()
mock_deactivate_sub.assert_called_with(self.nfs, self.mock_mr_pub, self.app_conf)
- self.mock_aai_event_thread.return_value.cancel.assert_called()
+ @patch('mod.subscription_handler.SubscriptionHandler._start_aai_event_thread', MagicMock())
@patch('mod.pmsh_utils.AppConfig.refresh_config', MagicMock(return_value=get_pmsh_config()))
@patch('mod.subscription.Subscription.create_subscription_on_nfs')
@patch('mod.logger.error')
@@ -101,9 +99,8 @@ class SubscriptionHandlerTest(BaseClassSetup):
def test_execute_exception(self, mock_get_aai, mock_logger, mock_activate_sub):
mock_get_aai.return_value = self.nfs
mock_activate_sub.side_effect = Exception
- sub_handler = SubscriptionHandler(self.mock_mr_pub,
- self.app, self.app_conf,
- self.mock_aai_event_thread)
+ sub_handler = SubscriptionHandler(self.mock_mr_pub, self.mock_mr_sub, self.app,
+ self.app_conf)
sub_handler.execute()
mock_logger.assert_called_with('Error occurred during the activation/deactivation process ',
exc_info=True)
@@ -125,8 +122,8 @@ class SubscriptionHandlerTest(BaseClassSetup):
def test_execute_change_of_state_to_locking_retry_delete(self, mock_retry_inc, mock_delete_sub,
mock_get_sub_status):
mock_get_sub_status.return_value = AdministrativeState.LOCKING.value
- sub_handler = SubscriptionHandler(self.mock_mr_pub, self.app, self.app_conf,
- self.mock_aai_event_thread)
+ sub_handler = SubscriptionHandler(self.mock_mr_pub, self.mock_mr_sub, self.app,
+ self.app_conf)
sub_handler.execute()
self.assertEqual(mock_delete_sub.call_count, 2)
self.assertEqual(mock_retry_inc.call_count, 2)
@@ -139,8 +136,8 @@ class SubscriptionHandlerTest(BaseClassSetup):
def test_execute_change_of_state_to_locking_success(self, mock_update_sub,
mock_get_sub_status):
mock_get_sub_status.return_value = AdministrativeState.LOCKING.value
- sub_handler = SubscriptionHandler(self.mock_mr_pub, self.app, self.app_conf,
- self.mock_aai_event_thread)
+ sub_handler = SubscriptionHandler(self.mock_mr_pub, self.mock_mr_sub, self.app,
+ self.app_conf)
sub_handler.execute()
mock_update_sub.assert_called_once()
@@ -161,7 +158,7 @@ class SubscriptionHandlerTest(BaseClassSetup):
def test_execute_change_of_state_to_locking_retry_failed(self, mock_nf_del,
mock_get_sub_status):
mock_get_sub_status.return_value = AdministrativeState.LOCKING.value
- sub_handler = SubscriptionHandler(self.mock_mr_pub, self.app, self.app_conf,
- self.mock_aai_event_thread)
+ sub_handler = SubscriptionHandler(self.mock_mr_pub, self.mock_mr_sub, self.app,
+ self.app_conf)
sub_handler.execute()
mock_nf_del.assert_called_once()