summaryrefslogtreecommitdiffstats
path: root/components/pm-subscription-handler/tests
diff options
context:
space:
mode:
authorajay_dp001 <ajay.deep.singh@est.tech>2021-08-25 13:53:27 +0530
committerajay_dp001 <ajay.deep.singh@est.tech>2021-10-04 20:53:55 +0530
commit053579b1a3a9d71fdc8fde5ed67600b453de083c (patch)
treecced45413b29daf5a718561f853ec880c3c718a3 /components/pm-subscription-handler/tests
parent62a3787b8c2f00ad4ba681517970db3201717088 (diff)
[DCAEGEN2] PMSH AppConfig Update
- Simplified existing PMSH Appconfig - Major version bump for J release Issue-ID: DCAEGEN2-2814 Signed-off-by: ajay_dp001 <ajay.deep.singh@est.tech> Change-Id: I8ed572ccc7385cfdf91e51a126622821c113c53d
Diffstat (limited to 'components/pm-subscription-handler/tests')
-rwxr-xr-xcomponents/pm-subscription-handler/tests/base_setup.py7
-rw-r--r--components/pm-subscription-handler/tests/test_pmsh_config.py92
2 files changed, 98 insertions, 1 deletions
diff --git a/components/pm-subscription-handler/tests/base_setup.py b/components/pm-subscription-handler/tests/base_setup.py
index 9e12f96e..e422ceac 100755
--- a/components/pm-subscription-handler/tests/base_setup.py
+++ b/components/pm-subscription-handler/tests/base_setup.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.
@@ -23,6 +23,7 @@ from unittest.mock import patch, MagicMock
from mod import create_app, db
from mod.network_function import NetworkFunctionFilter
from mod.pmsh_utils import AppConfig
+from mod.pmsh_config import AppConfig as NewAppConfig
def get_pmsh_config(file_path='data/cbs_data_1.json'):
@@ -51,6 +52,10 @@ class BaseClassSetup(TestCase):
self.app_conf = AppConfig()
self.app_conf.nf_filter = NetworkFunctionFilter(**self.app_conf.subscription.nfFilter)
+ @patch('mod.pmsh_config.AppConfig._get_config', MagicMock(return_value=get_pmsh_config()))
+ def setUpAppConf(self):
+ self.pmsh_app_conf = NewAppConfig()
+
def tearDown(self):
db.drop_all()
diff --git a/components/pm-subscription-handler/tests/test_pmsh_config.py b/components/pm-subscription-handler/tests/test_pmsh_config.py
new file mode 100644
index 00000000..deb867bf
--- /dev/null
+++ b/components/pm-subscription-handler/tests/test_pmsh_config.py
@@ -0,0 +1,92 @@
+# ============LICENSE_START===================================================
+# Copyright (C) 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# SPDX-License-Identifier: Apache-2.0
+# ============LICENSE_END=====================================================
+from unittest.mock import Mock, patch
+
+import responses
+from requests import Session
+
+from mod.pmsh_config import MRTopic, AppConfig
+from tests.base_setup import BaseClassSetup
+
+
+class PmshConfigTestCase(BaseClassSetup):
+
+ @classmethod
+ def setUpClass(cls):
+ super().setUpClass()
+
+ def setUp(self):
+ super().setUpAppConf()
+ self.mock_app = Mock()
+
+ def tearDown(self):
+ super().tearDown()
+
+ @classmethod
+ def tearDownClass(cls):
+ super().tearDownClass()
+
+ def test_config_get_aaf_creds(self):
+ self.assertEqual(self.pmsh_app_conf.enable_tls, 'true')
+ self.assertEqual(self.pmsh_app_conf.aaf_id, 'dcae@dcae.onap.org')
+ self.assertEqual(self.pmsh_app_conf.aaf_pass, 'demo123456!')
+
+ def test_config_get_cert_data(self):
+ self.assertEqual(self.pmsh_app_conf.key_path, '/opt/app/pmsh/etc/certs/key.pem')
+ self.assertEqual(self.pmsh_app_conf.cert_path, '/opt/app/pmsh/etc/certs/cert.pem')
+ self.assertEqual(self.pmsh_app_conf.ca_cert_path, '/opt/app/pmsh/etc/certs/cacert.pem')
+
+ def test_singleton_instance_is_accessible_using_class_method(self):
+ my_singleton_instance = AppConfig.get_instance()
+ self.assertIsNotNone(my_singleton_instance)
+ self.assertIsInstance(my_singleton_instance, AppConfig)
+
+ @patch.object(Session, 'post')
+ def test_mr_pub_publish_to_topic_success(self, mock_session):
+ mock_session.return_value.status_code = 200
+ with patch('requests.Session.post') as session_post_call:
+ self.pmsh_app_conf.publish_to_topic(MRTopic.POLICY_PM_PUBLISHER.value,
+ {"key": "43c4ee19-6b8d-4279-a80f-c507850aae47"})
+ session_post_call.assert_called_once()
+
+ @responses.activate
+ def test_mr_pub_publish_to_topic_fail(self):
+ responses.add(responses.POST,
+ 'https://message-router:3905/events/org.onap.dmaap.mr.PM_SUBSCRIPTIONS',
+ json={"error": "Client Error"}, status=400)
+ with self.assertRaises(Exception):
+ self.pmsh_app_conf.publish_to_topic(MRTopic.POLICY_PM_PUBLISHER.value,
+ {"key": "43c4ee19-6b8d-4279-a80f-c507850aae47"})
+
+ @responses.activate
+ def test_mr_sub_get_from_topic_success(self):
+ responses.add(responses.GET,
+ 'https://message-router:3905/events/org.onap.dmaap.mr.PM_SUBSCRIPTIONS/'
+ 'dcae_pmsh_cg/1?timeout=5000',
+ json={"key": "43c4ee19-6b8d-4279-a80f-c507850aae47"}, status=200)
+ mr_topic_data = self.pmsh_app_conf.get_from_topic(MRTopic.POLICY_PM_SUBSCRIBER.value, 1)
+ self.assertIsNotNone(mr_topic_data)
+
+ @responses.activate
+ def test_mr_sub_get_from_topic_fail(self):
+ responses.add(responses.GET,
+ 'https://message-router:3905/events/org.onap.dmaap.mr.PM_SUBSCRIPTIONS/'
+ 'dcae_pmsh_cg/1?timeout=5000',
+ json={"key": "43c4ee19-6b8d-4279-a80f-c507850aae47"}, status=400)
+ with self.assertRaises(Exception):
+ self.pmsh_app_conf.get_from_topic(MRTopic.POLICY_PM_SUBSCRIBER.value, 1)