Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions google/auth/transport/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

_LOGGER = logging.getLogger(__name__)

_DEFAULT_TIMEOUT = 120 # in seconds


class _Response(transport.Response):
"""Requests transport response adapter.
Expand Down Expand Up @@ -141,7 +143,13 @@ def __init__(self, session=None):
self.session = session

def __call__(
self, url, method="GET", body=None, headers=None, timeout=120, **kwargs
self,
url,
method="GET",
body=None,
headers=None,
timeout=_DEFAULT_TIMEOUT,
**kwargs
):
"""Make an HTTP request using requests.

Expand Down Expand Up @@ -246,7 +254,7 @@ def request(
data=None,
headers=None,
max_allowed_time=None,
timeout=None,
timeout=_DEFAULT_TIMEOUT,
**kwargs
):
"""Implementation of Requests' request.
Expand Down
15 changes: 15 additions & 0 deletions tests/transport/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,21 @@ def test_constructor_with_auth_request(self):

assert authed_session._auth_request == auth_request

def test_request_default_timeout(self):
credentials = mock.Mock(wraps=CredentialsStub())
response = make_response()
adapter = AdapterStub([response])

authed_session = google.auth.transport.requests.AuthorizedSession(credentials)
authed_session.mount(self.TEST_URL, adapter)

patcher = mock.patch("google.auth.transport.requests.requests.Session.request")
with patcher as patched_request:
authed_session.request("GET", self.TEST_URL)

expected_timeout = google.auth.transport.requests._DEFAULT_TIMEOUT
assert patched_request.call_args.kwargs.get("timeout") == expected_timeout

def test_request_no_refresh(self):
credentials = mock.Mock(wraps=CredentialsStub())
response = make_response()
Expand Down