|
21 | 21 | import time
|
22 | 22 | from email.utils import formatdate
|
23 | 23 |
|
24 |
| -import six |
25 | 24 | import mock
|
26 | 25 | import pytest
|
27 | 26 | import requests
|
| 27 | +import six |
28 | 28 |
|
29 | 29 | from conftest import mock_connection_params, MockResponse
|
30 |
| -from umapi_client import Connection, UnavailableError, ServerError, RequestError, UserAction, GroupTypes, \ |
31 |
| - IdentityTypes, RoleTypes |
| 30 | + |
| 31 | +from umapi_client import Connection |
| 32 | +from umapi_client import ArgumentError, UnavailableError, ServerError, RequestError |
| 33 | +from umapi_client import UserAction, GroupTypes, IdentityTypes, RoleTypes |
32 | 34 | from umapi_client import __version__ as umapi_version
|
| 35 | +from umapi_client.auth import Auth |
33 | 36 |
|
34 | 37 |
|
35 | 38 | def test_remote_status_success():
|
@@ -78,6 +81,35 @@ def test_ua_string_additional():
|
78 | 81 | assert ua_header.startswith("additional/1.0 umapi-client/" + umapi_version)
|
79 | 82 |
|
80 | 83 |
|
| 84 | +def test_mock_proxy_get(): |
| 85 | + with mock.patch("umapi_client.connection.requests.Session.get") as mock_get: |
| 86 | + mock_get.return_value = MockResponse(200, body=["test", "body"]) |
| 87 | + with mock.patch("umapi_client.connection.os.getenv") as mock_getenv: |
| 88 | + mock_getenv.return_value = "proxy" |
| 89 | + conn = Connection(**mock_connection_params) |
| 90 | + conn.make_call("").json() |
| 91 | + mock_get.assert_called_with('http://test/', auth='N/A', timeout=120.0) |
| 92 | + |
| 93 | + |
| 94 | +def test_mock_playback_get(): |
| 95 | + with mock.patch("umapi_client.connection.requests.Session.get") as mock_get: |
| 96 | + mock_get.return_value = MockResponse(200, body=["test", "body"]) |
| 97 | + with mock.patch("umapi_client.connection.os.getenv") as mock_getenv: |
| 98 | + mock_getenv.return_value = "playback" |
| 99 | + conn = Connection(**mock_connection_params) |
| 100 | + conn.make_call("").json() |
| 101 | + assert mock_get.call_args[0][0] == 'http://test/' |
| 102 | + assert isinstance(mock_get.call_args[1]['auth'], Auth) |
| 103 | + |
| 104 | + |
| 105 | +def test_mock_proxy_get(): |
| 106 | + with mock.patch("umapi_client.connection.requests.Session.get") as mock_get: |
| 107 | + mock_get.return_value = MockResponse(200, body=["test", "body"]) |
| 108 | + with mock.patch("umapi_client.connection.os.getenv") as mock_getenv: |
| 109 | + mock_getenv.return_value = "error" |
| 110 | + pytest.raises(ArgumentError, Connection, tuple(), mock_connection_params) |
| 111 | + |
| 112 | + |
81 | 113 | def test_get_success():
|
82 | 114 | with mock.patch("umapi_client.connection.requests.Session.get") as mock_get:
|
83 | 115 | mock_get.return_value = MockResponse(200, body=["test", "body"])
|
|
0 commit comments