1 # -------------------------------------------------------------------------
2 # Copyright (C) 2020 Wipro Limited.
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 # -------------------------------------------------------------------------
21 from unittest.mock import patch
22 from osdf.config.base import osdf_config
23 import osdf.config.loader as config_loader
24 from osdf.utils.programming_utils import DotDict
25 from osdf.utils.interfaces import json_from_file
26 from osdf.adapters.aai.fetch_aai_data import get_aai_data,AAIException
28 class TestRemoteOptProcessor(unittest.TestCase):
31 "deployment": "config/osdf_config.yaml",
32 "core": "config/common_config.yaml"
34 self.osdf_config = DotDict(config_loader.all_configs(**self.config_spec))
41 def test_get_aai_data(self):
43 response_file = main_dir + 'test/apps/nxi_termination/aai_response.json'
44 exception_response_file = main_dir + 'test/apps/nxi_termination/aai_exception_response.json'
45 request_file = main_dir + 'test/apps/nxi_termination/nxi_termination.json'
46 response_json = json_from_file(response_file)
47 request_json = json_from_file(request_file)
48 exception_json = json_from_file(exception_response_file)
49 response = mock.MagicMock()
50 response.status_code = 200
52 response.json.return_value = response_json
53 self.patcher_req = patch('requests.get',
54 return_value = response)
55 self.Mock_req = self.patcher_req.start()
56 self.assertEquals(response_json, get_aai_data(request_json,osdf_config))
57 self.patcher_req.stop()
59 responsenew=mock.MagicMock()
60 responsenew.status_code=404
61 responsenew.json.return_value = exception_json
62 self.patcher_req = patch('requests.get',
63 return_value=responsenew)
64 self.Mock_req = self.patcher_req.start()
65 self.assertRaises( AAIException,get_aai_data,request_json,osdf_config)
66 self.patcher_req.stop()
69 if __name__ == "__main__":