From 804c4d362cfcaff2746b97e6fcf72b5bbb886a63 Mon Sep 17 00:00:00 2001 From: Viacheslav Greshilov Date: Tue, 16 Feb 2021 17:42:08 +0200 Subject: [PATCH] fix: session object was never used in aiohttp request (#700) --- google/auth/transport/_aiohttp_requests.py | 7 ++++++- tests_async/transport/test_aiohttp_requests.py | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/google/auth/transport/_aiohttp_requests.py b/google/auth/transport/_aiohttp_requests.py index aaf4e2c0b..c83a1206b 100644 --- a/google/auth/transport/_aiohttp_requests.py +++ b/google/auth/transport/_aiohttp_requests.py @@ -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, diff --git a/tests_async/transport/test_aiohttp_requests.py b/tests_async/transport/test_aiohttp_requests.py index 10c31db8f..a64a4eec9 100644 --- a/tests_async/transport/test_aiohttp_requests.py +++ b/tests_async/transport/test_aiohttp_requests.py @@ -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) @@ -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(