diff options
author | 2021-11-09 17:30:03 +0000 | |
---|---|---|
committer | 2021-11-23 14:40:05 +0000 | |
commit | 86f4eb23f256c3d7b748791bcff96e61c94fbd0f (patch) | |
tree | 76bbdca2d5407bbb8e16f6be1e8751630237468a /components/pm-subscription-handler/tests | |
parent | 1685b700294ee0c1eaa1365d67a42861af0fe721 (diff) |
[PMSH] Read subscription API by Name
Issue-ID: DCAEGEN2-2818
Signed-off-by: Raviteja, Karumuri <raviteja.karumuri@est.tech>
Change-Id: Ie6925b4f4111e6f50c3b7dcd8eba670b89e63de3
Diffstat (limited to 'components/pm-subscription-handler/tests')
3 files changed, 52 insertions, 29 deletions
diff --git a/components/pm-subscription-handler/tests/base_setup.py b/components/pm-subscription-handler/tests/base_setup.py index e422ceac..4328f59c 100755 --- a/components/pm-subscription-handler/tests/base_setup.py +++ b/components/pm-subscription-handler/tests/base_setup.py @@ -15,12 +15,14 @@ # # SPDX-License-Identifier: Apache-2.0 # ============LICENSE_END===================================================== +import copy import json import os from unittest import TestCase from unittest.mock import patch, MagicMock from mod import create_app, db +from mod.api.db_models import NetworkFunctionFilterModel, MeasurementGroupModel, SubscriptionModel from mod.network_function import NetworkFunctionFilter from mod.pmsh_utils import AppConfig from mod.pmsh_config import AppConfig as NewAppConfig @@ -31,6 +33,24 @@ def get_pmsh_config(file_path='data/cbs_data_1.json'): return json.load(data) +def subscription_data(subscription_name): + nf_filter = NetworkFunctionFilterModel(subscription_name, '{^pnf.*,^vnf.*}', + '{}', '{}', '{}') + mg_first = MeasurementGroupModel(subscription_name, 'MG1', 'UNLOCKED', 15, '/pm/pm.xml', + '[{ "measurementType": "countera" }, ' + '{ "measurementType": "counterb" }]', + '[{ "DN":"dna"},{"DN":"dnb"}]') + mg_second = copy.deepcopy(mg_first) + mg_second.measurement_group_name = 'MG2' + mg_second.administrative_state = 'LOCKED' + mg_list = [mg_first, mg_second] + subscription_model = SubscriptionModel(subscription_name, 'pmsh_operational_policy', + 'pmsh_control_loop_name', 'LOCKED') + subscription_model.network_filter = nf_filter + subscription_model.measurement_groups = mg_list + return subscription_model + + class BaseClassSetup(TestCase): app = None app_context = None diff --git a/components/pm-subscription-handler/tests/test_controller.py b/components/pm-subscription-handler/tests/test_controller.py index a3a28163..7bd72a29 100755 --- a/components/pm-subscription-handler/tests/test_controller.py +++ b/components/pm-subscription-handler/tests/test_controller.py @@ -18,14 +18,15 @@ import json import os from unittest.mock import patch, MagicMock -import responses -from requests import Session +from http import HTTPStatus + from mod import aai_client -from mod.api.controller import status, get_all_sub_to_nf_relations, post_subscription +from mod.api.controller import status, post_subscription, get_subscription_by_name from tests.base_setup import BaseClassSetup from mod.api.db_models import SubscriptionModel, NfMeasureGroupRelationalModel from mod.subscription import SubNfState from mod.network_function import NetworkFunctionFilter +from tests.base_setup import subscription_data class ControllerTestCase(BaseClassSetup): @@ -55,26 +56,6 @@ class ControllerTestCase(BaseClassSetup): def test_status_response_healthy(self): self.assertEqual(status()['status'], 'healthy') - @patch.object(Session, 'get') - @patch.object(Session, 'put') - def test_get_all_sub_to_nf_relations(self, mock_put_session, mock_get_session): - mock_put_session.return_value.status_code = 200 - mock_put_session.return_value.text = self.aai_response_data - mock_get_session.return_value.status_code = 200 - mock_get_session.return_value.text = self.good_model_info - responses.add(responses.GET, - 'https://aai:8443/aai/v20/service-design-and-creation/models/model/' - '7129e420-d396-4efb-af02-6b83499b12f8/model-vers/model-ver/' - 'e80a6ae3-cafd-4d24-850d-e14c084a5ca9', - json=json.loads(self.good_model_info), status=200) - self.xnfs = aai_client.get_pmsh_nfs_from_aai(self.app_conf, self.app_conf.nf_filter) - sub_model = self.app_conf.subscription.get() - for nf in self.xnfs: - self.app_conf.subscription.add_network_function_to_subscription(nf, sub_model) - all_subs = get_all_sub_to_nf_relations() - self.assertEqual(len(all_subs[0]['network_functions']), 3) - self.assertEqual(all_subs[0]['subscription_name'], 'ExtraPM-All-gNB-R2B') - def create_test_subs(self, new_sub_name, new_msrmt_grp_name): subscription = self.subscription_request.replace('ExtraPM-All-gNB-R2B', new_sub_name) subscription = subscription.replace('msrmt_grp_name', new_msrmt_grp_name) @@ -129,3 +110,31 @@ class ControllerTestCase(BaseClassSetup): response = post_subscription(subscription) self.assertEqual(response[1], 400) self.assertEqual(response[0], 'No value provided in subscription name') + + @patch('mod.api.services.subscription_service.get_subscription_by_name', + MagicMock(return_value=subscription_data('sub_demo'))) + def test_get_subscription_by_name_api(self): + sub, status_code = get_subscription_by_name('sub_demo') + self.assertEqual(status_code, HTTPStatus.OK) + self.assertEqual(sub['subscription']['subscriptionName'], 'sub_demo') + self.assertEqual(sub['subscription']['nfFilter']['nfNames'], + ['^pnf.*', '^vnf.*']) + self.assertEqual(sub['subscription']['controlLoopName'], + 'pmsh_control_loop_name') + self.assertEqual(len(sub['subscription']['measurementGroups']), 2) + self.assertEqual(sub['subscription']['operationalPolicyName'], + 'pmsh_operational_policy') + + @patch('mod.api.services.subscription_service.get_subscription_by_name', + MagicMock(return_value=None)) + def test_get_subscription_by_name_api_error(self): + sub, status_code = get_subscription_by_name('sub_demo') + self.assertEqual(status_code, HTTPStatus.NOT_FOUND) + self.assertEqual(sub['error'], + 'Subscription was not defined with the name : sub_demo') + + @patch('mod.api.services.subscription_service.get_subscription_by_name', + MagicMock(side_effect=Exception('something failed'))) + def test_get_subscription_by_name_api_exception(self): + sub, status_code = get_subscription_by_name('sub_demo') + self.assertEqual(status_code, HTTPStatus.INTERNAL_SERVER_ERROR) diff --git a/components/pm-subscription-handler/tests/test_subscription.py b/components/pm-subscription-handler/tests/test_subscription.py index 538baf39..5c40c4fd 100755 --- a/components/pm-subscription-handler/tests/test_subscription.py +++ b/components/pm-subscription-handler/tests/test_subscription.py @@ -75,12 +75,6 @@ class SubscriptionTest(BaseClassSetup): self.app_conf.subscription.add_network_function_to_subscription(list(self.xnfs)[1], self.sub_model) - def test_create_existing_subscription(self): - sub1 = self.app_conf.subscription.create() - same_sub1 = self.app_conf.subscription.create() - self.assertEqual(sub1, same_sub1) - self.assertEqual(1, len(self.app_conf.subscription.get_all())) - def test_add_duplicate_network_functions_per_subscription(self): self.app_conf.subscription.add_network_function_to_subscription(list(self.xnfs)[0], self.sub_model) |