summaryrefslogtreecommitdiffstats
path: root/components/pm-subscription-handler/tests
diff options
context:
space:
mode:
authorERIMROB <robertas.rimkus@est.tech>2020-05-12 12:56:56 +0100
committerERIMROB <robertas.rimkus@est.tech>2020-06-05 10:11:06 +0100
commit2760519436f78975f16f26c412e842e34b28d624 (patch)
tree3fb616398002bd4525c10ff8b510bbf5ebadc26f /components/pm-subscription-handler/tests
parent5ed9b7d3cad56c6438bca305b6d2931bd320352b (diff)
[PMSH] Replace own logging implementation with pylog
Signed-off-by: ERIMROB <robertas.rimkus@est.tech> Issue-ID: DCAEGEN2-2155 Change-Id: I670c4fff8029a73075b651c2afe6237c08cf907c
Diffstat (limited to 'components/pm-subscription-handler/tests')
-rwxr-xr-xcomponents/pm-subscription-handler/tests/log_config.yaml20
-rw-r--r--components/pm-subscription-handler/tests/test_aai_service.py8
-rwxr-xr-xcomponents/pm-subscription-handler/tests/test_controller.py6
-rwxr-xr-xcomponents/pm-subscription-handler/tests/test_network_function.py6
-rw-r--r--components/pm-subscription-handler/tests/test_pmsh_utils.py6
-rwxr-xr-xcomponents/pm-subscription-handler/tests/test_subscription.py16
-rw-r--r--components/pm-subscription-handler/tests/test_subscription_handler.py4
7 files changed, 51 insertions, 15 deletions
diff --git a/components/pm-subscription-handler/tests/log_config.yaml b/components/pm-subscription-handler/tests/log_config.yaml
new file mode 100755
index 00000000..56620708
--- /dev/null
+++ b/components/pm-subscription-handler/tests/log_config.yaml
@@ -0,0 +1,20 @@
+version: 1
+
+disable_existing_loggers: true
+
+loggers:
+ onap_logger:
+ level: INFO
+ handlers: [stdout_handler]
+ propagate: false
+handlers:
+ stdout_handler:
+ class: logging.StreamHandler
+ formatter: mdcFormatter
+formatters:
+ mdcFormatter:
+ format: '%(asctime)s | %(threadName)s | %(thread)d | %(levelname)s | %(module)s
+ | %(funcName)s | %(mdc)s | %(message)s'
+ mdcfmt: '{ServiceName} | {RequestID} | {InvocationID}'
+ datefmt: '%Y-%m-%dT%H:%M:%S%z'
+ (): onaplogging.mdcformatter.MDCFormatter
diff --git a/components/pm-subscription-handler/tests/test_aai_service.py b/components/pm-subscription-handler/tests/test_aai_service.py
index 1ee71554..9a3a1b69 100644
--- a/components/pm-subscription-handler/tests/test_aai_service.py
+++ b/components/pm-subscription-handler/tests/test_aai_service.py
@@ -25,18 +25,24 @@ import responses
from requests import Session
import mod.aai_client as aai_client
+from mod import create_app
class AaiClientTestCase(TestCase):
- def setUp(self):
+ @patch('mod.update_config')
+ @patch('mod.get_db_connection_url')
+ def setUp(self, mock_get_db_url, mock_update_config):
+ mock_get_db_url.return_value = 'sqlite://'
self.env = EnvironmentVarGuard()
self.env.set('AAI_SERVICE_HOST', '1.2.3.4')
self.env.set('AAI_SERVICE_PORT', '8443')
+ self.env.set('LOGGER_CONFIG', os.path.join(os.path.dirname(__file__), 'log_config.yaml'))
with open(os.path.join(os.path.dirname(__file__), 'data/cbs_data_1.json'), 'r') as data:
self.cbs_data = json.load(data)
with open(os.path.join(os.path.dirname(__file__), 'data/aai_xnfs.json'), 'r') as data:
self.aai_response_data = data.read()
+ self.app = create_app()
@patch.object(Session, 'put')
def test_aai_client_get_pm_sub_data_success(self, mock_session):
diff --git a/components/pm-subscription-handler/tests/test_controller.py b/components/pm-subscription-handler/tests/test_controller.py
index 8ef39460..8ca208ae 100755
--- a/components/pm-subscription-handler/tests/test_controller.py
+++ b/components/pm-subscription-handler/tests/test_controller.py
@@ -29,9 +29,10 @@ from mod.network_function import NetworkFunction
class ControllerTestCase(unittest.TestCase):
+ @patch('mod.update_config')
@patch('mod.get_db_connection_url')
@patch.object(Session, 'put')
- def setUp(self, mock_session, mock_get_db_url):
+ def setUp(self, mock_session, mock_get_db_url, mock_update_config):
mock_get_db_url.return_value = 'sqlite://'
with open(os.path.join(os.path.dirname(__file__), 'data/aai_xnfs.json'), 'r') as data:
self.aai_response_data = data.read()
@@ -40,8 +41,7 @@ class ControllerTestCase(unittest.TestCase):
self.env = EnvironmentVarGuard()
self.env.set('AAI_SERVICE_HOST', '1.2.3.4')
self.env.set('AAI_SERVICE_PORT', '8443')
- self.env.set('TESTING', 'True')
- self.env.set('LOGS_PATH', './unit_test_logs')
+ self.env.set('LOGGER_CONFIG', os.path.join(os.path.dirname(__file__), 'log_config.yaml'))
with open(os.path.join(os.path.dirname(__file__), 'data/cbs_data_1.json'), 'r') as data:
self.cbs_data_1 = json.load(data)
self.sub_1, self.xnfs = aai_client.get_pmsh_subscription_data(self.cbs_data_1)
diff --git a/components/pm-subscription-handler/tests/test_network_function.py b/components/pm-subscription-handler/tests/test_network_function.py
index 138d99ad..a5324bd1 100755
--- a/components/pm-subscription-handler/tests/test_network_function.py
+++ b/components/pm-subscription-handler/tests/test_network_function.py
@@ -15,6 +15,7 @@
#
# SPDX-License-Identifier: Apache-2.0
# ============LICENSE_END=====================================================
+import os
from test.support import EnvironmentVarGuard
from unittest import TestCase
from unittest.mock import patch
@@ -26,13 +27,14 @@ from mod.subscription import Subscription
class NetworkFunctionTests(TestCase):
+ @patch('mod.update_config')
@patch('mod.get_db_connection_url')
- def setUp(self, mock_get_db_url):
+ def setUp(self, mock_get_db_url, mock_update_config):
mock_get_db_url.return_value = 'sqlite://'
self.nf_1 = NetworkFunction(nf_name='pnf_1', orchestration_status='Inventoried')
self.nf_2 = NetworkFunction(nf_name='pnf_2', orchestration_status='Active')
self.env = EnvironmentVarGuard()
- self.env.set('LOGS_PATH', './unit_test_logs')
+ self.env.set('LOGGER_CONFIG', os.path.join(os.path.dirname(__file__), 'log_config.yaml'))
self.app = create_app()
self.app_context = self.app.app_context()
self.app_context.push()
diff --git a/components/pm-subscription-handler/tests/test_pmsh_utils.py b/components/pm-subscription-handler/tests/test_pmsh_utils.py
index 236331b4..0c3b2d28 100644
--- a/components/pm-subscription-handler/tests/test_pmsh_utils.py
+++ b/components/pm-subscription-handler/tests/test_pmsh_utils.py
@@ -31,16 +31,18 @@ from mod.subscription import Subscription
class PmshUtilsTestCase(TestCase):
+ @patch('mod.update_config')
@patch('mod.create_app')
@patch('mod.get_db_connection_url')
- def setUp(self, mock_get_db_url, mock_app):
+ def setUp(self, mock_get_db_url, mock_app, mock_update_config):
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)
self.app_conf = AppConfig(**self.cbs_data['config'])
self.sub = Subscription(**self.cbs_data['policy']['subscription'])
self.env = EnvironmentVarGuard()
- self.env.set('LOGS_PATH', './unit_test_logs')
+ self.env.set('TESTING', 'True')
+ self.env.set('LOGGER_CONFIG', os.path.join(os.path.dirname(__file__), 'log_config.yaml'))
self.policy_mr_sub = self.app_conf.get_mr_sub('policy_pm_subscriber')
self.mock_app = mock_app
self.app = create_app()
diff --git a/components/pm-subscription-handler/tests/test_subscription.py b/components/pm-subscription-handler/tests/test_subscription.py
index dc549c94..b50d9aaf 100755
--- a/components/pm-subscription-handler/tests/test_subscription.py
+++ b/components/pm-subscription-handler/tests/test_subscription.py
@@ -33,12 +33,14 @@ from mod.subscription import Subscription
class SubscriptionTest(TestCase):
+ @patch('mod.update_config')
@patch('mod.pmsh_utils._MrPub')
@patch('mod.pmsh_utils._MrSub')
@patch('mod.get_db_connection_url')
@patch.object(Session, 'put')
@patch('pmsh_service_main.AppConfig')
- def setUp(self, mock_app_config, mock_session, mock_get_db_url, mock_mr_sub, mock_mr_pub):
+ def setUp(self, mock_app_config, mock_session, mock_get_db_url,
+ mock_mr_sub, mock_mr_pub, mock_update_config):
mock_get_db_url.return_value = 'sqlite://'
with open(os.path.join(os.path.dirname(__file__), 'data/aai_xnfs.json'), 'r') as data:
self.aai_response_data = data.read()
@@ -47,8 +49,7 @@ class SubscriptionTest(TestCase):
self.env = EnvironmentVarGuard()
self.env.set('AAI_SERVICE_HOST', '1.2.3.4')
self.env.set('AAI_SERVICE_PORT', '8443')
- self.env.set('TESTING', 'True')
- self.env.set('LOGS_PATH', './unit_test_logs')
+ self.env.set('LOGGER_CONFIG', os.path.join(os.path.dirname(__file__), 'log_config.yaml'))
with open(os.path.join(os.path.dirname(__file__), 'data/cbs_data_1.json'), 'r') as data:
self.cbs_data_1 = json.load(data)
with open(os.path.join(os.path.dirname(__file__),
@@ -103,6 +104,13 @@ class SubscriptionTest(TestCase):
self.assertEqual(2, len(subs))
+ def test_get_nf_names_per_sub(self):
+ self.sub_1.create()
+ self.sub_1.add_network_function_to_subscription(self.nf_1)
+ self.sub_1.add_network_function_to_subscription(self.nf_2)
+ nfs = Subscription.get_nf_names_per_sub(self.sub_1.subscriptionName)
+ self.assertEqual(2, len(nfs))
+
def test_create_existing_subscription(self):
sub1 = self.sub_1.create()
same_sub1 = self.sub_1.create()
@@ -117,7 +125,6 @@ class SubscriptionTest(TestCase):
new_nf = NetworkFunction(nf_name='vnf_3', orchestration_status='Inventoried')
self.sub_1.add_network_function_to_subscription(new_nf)
nf_subs = Subscription.get_all_nfs_subscription_relations()
- print(nf_subs)
self.assertEqual(3, len(nf_subs))
def test_add_duplicate_network_functions_per_subscription(self):
@@ -201,7 +208,6 @@ class SubscriptionTest(TestCase):
expected_sub_event = json.load(data)
app_conf = AppConfig(**self.cbs_data_1['config'])
actual_sub_event = self.sub_1.prepare_subscription_event(self.nf_1.nf_name, app_conf)
- print(actual_sub_event)
self.assertEqual(expected_sub_event, actual_sub_event)
def test_get_nf_models(self):
diff --git a/components/pm-subscription-handler/tests/test_subscription_handler.py b/components/pm-subscription-handler/tests/test_subscription_handler.py
index d922b96f..3eb12bca 100644
--- a/components/pm-subscription-handler/tests/test_subscription_handler.py
+++ b/components/pm-subscription-handler/tests/test_subscription_handler.py
@@ -45,7 +45,7 @@ class SubscriptionHandlerTest(TestCase):
self.nf_2 = NetworkFunction(nf_name='pnf_2')
self.nfs = [self.nf_1, self.nf_2]
- @patch('mod.pmsh_logging.debug')
+ @patch('mod.logger.info')
@patch('mod.aai_client.get_pmsh_subscription_data')
def test_execute_no_change_of_state(self, mock_get_aai, mock_logger):
mock_get_aai.return_value = self.mock_sub, self.nfs
@@ -88,7 +88,7 @@ class SubscriptionHandlerTest(TestCase):
self.mock_app_conf)
self.mock_aai_event_thread.return_value.cancel.assert_called()
- @patch('mod.pmsh_logging.debug')
+ @patch('mod.logger.error')
@patch('mod.aai_client.get_pmsh_subscription_data')
def test_execute_exception(self, mock_get_aai, mock_logger):
mock_get_aai.return_value = self.mock_sub, self.nfs