-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from uc-cdis/chore/403
chore(403): handle 403 response
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
from googleapiclient.errors import HttpError | ||
import pytest | ||
from requests import Response | ||
import httplib2 | ||
|
||
from cirrus.google_cloud import ( | ||
COMPUTE_ENGINE_DEFAULT_SERVICE_ACCOUNT, | ||
|
@@ -1282,6 +1283,35 @@ def test_handled_exception_no_retry(test_cloud_manager): | |
assert logger_error.call_count <= 1 | ||
|
||
|
||
def test_handled_exception_403_no_retry(test_cloud_manager): | ||
""" | ||
Test that when a handled exception is raised (e.g. a cirrus error), we | ||
do NOT retry the Google API call | ||
""" | ||
from cirrus.google_cloud.manager import BACKOFF_SETTINGS | ||
|
||
response = httplib2.Response({"status": "403", "content-type": "application/json"}) | ||
http_error = HttpError(resp=response, content="") | ||
mock_config = {"get.side_effect": http_error} | ||
test_cloud_manager._authed_session.configure_mock(**mock_config) | ||
warn = cirrus.google_cloud.manager.logger.warn | ||
error = cirrus.google_cloud.manager.logger.error | ||
with mock.patch( | ||
"cirrus.google_cloud.manager.logger.warn" | ||
) as logger_warn, mock.patch( | ||
"cirrus.google_cloud.manager.logger.error" | ||
) as logger_error: | ||
# keep the side effect to actually put logs, so you can see the format with `-s` | ||
logger_warn.side_effect = warn | ||
logger_error.side_effect = error | ||
with pytest.raises(HttpError): | ||
test_cloud_manager.get_service_account_type( | ||
account="[email protected]" | ||
) | ||
assert logger_warn.call_count == 0 | ||
assert logger_error.call_count == 1 | ||
|
||
|
||
def test_unhandled_exception_retry(test_cloud_manager): | ||
""" | ||
Test that when an unhandled exception is raised, | ||
|