1 # -------------------------------------------------------------------------
2 # Copyright (c) 2017-2018 AT&T Intellectual Property
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 requests.models import Response
22 from osdf.utils.interfaces import RestClient, get_rest_client
23 from unittest.mock import patch
27 m1._content = b'{"msg": "OK"}'
29 mock_good_response = m1
32 m2._content = b'{"msg": "Not-OK"}'
34 mock_bad_response = m2
37 class TestOsdfUtilsInterfaces(unittest.TestCase):
38 @patch('requests.request', return_value=mock_good_response)
39 def test_rc_request(self, mock_good_response):
42 rc.request(req_id="testReq")
44 @patch('requests.request', return_value=mock_good_response)
45 def test_rc_request_v1(self, mock_good_response):
48 rc.request(url="http://localhost", asjson=False, log_func=lambda x: None)
49 rc.request(url="http://localhost", raw_response=True)
50 rc.request(url="http://localhost", no_response=True)
52 @patch('requests.request', return_value=mock_bad_response)
53 def test_rc_request_v2(self, mock_bad_response):
57 except requests.RequestException:
59 raise Exception("Allows bad requests instead of raising exception")
61 def test_get_rest_client(self):
62 request_json = {"requestInfo": {"callbackUrl": "http://localhost"}}
64 get_rest_client(request_json, service)
67 if __name__ == "__main__":