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 # -------------------------------------------------------------------------
19 from requests.models import Response
21 from unittest.mock import patch
23 from osdf.utils.interfaces import get_rest_client
24 from osdf.utils.interfaces import RestClient
28 m1._content = b'{"msg": "OK"}'
30 mock_good_response = m1
33 m2._content = b'{"msg": "Not-OK"}'
35 mock_bad_response = m2
38 class TestOsdfUtilsInterfaces(unittest.TestCase):
39 @patch('requests.request', return_value=mock_good_response)
40 def test_rc_request(self, mock_good_response):
43 rc.request(url="http://localhost", req_id="testReq")
45 @patch('requests.request', return_value=mock_good_response)
46 def test_rc_request_v1(self, mock_good_response):
49 rc.request(url="http://localhost", asjson=False, log_func=lambda x: None)
50 rc.request(url="http://localhost", raw_response=True)
51 rc.request(url="http://localhost", no_response=True)
53 @patch('requests.request', return_value=mock_bad_response)
54 def test_rc_request_v2(self, mock_bad_response):
57 rc.request(url="http://localhost")
58 except requests.RequestException:
60 raise Exception("Allows bad requests instead of raising exception")
62 def test_get_rest_client(self):
63 request_json = {"requestInfo": {"callbackUrl": "http://localhost"}}
65 get_rest_client(request_json, service)
68 if __name__ == "__main__":