1 # ============LICENSE_START===================================================
2 # Copyright (C) 2019-2020 Nordix Foundation.
3 # ============================================================================
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # SPDX-License-Identifier: Apache-2.0
17 # ============LICENSE_END=====================================================
20 from unittest.mock import patch
23 from requests import Session
25 from mod import aai_client
26 from mod.api.controller import status, get_all_sub_to_nf_relations
27 from tests.base_setup import BaseClassSetup
30 class ControllerTestCase(BaseClassSetup):
38 with open(os.path.join(os.path.dirname(__file__), 'data/aai_xnfs.json'), 'r') as data:
39 self.aai_response_data = data.read()
40 with open(os.path.join(os.path.dirname(__file__), 'data/aai_model_info.json'), 'r') as data:
41 self.good_model_info = data.read()
47 def tearDownClass(cls):
48 super().tearDownClass()
50 def test_status_response_healthy(self):
51 self.assertEqual(status()['status'], 'healthy')
53 @patch.object(Session, 'get')
54 @patch.object(Session, 'put')
55 def test_get_all_sub_to_nf_relations(self, mock_put_session, mock_get_session):
56 mock_put_session.return_value.status_code = 200
57 mock_put_session.return_value.text = self.aai_response_data
58 mock_get_session.return_value.status_code = 200
59 mock_get_session.return_value.text = self.good_model_info
60 responses.add(responses.GET,
61 'https://aai:8443/aai/v20/service-design-and-creation/models/model/'
62 '7129e420-d396-4efb-af02-6b83499b12f8/model-vers/model-ver/'
63 'e80a6ae3-cafd-4d24-850d-e14c084a5ca9',
64 json=json.loads(self.good_model_info), status=200)
65 self.xnfs = aai_client.get_pmsh_nfs_from_aai(self.app_conf)
66 sub_model = self.app_conf.subscription.get()
68 self.app_conf.subscription.add_network_function_to_subscription(nf, sub_model)
69 all_subs = get_all_sub_to_nf_relations()
70 self.assertEqual(len(all_subs[0]['network_functions']), 3)
71 self.assertEqual(all_subs[0]['subscription_name'], 'ExtraPM-All-gNB-R2B')