From 3c43a9cc4fda818eb387bf41dc7b98f50bb9b9ce Mon Sep 17 00:00:00 2001 From: Chris Wilcox Date: Thu, 24 Sep 2020 20:42:50 -0700 Subject: [PATCH 1/3] fix: move async surfaces to internal until stabilized --- .../google.auth.transport.aiohttp_requests.rst | 2 +- docs/reference/google.auth.transport.rst | 2 +- google/auth/{jwt_async.py => _jwt_async.py} | 3 +++ .../{aiohttp_requests.py => _aiohttp_requests.py} | 8 ++++++-- system_tests/system_tests_async/conftest.py | 4 ++-- tests_async/oauth2/test__client_async.py | 2 +- tests_async/test_jwt_async.py | 2 +- tests_async/transport/test_aiohttp_requests.py | 14 +++++++------- 8 files changed, 22 insertions(+), 15 deletions(-) rename google/auth/{jwt_async.py => _jwt_async.py} (98%) rename google/auth/transport/{aiohttp_requests.py => _aiohttp_requests.py} (98%) diff --git a/docs/reference/google.auth.transport.aiohttp_requests.rst b/docs/reference/google.auth.transport.aiohttp_requests.rst index bc3e74381..44fc4e577 100644 --- a/docs/reference/google.auth.transport.aiohttp_requests.rst +++ b/docs/reference/google.auth.transport.aiohttp_requests.rst @@ -1,7 +1,7 @@ google.auth.transport.aiohttp\_requests module ============================================== -.. automodule:: google.auth.transport.aiohttp_requests +.. automodule:: google.auth.transport._aiohttp_requests :members: :inherited-members: :show-inheritance: diff --git a/docs/reference/google.auth.transport.rst b/docs/reference/google.auth.transport.rst index eba29d037..f1d198855 100644 --- a/docs/reference/google.auth.transport.rst +++ b/docs/reference/google.auth.transport.rst @@ -12,7 +12,7 @@ Submodules .. toctree:: :maxdepth: 4 - google.auth.transport.aiohttp_requests + google.auth.transport._aiohttp_requests google.auth.transport.grpc google.auth.transport.mtls google.auth.transport.requests diff --git a/google/auth/jwt_async.py b/google/auth/_jwt_async.py similarity index 98% rename from google/auth/jwt_async.py rename to google/auth/_jwt_async.py index daa5e3ee9..9d39fcf14 100644 --- a/google/auth/jwt_async.py +++ b/google/auth/_jwt_async.py @@ -38,6 +38,9 @@ .. _rfc7519: https://tools.ietf.org/html/rfc7519 + +NOTE: This async support is experimental and marked internal. This surface may +change in minor releases. """ import google.auth diff --git a/google/auth/transport/aiohttp_requests.py b/google/auth/transport/_aiohttp_requests.py similarity index 98% rename from google/auth/transport/aiohttp_requests.py rename to google/auth/transport/_aiohttp_requests.py index 8fe0434f3..b90cdcde9 100644 --- a/google/auth/transport/aiohttp_requests.py +++ b/google/auth/transport/_aiohttp_requests.py @@ -12,7 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Transport adapter for Async HTTP (aiohttp).""" +"""Transport adapter for Async HTTP (aiohttp). + +NOTE: This async support is experimental and marked internal. This surface may +change in minor releases. +""" from __future__ import absolute_import @@ -197,7 +201,7 @@ class AuthorizedSession(aiohttp.ClientSession): This class is used to perform requests to API endpoints that require authorization:: - import google.auth.transport.aiohttp_requests + from google.auth.transport import aiohttp_requests async with aiohttp_requests.AuthorizedSession(credentials) as authed_session: response = await authed_session.request( diff --git a/system_tests/system_tests_async/conftest.py b/system_tests/system_tests_async/conftest.py index 2477f3f82..af2a70517 100644 --- a/system_tests/system_tests_async/conftest.py +++ b/system_tests/system_tests_async/conftest.py @@ -23,7 +23,7 @@ import urllib3 import aiohttp -import google.auth.transport.aiohttp_requests +from google.auth.transport import _aiohttp_requests as aiohttp_requests from system_tests import conftest as sync_conftest ASYNC_REQUESTS_SESSION = aiohttp.ClientSession() @@ -52,7 +52,7 @@ def authorized_user_file(): @pytest.fixture(params=["aiohttp"]) async def http_request(request): """A transport.request object.""" - yield google.auth.transport.aiohttp_requests.Request(ASYNC_REQUESTS_SESSION) + yield aiohttp_requests.Request(ASYNC_REQUESTS_SESSION) @pytest.fixture async def token_info(http_request): diff --git a/tests_async/oauth2/test__client_async.py b/tests_async/oauth2/test__client_async.py index 87982807f..df0ad6cb0 100644 --- a/tests_async/oauth2/test__client_async.py +++ b/tests_async/oauth2/test__client_async.py @@ -23,7 +23,7 @@ from google.auth import _helpers from google.auth import exceptions -from google.auth import jwt_async as jwt +from google.auth import _jwt_async as jwt from google.oauth2 import _client as sync_client from google.oauth2 import _client_async as _client from tests.oauth2 import test__client as test_client diff --git a/tests_async/test_jwt_async.py b/tests_async/test_jwt_async.py index b5a499027..ba7044532 100644 --- a/tests_async/test_jwt_async.py +++ b/tests_async/test_jwt_async.py @@ -20,7 +20,7 @@ from google.auth import crypt from google.auth import exceptions -from google.auth import jwt_async +from google.auth import _jwt_async as jwt_async from tests import test_jwt diff --git a/tests_async/transport/test_aiohttp_requests.py b/tests_async/transport/test_aiohttp_requests.py index 4c3d9717b..10ccdaaea 100644 --- a/tests_async/transport/test_aiohttp_requests.py +++ b/tests_async/transport/test_aiohttp_requests.py @@ -19,7 +19,7 @@ from tests_async.transport import async_compliance import google.auth.credentials_async -from google.auth.transport import aiohttp_requests +from google.auth.transport import _aiohttp_requests as aiohttp_requests import google.auth.transport._mtls_helper @@ -33,7 +33,7 @@ def make_with_parameter_request(self): def test_timeout(self): http = mock.create_autospec(aiohttp.ClientSession, instance=True) - request = google.auth.transport.aiohttp_requests.Request(http) + request = aiohttp_requests.Request(http) request(url="http://example.com", method="GET", timeout=5) @@ -54,16 +54,16 @@ class TestAuthorizedSession(object): method = "GET" def test_constructor(self): - authed_session = google.auth.transport.aiohttp_requests.AuthorizedSession( + authed_session = aiohttp_requests.AuthorizedSession( mock.sentinel.credentials ) assert authed_session.credentials == mock.sentinel.credentials def test_constructor_with_auth_request(self): http = mock.create_autospec(aiohttp.ClientSession) - auth_request = google.auth.transport.aiohttp_requests.Request(http) + auth_request = aiohttp_requests.Request(http) - authed_session = google.auth.transport.aiohttp_requests.AuthorizedSession( + authed_session = aiohttp_requests.AuthorizedSession( mock.sentinel.credentials, auth_request=auth_request ) @@ -137,7 +137,7 @@ async def test_request_no_refresh(self): credentials = mock.Mock(wraps=CredentialsStub()) with aioresponses() as mocked: mocked.get("http://example.com", status=200) - authed_session = google.auth.transport.aiohttp_requests.AuthorizedSession( + authed_session = aiohttp_requests.AuthorizedSession( credentials ) response = await authed_session.request("GET", "http://example.com") @@ -153,7 +153,7 @@ async def test_request_refresh(self): with aioresponses() as mocked: mocked.get("http://example.com", status=401) mocked.get("http://example.com", status=200) - authed_session = google.auth.transport.aiohttp_requests.AuthorizedSession( + authed_session = aiohttp_requests.AuthorizedSession( credentials ) response = await authed_session.request("GET", "http://example.com") From 609e28dd800c056bb9fec22da30ffa28b830d1c4 Mon Sep 17 00:00:00 2001 From: Chris Wilcox Date: Fri, 25 Sep 2020 09:27:53 -0700 Subject: [PATCH 2/3] chore: lint/black --- tests_async/transport/test_aiohttp_requests.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/tests_async/transport/test_aiohttp_requests.py b/tests_async/transport/test_aiohttp_requests.py index 10ccdaaea..875a24e67 100644 --- a/tests_async/transport/test_aiohttp_requests.py +++ b/tests_async/transport/test_aiohttp_requests.py @@ -54,9 +54,7 @@ class TestAuthorizedSession(object): method = "GET" def test_constructor(self): - authed_session = aiohttp_requests.AuthorizedSession( - mock.sentinel.credentials - ) + authed_session = aiohttp_requests.AuthorizedSession(mock.sentinel.credentials) assert authed_session.credentials == mock.sentinel.credentials def test_constructor_with_auth_request(self): @@ -137,9 +135,7 @@ async def test_request_no_refresh(self): credentials = mock.Mock(wraps=CredentialsStub()) with aioresponses() as mocked: mocked.get("http://example.com", status=200) - authed_session = aiohttp_requests.AuthorizedSession( - credentials - ) + authed_session = aiohttp_requests.AuthorizedSession(credentials) response = await authed_session.request("GET", "http://example.com") assert response.status == 200 assert credentials.before_request.called @@ -153,9 +149,7 @@ async def test_request_refresh(self): with aioresponses() as mocked: mocked.get("http://example.com", status=401) mocked.get("http://example.com", status=200) - authed_session = aiohttp_requests.AuthorizedSession( - credentials - ) + authed_session = aiohttp_requests.AuthorizedSession(credentials) response = await authed_session.request("GET", "http://example.com") assert credentials.refresh.called assert response.status == 200 From dcabb3d81a919c8d79f158dfe0e5b5b431a6b5a1 Mon Sep 17 00:00:00 2001 From: Chris Wilcox Date: Fri, 25 Sep 2020 09:41:03 -0700 Subject: [PATCH 3/3] chore: lint --- tests_async/oauth2/test__client_async.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests_async/oauth2/test__client_async.py b/tests_async/oauth2/test__client_async.py index df0ad6cb0..458937ac1 100644 --- a/tests_async/oauth2/test__client_async.py +++ b/tests_async/oauth2/test__client_async.py @@ -22,8 +22,8 @@ from six.moves import urllib from google.auth import _helpers -from google.auth import exceptions from google.auth import _jwt_async as jwt +from google.auth import exceptions from google.oauth2 import _client as sync_client from google.oauth2 import _client_async as _client from tests.oauth2 import test__client as test_client