Skip to content

Commit

Permalink
fix: session object was never used in aiohttp request (googleapis#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
greshilov committed Feb 16, 2021
1 parent aeab5d0 commit e1acb4c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
7 changes: 6 additions & 1 deletion google/auth/transport/_aiohttp_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ class Request(transport.Request):
"""

def __init__(self, session=None):
self.session = None
# TODO: Use auto_decompress property for aiohttp 3.7+
if session is not None and session._auto_decompress:
raise ValueError(
"Client sessions with auto_decompress=True are not supported."
)
self.session = session

async def __call__(
self,
Expand Down
15 changes: 12 additions & 3 deletions tests_async/transport/test_aiohttp_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,18 @@ def make_request(self):
return aiohttp_requests.Request()

def make_with_parameter_request(self):
http = mock.create_autospec(aiohttp.ClientSession, instance=True)
http = aiohttp.ClientSession(auto_decompress=False)
return aiohttp_requests.Request(http)

def test_unsupported_session(self):
http = aiohttp.ClientSession(auto_decompress=True)
with pytest.raises(ValueError):
aiohttp_requests.Request(http)

def test_timeout(self):
http = mock.create_autospec(aiohttp.ClientSession, instance=True)
http = mock.create_autospec(
aiohttp.ClientSession, instance=True, _auto_decompress=False
)
request = aiohttp_requests.Request(http)
request(url="http://example.com", method="GET", timeout=5)

Expand All @@ -142,7 +149,9 @@ def test_constructor(self):
assert authed_session.credentials == mock.sentinel.credentials

def test_constructor_with_auth_request(self):
http = mock.create_autospec(aiohttp.ClientSession)
http = mock.create_autospec(
aiohttp.ClientSession, instance=True, _auto_decompress=False
)
auth_request = aiohttp_requests.Request(http)

authed_session = aiohttp_requests.AuthorizedSession(
Expand Down

0 comments on commit e1acb4c

Please sign in to comment.