PyExecutor ResourceResolution store/retrieve templates
[ccsdk/cds.git] / ms / py-executor / resource_resolution / tests / http_client_test.py
1 """Copyright 2020 Deutsche Telekom.
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7     http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 """
15
16 from unittest.mock import MagicMock, patch
17
18 from resource_resolution.http.client import Client
19
20
21 @patch("resource_resolution.http.client.request")
22 def test_http_client(request_mock):
23     c = Client("127.0.0.1", 8080)
24     assert c.auth is None
25     c = Client("127.0.0.1", 8080, auth_user="user")
26     assert c.auth is None
27     c = Client("127.0.0.1", 8080, auth_user="user", auth_pass="pass")
28     assert c.auth == ("user", "pass")
29
30     assert c.protocol == "http"
31     assert c.url == "http://127.0.0.1:8080/api/v1"
32
33     c = Client("127.0.0.1", 8081, use_ssl=True)
34     assert c.protocol == "https"
35     assert c.url == "https://127.0.0.1:8081/api/v1"
36
37     c.send_request("GET", "something")
38     request_mock.assert_called_once_with(method="GET", url=f"{c.url}/something", verify=False, auth=None)