def update_filter(sub_name, nf_filter): """ Updates the network function filter for the subscription Args: sub_name (String): Name of the Subscription nf_filter (dict): filter object to update in the subscription Returns: InvalidDataException: contains details on invalid fields DataConflictException: contains details on conflicting state of a field Exception: contains runtime error details """ sub_model = query_subscription_by_name(sub_name) if sub_model is None: raise InvalidDataException('Requested subscription is not available ' f'with sub name: {sub_name} for nf filter update') if is_duplicate_filter(nf_filter, sub_model.network_filter): raise InvalidDataException('Duplicate nf filter update requested for subscription ' f'with sub name: {sub_name}') validate_sub_mgs_state(sub_model) nf_service.save_nf_filter_update(sub_name, nf_filter) del_nfs, new_nfs = extract_del_new_nfs(sub_model) NfSubRelationalModel.query.filter( NfSubRelationalModel.subscription_name == sub_name, NfSubRelationalModel.nf_name.in_(del_nfs)).delete() db.session.commit() unlocked_mgs = get_unlocked_measurement_grps(sub_model) if unlocked_mgs: add_new_filtered_nfs(new_nfs, unlocked_mgs, sub_model) delete_filtered_nfs(del_nfs, sub_model, unlocked_mgs) db.session.remove()
def update_admin_status(measurement_group, status): """ Performs administrative status updates for the measurement group Args: measurement_group (MeasurementGroupModel): Measurement group to update status (string): Admin status to update for measurement group Raises: InvalidDataException: contains details on invalid fields DataConflictException: contains details on conflicting state of a field Exception: contains runtime error details """ if measurement_group is None: raise InvalidDataException('Requested measurement group not available ' 'for admin status update') elif measurement_group.administrative_state == AdministrativeState.LOCKING.value: raise DataConflictException( 'Cannot update admin status as Locked request is in progress' f' for sub name: {measurement_group.subscription_name} and ' f'meas group name: {measurement_group.measurement_group_name}') elif measurement_group.administrative_state == status: raise InvalidDataException( f'Measurement group is already in {status} state ' f'for sub name: {measurement_group.subscription_name} and ' f'meas group name: {measurement_group.measurement_group_name}') else: sub_model = SubscriptionModel.query.filter( SubscriptionModel.subscription_name == measurement_group.subscription_name) \ .one_or_none() nf_meas_relations = NfMeasureGroupRelationalModel.query.filter( NfMeasureGroupRelationalModel.measurement_grp_name == measurement_group.measurement_group_name).all() if nf_meas_relations and status == AdministrativeState.LOCKED.value: status = AdministrativeState.LOCKING.value measurement_group.administrative_state = status db.session.commit() if status == AdministrativeState.LOCKING.value: deactivate_nfs(sub_model, measurement_group, nf_meas_relations) elif status == AdministrativeState.UNLOCKED.value: activate_nfs(sub_model, measurement_group)
def check_missing_data(subscription): """ checks if the subscription request has missing data Args: subscription (dict): subscription to validate Raises: InvalidDataException: exception containing the list of invalid data. """ if subscription['subscriptionName'].strip() in (None, ''): raise InvalidDataException("No value provided in subscription name") if subscription['operationalPolicyName'].strip() in (None, ''): raise InvalidDataException("Value required for operational Policy Name") for measurement_group in subscription.get('measurementGroups'): measurement_group_details = measurement_group['measurementGroup'] if measurement_group_details['administrativeState'].strip() in (None, ''): raise InvalidDataException("No value provided for administrative state") if measurement_group_details['measurementGroupName'].strip() in (None, ''): raise InvalidDataException("No value provided for measurement group name")
def validate_nf_filter(nf_filter): """ checks if the nf filter is valid Args: nf_filter (dict): nf filter to validate Raises: InvalidDataException: if no field is available in nf_filter """ for filter_name, filter_values in nf_filter.items(): filter_values[:] = [x for x in filter_values if x.strip()] if not [filter_name for filter_name, val in nf_filter.items() if len(val) > 0]: raise InvalidDataException("At least one filter within nfFilter must not be empty")
def test_create_subscription_service_on_aai_failed(self, mock_filter_call, mock_aai): mock_aai.side_effect = InvalidDataException(["AAI call failed"]) subscription = self.create_test_subs('xtraPM-All-gNB-R2B-fail', 'msrmt_grp_name-fail') subscription = json.loads(subscription)['subscription'] mock_filter_call.return_value = NetworkFunctionFilter( **subscription["nfFilter"]) try: subscription_service.create_subscription(subscription) except InvalidDataException as exception: self.assertEqual(exception.args[0], ["AAI call failed"]) # Checking Rollback on AAI failure with subscription request saved existing_subscription = (SubscriptionModel.query.filter( SubscriptionModel.subscription_name == 'xtraPM-All-gNB-R2B-fail').one_or_none()) self.assertIsNotNone(existing_subscription)
def test_create_subscription_service_failed_rollback( self, mock_filter_call, mock_model_aai, mock_aai, mock_publish): mock_aai.return_value = json.loads(self.aai_response_data) mock_model_aai.return_value = json.loads(self.good_model_info) mock_publish.side_effect = InvalidDataException(["publish failed"]) subscription = self.create_test_subs('xtraPM-All-gNB-R2B-fail1', 'msrmt_grp_name-fail1') subscription = json.loads(subscription)['subscription'] mock_filter_call.return_value = NetworkFunctionFilter( **subscription["nfFilter"]) try: subscription_service.create_subscription(subscription) except InvalidDataException as exception: self.assertEqual(exception.args[0], ["AAI call failed"]) # Checking Rollback on publish failure with subscription and nfs captured existing_subscription = (SubscriptionModel.query.filter( SubscriptionModel.subscription_name == 'xtraPM-All-gNB-R2B-fail1').one_or_none()) self.assertIsNotNone(existing_subscription) saved_nf_sub_rel = (NfSubRelationalModel.query.filter( NfSubRelationalModel.subscription_name == 'xtraPM-All-gNB-R2B-fail1')) self.assertIsNotNone(saved_nf_sub_rel)
class ControllerTestCase(BaseClassSetup): def setUp(self): super().setUp() with open( os.path.join(os.path.dirname(__file__), 'data/aai_xnfs.json'), 'r') as data: self.aai_response_data = data.read() with open( os.path.join(os.path.dirname(__file__), 'data/aai_model_info.json'), 'r') as data: self.good_model_info = data.read() with open( os.path.join(os.path.dirname(__file__), 'data/create_subscription_request.json'), 'r') as data: self.subscription_request = data.read() def test_status_response_healthy(self): self.assertEqual(status()['status'], 'healthy') 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) return subscription @patch('mod.api.services.subscription_service.save_nf_filter', MagicMock(return_value=None)) @patch('mod.pmsh_config.AppConfig.publish_to_topic', MagicMock(return_value=None)) @patch.object(aai_client, '_get_all_aai_nf_data') @patch.object(aai_client, 'get_aai_model_data') @patch.object(NetworkFunctionFilter, 'get_network_function_filter') def test_post_subscription(self, mock_filter_call, mock_model_aai, mock_aai): mock_aai.return_value = json.loads(self.aai_response_data) mock_model_aai.return_value = json.loads(self.good_model_info) subscription = self.create_test_subs('xtraPM-All-gNB-R2B-post', 'msrmt_grp_name-post') subscription = json.loads(subscription) mock_filter_call.return_value = NetworkFunctionFilter( **subscription['subscription']["nfFilter"]) sub_name = subscription['subscription']['subscriptionName'] mes_grp = subscription['subscription']['measurementGroups'][0][ 'measurementGroup'] mes_grp_name = mes_grp['measurementGroupName'] response = post_subscription(subscription) subscription = (SubscriptionModel.query.filter( SubscriptionModel.subscription_name == sub_name).one_or_none()) self.assertIsNotNone(subscription) msr_grp_nf_rel = (NfMeasureGroupRelationalModel.query.filter( NfMeasureGroupRelationalModel.measurement_grp_name == mes_grp_name) ).all() for published_event in msr_grp_nf_rel: self.assertEqual(published_event.nf_measure_grp_status, MgNfState.PENDING_CREATE.value) self.assertEqual(response[1], 201) def test_post_subscription_duplicate_sub(self): # Posting the same subscription request stored in previous test to get duplicate response subscription = create_subscription_data('ExtraPM-All-gNB-R2B') db.session.add(subscription) db.session.commit() response = post_subscription(json.loads(self.subscription_request)) self.assertEqual(response[1], 409) self.assertEqual( response[0], 'subscription Name: ExtraPM-All-gNB-R2B already exists.') def test_post_subscription_invalid_filter(self): subscription = self.create_test_subs('xtraPM-All-gNB-R2B-invalid', 'msrmt_grp_name-invalid') subscription = json.loads(subscription) subscription['subscription']['nfFilter']['nfNames'] = [] subscription['subscription']['nfFilter']['modelInvariantIDs'] = [] subscription['subscription']['nfFilter']['modelVersionIDs'] = [] subscription['subscription']['nfFilter']['modelNames'] = [] response = post_subscription(subscription) self.assertEqual(response[1], 400) self.assertEqual( response[0], 'At least one filter within nfFilter must not be empty') def test_post_subscription_missing(self): subscription = json.loads(self.subscription_request) subscription['subscription']['subscriptionName'] = '' 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.query_subscription_by_name', MagicMock(return_value=create_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.value) 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.query_subscription_by_name', MagicMock(return_value=None)) def test_get_subscription_by_name_api_none(self): sub, status_code = get_subscription_by_name('sub_demo') self.assertEqual(status_code, HTTPStatus.NOT_FOUND.value) self.assertEqual( sub['error'], 'Subscription was not defined with the name : sub_demo') @patch('mod.api.services.subscription_service.query_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.value) @patch('mod.api.services.subscription_service.query_all_subscriptions', MagicMock(return_value=create_multiple_subscription_data( ['sub_demo_one', 'sub_demo_two']))) def test_get_subscriptions_api(self): subs, status_code = get_subscriptions() self.assertEqual(status_code, HTTPStatus.OK.value) self.assertEqual(subs[0]['subscription']['subscriptionName'], 'sub_demo_one') self.assertEqual(subs[1]['subscription']['subscriptionName'], 'sub_demo_two') self.assertEqual( subs[1]['subscription']['measurementGroups'][0]['measurementGroup'] ['measurementGroupName'], 'MG1') self.assertEqual(len(subs[1]['subscription']['measurementGroups']), 2) self.assertEqual(subs[0]['subscription']['nfs'][0], 'pnf_101') self.assertEqual(subs[0]['subscription']['nfs'][1], 'pnf_102') self.assertEqual(subs[1]['subscription']['nfs'], []) self.assertEqual(len(subs), 2) @patch('mod.api.services.subscription_service.query_all_subscriptions', MagicMock(return_value=None)) def test_get_subscriptions_api_none(self): subs, status_code = get_subscriptions() self.assertEqual(status_code, HTTPStatus.OK.value) self.assertEqual(subs, []) @patch('mod.api.services.subscription_service.query_all_subscriptions', MagicMock(side_effect=Exception('something failed'))) def test_get_subscriptions_api_exception(self): subs, status_code = get_subscriptions() self.assertEqual(status_code, HTTPStatus.INTERNAL_SERVER_ERROR.value) def test_get_meas_group_with_nfs_api(self): sub = create_subscription_data('sub1') nf_list = create_multiple_network_function_data(['pnf101', 'pnf102']) measurement_group_service.save_measurement_group( sub.measurement_groups[0].serialize()['measurementGroup'], sub.subscription_name) for nf in nf_list: nf_service.save_nf(nf) measurement_group_service. \ apply_nf_status_to_measurement_group(nf.nf_name, sub.measurement_groups[0]. measurement_group_name, MgNfState.PENDING_CREATE.value) db.session.commit() mg_with_nfs, status_code = get_meas_group_with_nfs('sub1', 'MG1') self.assertEqual(status_code, HTTPStatus.OK.value) self.assertEqual(mg_with_nfs['subscriptionName'], 'sub1') self.assertEqual(mg_with_nfs['measurementGroupName'], 'MG1') self.assertEqual(mg_with_nfs['administrativeState'], 'UNLOCKED') self.assertEqual(len(mg_with_nfs['networkFunctions']), 2) def test_get_meas_group_with_nfs_api_none(self): error, status_code = get_meas_group_with_nfs('sub1', 'MG1') self.assertEqual( error['error'], 'measurement group was not defined with ' 'the sub name: sub1 and meas group name: MG1') self.assertEqual(status_code, HTTPStatus.NOT_FOUND.value) @patch( 'mod.api.services.measurement_group_service.query_meas_group_by_name', MagicMock(side_effect=Exception('something failed'))) def test_get_meas_group_with_nfs_api_exception(self): error, status_code = get_meas_group_with_nfs('sub1', 'MG1') self.assertEqual(status_code, HTTPStatus.INTERNAL_SERVER_ERROR.value) @patch.object(aai_client, '_get_all_aai_nf_data') @patch.object(aai_client, 'get_aai_model_data') def test_post_meas_group(self, mock_model_aai, mock_aai): mock_aai.return_value = json.loads(self.aai_response_data) mock_model_aai.return_value = json.loads(self.good_model_info) subscription_data = create_subscription_data('Post_MG') measurement_grp = { 'measurementGroup': { 'measurementGroupName': 'MG2', 'administrativeState': 'UNLOCKED', 'fileBasedGP': 15, 'fileLocation': '/pm/pm.xml', 'measurementTypes': '[{ "measurementType": "countera" }, ' '{ "measurementType": "counterb" }]', 'managedObjectDNsBasic': '[{ "DN":"dna"},{"DN":"dnb"}]' } } db.session.add(subscription_data) db.session.commit() db.session.remove() _, status_code = post_meas_group('Post_MG', 'MG3', measurement_grp) self.assertEqual(status_code, 201) def test_post_meas_group_with_duplicate(self): subscription_data = create_subscription_data('Post_MG') measurement_grp = MeasurementGroupModel( 'Post_MG', 'MG1', 'UNLOCKED', 15, '/pm/pm.xml', '[{ "measurementType": "countera" }, ' '{ "measurementType": "counterb" }]', '[{ "DN":"dna"},{"DN":"dnb"}]') db.session.add(subscription_data) db.session.commit() db.session.remove() _, status_code = post_meas_group('Post_MG', 'MG1', measurement_grp) self.assertEqual(status_code, 409) def test_delete_sub_when_state_unlocked(self): subscription_unlocked_data = create_subscription_data('MG_unlocked') subscription_unlocked_data.measurement_groups[ 0].measurement_group_name = 'unlock' subscription_unlocked_data.measurement_groups[ 0].administrative_state = 'UNLOCKED' db.session.add(subscription_unlocked_data) db.session.add(subscription_unlocked_data.measurement_groups[0]) db.session.commit() db.session.remove() message, status_code = delete_subscription_by_name('MG_unlocked') self.assertEqual(status_code, HTTPStatus.CONFLICT.value) self.assertEqual( subscription_service.query_subscription_by_name( 'MG_unlocked').subscription_name, 'MG_unlocked') def test_delete_mg_when_state_unlocked(self): subscription_unlocked_data = create_subscription_data('MG_unlocked') db.session.add(subscription_unlocked_data) db.session.commit() db.session.remove() message, status_code = delete_meas_group_by_name('MG_unlocked', 'MG1') self.assertEqual(status_code, HTTPStatus.CONFLICT.value) self.assertEqual( query_meas_group_by_name('MG_unlocked', 'MG1').measurement_group_name, 'MG1') def test_delete_sub_when_state_locked(self): subscription_unlocked_data = create_subscription_data('MG_locked') subscription_unlocked_data.measurement_groups[ 0].measurement_group_name = 'lock' subscription_unlocked_data.measurement_groups[ 0].administrative_state = 'LOCKED' db.session.add(subscription_unlocked_data) db.session.add(subscription_unlocked_data.measurement_groups[0]) db.session.commit() db.session.remove() none_type, status_code = delete_subscription_by_name('MG_locked') self.assertEqual(none_type, None) self.assertEqual(status_code, HTTPStatus.NO_CONTENT.value) self.assertEqual( subscription_service.query_subscription_by_name('MG_locked'), None) def test_delete_mg_when_state_locked(self): subscription_locked_data = create_subscription_data('MG_locked') subscription_locked_data.measurement_groups[ 0].administrative_state = 'LOCKED' db.session.add(subscription_locked_data) db.session.add(subscription_locked_data.measurement_groups[0]) db.session.commit() db.session.remove() non_type, status_code = delete_meas_group_by_name('MG_locked', 'MG1') self.assertEqual(non_type, None) self.assertEqual(status_code, HTTPStatus.NO_CONTENT.value) self.assertEqual(query_meas_group_by_name('MG_locked', 'MG1'), None) def test_delete_sub_when_state_locking(self): subscription_locking_data = create_subscription_data('MG_locking') subscription_locking_data.measurement_groups[ 0].measurement_group_name = 'locking' subscription_locking_data.measurement_groups[ 0].administrative_state = 'LOCKING' db.session.add(subscription_locking_data) db.session.add(subscription_locking_data.measurement_groups[0]) db.session.commit() db.session.remove() message, status_code = delete_subscription_by_name('MG_locking') self.assertEqual(status_code, HTTPStatus.CONFLICT.value) self.assertEqual( subscription_service.query_subscription_by_name( 'MG_locking').subscription_name, 'MG_locking') def test_delete_mg_when_state_locking(self): subscription_locking_data = create_subscription_data('MG_locking') subscription_locking_data.measurement_groups[ 0].administrative_state = 'LOCKING' db.session.add(subscription_locking_data) db.session.add(subscription_locking_data.measurement_groups[0]) db.session.commit() db.session.remove() message, status_code = delete_meas_group_by_name('MG_locking', 'MG1') self.assertEqual(status_code, HTTPStatus.CONFLICT.value) self.assertEqual( query_meas_group_by_name('MG_locking', 'MG1').measurement_group_name, 'MG1') def test_delete_sub_none(self): message, status_code = delete_subscription_by_name('None') self.assertEqual(message['error'], 'Subscription is not defined with name None') self.assertEqual(status_code, HTTPStatus.NOT_FOUND.value) def test_delete_mg_exception(self): subscription_locking_data = create_subscription_data('MG_locking') message, status_code = delete_meas_group_by_name( subscription_locking_data, 'None') self.assertEqual(status_code, HTTPStatus.INTERNAL_SERVER_ERROR.value) @patch( 'mod.api.services.subscription_service.query_to_delete_subscription_by_name', MagicMock(side_effect=Exception('something failed'))) def test_delete_sub_exception(self): error, status_code = delete_subscription_by_name('None') self.assertEqual(status_code, HTTPStatus.INTERNAL_SERVER_ERROR.value) @patch('mod.pmsh_config.AppConfig.publish_to_topic', MagicMock(return_value=None)) def test_update_admin_state_api_for_locked_update(self): sub = create_subscription_data('sub1') nf_list = create_multiple_network_function_data(['pnf_101', 'pnf_102']) db.session.add(sub) for nf in nf_list: nf_service.save_nf(nf) measurement_group_service. \ apply_nf_status_to_measurement_group(nf.nf_name, sub.measurement_groups[0]. measurement_group_name, MgNfState.CREATED.value) db.session.commit() response = update_admin_state('sub1', 'MG1', {'administrativeState': 'LOCKED'}) self.assertEqual(response[1], HTTPStatus.OK.value) self.assertEqual(response[0], 'Successfully updated admin state') mg_with_nfs, status_code = get_meas_group_with_nfs('sub1', 'MG1') self.assertEqual(mg_with_nfs['subscriptionName'], 'sub1') self.assertEqual(mg_with_nfs['measurementGroupName'], 'MG1') self.assertEqual(mg_with_nfs['administrativeState'], 'LOCKING') for nf in mg_with_nfs['networkFunctions']: self.assertEqual(nf['nfMgStatus'], MgNfState.PENDING_DELETE.value) @patch('mod.pmsh_config.AppConfig.publish_to_topic', MagicMock(return_value=None)) @patch.object(aai_client, '_get_all_aai_nf_data') @patch.object(aai_client, 'get_aai_model_data') @patch.object(NetworkFunctionFilter, 'get_network_function_filter') def test_update_admin_state_api_for_unlocked_update( self, mock_filter_call, mock_model_aai, mock_aai): mock_aai.return_value = json.loads(self.aai_response_data) mock_model_aai.return_value = json.loads(self.good_model_info) sub = create_subscription_data('sub1') db.session.add(sub) nf_list = create_multiple_network_function_data(['pnf_101', 'pnf_102']) for network_function in nf_list: db.session.add(network_function) db.session.commit() mock_filter_call.return_value = NetworkFunctionFilter.get_network_function_filter( 'sub') response = update_admin_state('sub1', 'MG2', {'administrativeState': 'UNLOCKED'}) self.assertEqual(response[1], HTTPStatus.OK.value) self.assertEqual(response[0], 'Successfully updated admin state') mg_with_nfs, status_code = get_meas_group_with_nfs('sub1', 'MG2') self.assertEqual(mg_with_nfs['subscriptionName'], 'sub1') self.assertEqual(mg_with_nfs['measurementGroupName'], 'MG2') self.assertEqual(mg_with_nfs['administrativeState'], 'UNLOCKED') for nf in mg_with_nfs['networkFunctions']: self.assertEqual(nf['nfMgStatus'], MgNfState.PENDING_CREATE.value) @patch('mod.api.services.measurement_group_service.update_admin_status', MagicMock(side_effect=InvalidDataException('Bad request'))) def test_update_admin_state_api_invalid_data_exception(self): error, status_code = update_admin_state( 'sub4', 'MG2', {'administrativeState': 'UNLOCKED'}) self.assertEqual(status_code, HTTPStatus.BAD_REQUEST.value) self.assertEqual(error, 'Bad request') @patch('mod.api.services.measurement_group_service.update_admin_status', MagicMock(side_effect=DataConflictException('Data conflict'))) def test_update_admin_state_api_data_conflict_exception(self): error, status_code = update_admin_state( 'sub4', 'MG2', {'administrativeState': 'UNLOCKED'}) self.assertEqual(status_code, HTTPStatus.CONFLICT.value) self.assertEqual(error, 'Data conflict') @patch('mod.api.services.measurement_group_service.update_admin_status', MagicMock(side_effect=Exception('Server Error'))) def test_update_admin_state_api_exception(self): error, status_code = update_admin_state( 'sub4', 'MG2', {'administrativeState': 'UNLOCKED'}) self.assertEqual(status_code, HTTPStatus.INTERNAL_SERVER_ERROR.value) self.assertEqual( error, 'Update admin status request was not processed for sub name: sub4 ' 'and meas group name: MG2 due to Exception : Server Error') @patch('mod.api.services.subscription_service.update_filter', MagicMock(return_value=None)) def test_put_nf_filter(self): response = put_nf_filter( 'sub1', json.loads('{"nfNames": ["^pnf.*", "^vnf.*"]}')) self.assertEqual(response[0], 'Successfully updated network function Filter') self.assertEqual(response[1], HTTPStatus.OK.value) @patch('mod.api.services.subscription_service.update_filter', MagicMock(side_effect=InvalidDataException('Bad request'))) def test_put_nf_filter_api_invalid_data_exception(self): error, status_code = put_nf_filter( 'sub1', json.loads('{"nfNames": ["^pnf.*", "^vnf.*"]}')) self.assertEqual(status_code, HTTPStatus.BAD_REQUEST.value) self.assertEqual(error, 'Bad request') @patch('mod.api.services.subscription_service.update_filter', MagicMock(side_effect=DataConflictException('Data conflict'))) def test_put_nf_filter_api_data_conflict_exception(self): error, status_code = put_nf_filter( 'sub1', json.loads('{"nfNames": ["^pnf.*", "^vnf.*"]}')) self.assertEqual(status_code, HTTPStatus.CONFLICT.value) self.assertEqual(error, 'Data conflict') @patch('mod.api.services.subscription_service.update_filter', MagicMock(side_effect=Exception('Server Error'))) def test_put_nf_filter_api_exception(self): error, status_code = put_nf_filter( 'sub1', json.loads('{"nfNames": ["^pnf.*", "^vnf.*"]}')) self.assertEqual(status_code, HTTPStatus.INTERNAL_SERVER_ERROR.value) self.assertEqual( error, 'Update nf filter request was not processed for sub name: sub1 ' 'due to Exception : Server Error')