|
6 | 6 |
|
7 | 7 | import pytest |
8 | 8 |
|
| 9 | +from boxsdk import CCGAuth |
9 | 10 | from boxsdk.auth.oauth2 import OAuth2 |
10 | 11 | from boxsdk.config import API, Proxy |
11 | 12 | from boxsdk.exception import BoxAPIException, BoxException |
@@ -50,6 +51,14 @@ def box_session(mock_oauth, mock_network_layer, translator): |
50 | 51 | return AuthorizedSession(oauth=mock_oauth, network_layer=mock_network_layer, translator=translator) |
51 | 52 |
|
52 | 53 |
|
| 54 | +@pytest.fixture |
| 55 | +def ccg_auth(client_id, client_secret, mock_user_id, mock_enterprise_id, box_session) -> CCGAuth: |
| 56 | + # pylint:disable=protected-access |
| 57 | + auth = CCGAuth(client_id=client_id, client_secret=client_secret, user=mock_user_id, enterprise_id=mock_enterprise_id) |
| 58 | + auth._session = box_session |
| 59 | + return auth |
| 60 | + |
| 61 | + |
53 | 62 | @pytest.mark.parametrize('test_method', [ |
54 | 63 | Session.get, |
55 | 64 | Session.post, |
@@ -230,6 +239,15 @@ def test_box_session_retries_connection_aborted_exception(box_session, mock_netw |
230 | 239 | assert box_response.status_code == 200 |
231 | 240 |
|
232 | 241 |
|
| 242 | +def test_box_session_retries_connection_aborted_exception_on_ccg_auth_call(successful_token_response, ccg_auth, mock_user_id, access_token): |
| 243 | + # pylint:disable=protected-access |
| 244 | + ccg_auth._session._network_layer.request.side_effect = [RequestsConnectionError('Connection aborted'), successful_token_response] |
| 245 | + ccg_auth._session._network_layer.retry_after.side_effect = lambda delay, request, *args, **kwargs: request(*args, **kwargs) |
| 246 | + |
| 247 | + new_access_token = ccg_auth.authenticate_user(mock_user_id) |
| 248 | + assert new_access_token == access_token |
| 249 | + |
| 250 | + |
233 | 251 | def test_box_session_retries_requests_library_exceptions_only_once(box_session, mock_network_layer, test_url, generic_successful_request_response): |
234 | 252 | mock_network_layer.request.side_effect = [ |
235 | 253 | RequestException('Connection aborted'), |
|
0 commit comments