chore: blacken (#375)
diff --git a/system_tests/app_engine_test_app/appengine_config.py b/system_tests/app_engine_test_app/appengine_config.py
index da02e10..6339909 100644
--- a/system_tests/app_engine_test_app/appengine_config.py
+++ b/system_tests/app_engine_test_app/appengine_config.py
@@ -15,7 +15,7 @@
from google.appengine.ext import vendor
# Add any libraries installed in the "lib" folder.
-vendor.add('lib')
+vendor.add("lib")
# Patch os.path.expanduser. This should be fixed in GAE
@@ -26,4 +26,5 @@
def patched_expanduser(path):
return path
+
os.path.expanduser = patched_expanduser
diff --git a/system_tests/app_engine_test_app/main.py b/system_tests/app_engine_test_app/main.py
index 122b505..a3354ac 100644
--- a/system_tests/app_engine_test_app/main.py
+++ b/system_tests/app_engine_test_app/main.py
@@ -42,8 +42,8 @@
Captured output:
{}
"""
-TOKEN_INFO_URL = 'https://www.googleapis.com/oauth2/v3/tokeninfo'
-EMAIL_SCOPE = 'https://www.googleapis.com/auth/userinfo.email'
+TOKEN_INFO_URL = "https://www.googleapis.com/oauth2/v3/tokeninfo"
+EMAIL_SCOPE = "https://www.googleapis.com/auth/userinfo.email"
HTTP = urllib3.contrib.appengine.AppEngineManager()
HTTP_REQUEST = google.auth.transport.urllib3.Request(HTTP)
@@ -58,13 +58,13 @@
assert scoped_credentials.token is not None
# Get token info and verify scope
- url = _helpers.update_query(TOKEN_INFO_URL, {
- 'access_token': scoped_credentials.token,
- })
- response = HTTP_REQUEST(url=url, method='GET')
- token_info = json.loads(response.data.decode('utf-8'))
+ url = _helpers.update_query(
+ TOKEN_INFO_URL, {"access_token": scoped_credentials.token}
+ )
+ response = HTTP_REQUEST(url=url, method="GET")
+ token_info = json.loads(response.data.decode("utf-8"))
- assert token_info['scope'] == EMAIL_SCOPE
+ assert token_info["scope"] == EMAIL_SCOPE
def test_default():
@@ -90,11 +90,11 @@
with capture() as capsys:
try:
func()
- return True, ''
+ return True, ""
except Exception as exc:
output = FAILED_TEST_TMPL.format(
- func.func_name, exc, traceback.format_exc(),
- capsys.getvalue())
+ func.func_name, exc, traceback.format_exc(), capsys.getvalue()
+ )
return False, output
@@ -106,7 +106,7 @@
otherwise, and any captured output from the tests.
"""
status = True
- output = ''
+ output = ""
tests = (test_credentials, test_default)
@@ -120,7 +120,7 @@
class MainHandler(webapp2.RequestHandler):
def get(self):
- self.response.headers['content-type'] = 'text/plain'
+ self.response.headers["content-type"] = "text/plain"
status, output = run_tests()
@@ -130,6 +130,4 @@
self.response.write(output)
-app = webapp2.WSGIApplication([
- ('/', MainHandler),
-], debug=True)
+app = webapp2.WSGIApplication([("/", MainHandler)], debug=True)
diff --git a/system_tests/conftest.py b/system_tests/conftest.py
index d0f7cc0..3f089c4 100644
--- a/system_tests/conftest.py
+++ b/system_tests/conftest.py
@@ -24,13 +24,13 @@
HERE = os.path.dirname(__file__)
-DATA_DIR = os.path.join(HERE, 'data')
-SERVICE_ACCOUNT_FILE = os.path.join(DATA_DIR, 'service_account.json')
-AUTHORIZED_USER_FILE = os.path.join(DATA_DIR, 'authorized_user.json')
+DATA_DIR = os.path.join(HERE, "data")
+SERVICE_ACCOUNT_FILE = os.path.join(DATA_DIR, "service_account.json")
+AUTHORIZED_USER_FILE = os.path.join(DATA_DIR, "authorized_user.json")
URLLIB3_HTTP = urllib3.PoolManager(retries=False)
REQUESTS_SESSION = requests.Session()
REQUESTS_SESSION.verify = False
-TOKEN_INFO_URL = 'https://www.googleapis.com/oauth2/v3/tokeninfo'
+TOKEN_INFO_URL = "https://www.googleapis.com/oauth2/v3/tokeninfo"
@pytest.fixture
@@ -45,33 +45,34 @@
yield AUTHORIZED_USER_FILE
-@pytest.fixture(params=['urllib3', 'requests'])
+@pytest.fixture(params=["urllib3", "requests"])
def http_request(request):
"""A transport.request object."""
- if request.param == 'urllib3':
+ if request.param == "urllib3":
yield google.auth.transport.urllib3.Request(URLLIB3_HTTP)
- elif request.param == 'requests':
+ elif request.param == "requests":
yield google.auth.transport.requests.Request(REQUESTS_SESSION)
@pytest.fixture
def token_info(http_request):
"""Returns a function that obtains OAuth2 token info."""
+
def _token_info(access_token=None, id_token=None):
query_params = {}
if access_token is not None:
- query_params['access_token'] = access_token
+ query_params["access_token"] = access_token
elif id_token is not None:
- query_params['id_token'] = id_token
+ query_params["id_token"] = id_token
else:
- raise ValueError('No token specified.')
+ raise ValueError("No token specified.")
url = _helpers.update_query(TOKEN_INFO_URL, query_params)
- response = http_request(url=url, method='GET')
+ response = http_request(url=url, method="GET")
- return json.loads(response.data.decode('utf-8'))
+ return json.loads(response.data.decode("utf-8"))
yield _token_info
@@ -79,9 +80,10 @@
@pytest.fixture
def verify_refresh(http_request):
"""Returns a function that verifies that credentials can be refreshed."""
+
def _verify_refresh(credentials):
if credentials.requires_scopes:
- credentials = credentials.with_scopes(['email', 'profile'])
+ credentials = credentials.with_scopes(["email", "profile"])
credentials.refresh(http_request)
@@ -95,8 +97,9 @@
"""Checks to make sure that requisite data files are available."""
if not os.path.isdir(DATA_DIR):
raise EnvironmentError(
- 'In order to run system tests, test data must exist in '
- 'system_tests/data. See CONTRIBUTING.rst for details.')
+ "In order to run system tests, test data must exist in "
+ "system_tests/data. See CONTRIBUTING.rst for details."
+ )
def pytest_configure(config):
diff --git a/system_tests/noxfile.py b/system_tests/noxfile.py
index fa0422a..5f9291a 100644
--- a/system_tests/noxfile.py
+++ b/system_tests/noxfile.py
@@ -30,31 +30,31 @@
HERE = os.path.abspath(os.path.dirname(__file__))
-DATA_DIR = os.path.join(HERE, 'data')
-SERVICE_ACCOUNT_FILE = os.path.join(DATA_DIR, 'service_account.json')
-AUTHORIZED_USER_FILE = os.path.join(DATA_DIR, 'authorized_user.json')
-EXPLICIT_CREDENTIALS_ENV = 'GOOGLE_APPLICATION_CREDENTIALS'
-EXPLICIT_PROJECT_ENV = 'GOOGLE_CLOUD_PROJECT'
-EXPECT_PROJECT_ENV = 'EXPECT_PROJECT_ID'
+DATA_DIR = os.path.join(HERE, "data")
+SERVICE_ACCOUNT_FILE = os.path.join(DATA_DIR, "service_account.json")
+AUTHORIZED_USER_FILE = os.path.join(DATA_DIR, "authorized_user.json")
+EXPLICIT_CREDENTIALS_ENV = "GOOGLE_APPLICATION_CREDENTIALS"
+EXPLICIT_PROJECT_ENV = "GOOGLE_CLOUD_PROJECT"
+EXPECT_PROJECT_ENV = "EXPECT_PROJECT_ID"
-SKIP_GAE_TEST_ENV = 'SKIP_APP_ENGINE_SYSTEM_TEST'
-GAE_APP_URL_TMPL = 'https://{}-dot-{}.appspot.com'
-GAE_TEST_APP_SERVICE = 'google-auth-system-tests'
+SKIP_GAE_TEST_ENV = "SKIP_APP_ENGINE_SYSTEM_TEST"
+GAE_APP_URL_TMPL = "https://{}-dot-{}.appspot.com"
+GAE_TEST_APP_SERVICE = "google-auth-system-tests"
# The download location for the Cloud SDK
-CLOUD_SDK_DIST_FILENAME = 'google-cloud-sdk.tar.gz'
-CLOUD_SDK_DOWNLOAD_URL = (
- 'https://dl.google.com/dl/cloudsdk/release/{}'.format(
- CLOUD_SDK_DIST_FILENAME))
+CLOUD_SDK_DIST_FILENAME = "google-cloud-sdk.tar.gz"
+CLOUD_SDK_DOWNLOAD_URL = "https://dl.google.com/dl/cloudsdk/release/{}".format(
+ CLOUD_SDK_DIST_FILENAME
+)
# This environment variable is recognized by the Cloud SDK and overrides
# the location of the SDK's configuration files (which is usually at
# ${HOME}/.config).
-CLOUD_SDK_CONFIG_ENV = 'CLOUDSDK_CONFIG'
+CLOUD_SDK_CONFIG_ENV = "CLOUDSDK_CONFIG"
# If set, this is where the environment setup will install the Cloud SDK.
# If unset, it will download the SDK to a temporary directory.
-CLOUD_SDK_ROOT = os.environ.get('CLOUD_SDK_ROOT')
+CLOUD_SDK_ROOT = os.environ.get("CLOUD_SDK_ROOT")
if CLOUD_SDK_ROOT is not None:
CLOUD_SDK_ROOT = py.path.local(CLOUD_SDK_ROOT)
@@ -63,15 +63,15 @@
CLOUD_SDK_ROOT = py.path.local.mkdtemp()
# The full path the cloud sdk install directory
-CLOUD_SDK_INSTALL_DIR = CLOUD_SDK_ROOT.join('google-cloud-sdk')
+CLOUD_SDK_INSTALL_DIR = CLOUD_SDK_ROOT.join("google-cloud-sdk")
# The full path to the gcloud cli executable.
-GCLOUD = str(CLOUD_SDK_INSTALL_DIR.join('bin', 'gcloud'))
+GCLOUD = str(CLOUD_SDK_INSTALL_DIR.join("bin", "gcloud"))
# gcloud requires Python 2 and doesn't work on 3, so we need to tell it
# where to find 2 when we're running in a 3 environment.
-CLOUD_SDK_PYTHON_ENV = 'CLOUDSDK_PYTHON'
-CLOUD_SDK_PYTHON = which('python2', None)
+CLOUD_SDK_PYTHON_ENV = "CLOUDSDK_PYTHON"
+CLOUD_SDK_PYTHON = which("python2", None)
# Cloud SDK helpers
@@ -87,46 +87,47 @@
session.env[CLOUD_SDK_PYTHON_ENV] = CLOUD_SDK_PYTHON
# This set the $PATH for the subprocesses so they can find the gcloud
# executable.
- session.env['PATH'] = (
- str(CLOUD_SDK_INSTALL_DIR.join('bin')) + os.pathsep +
- os.environ['PATH'])
+ session.env["PATH"] = (
+ str(CLOUD_SDK_INSTALL_DIR.join("bin")) + os.pathsep + os.environ["PATH"]
+ )
# If gcloud cli executable already exists, just update it.
if py.path.local(GCLOUD).exists():
- session.run(GCLOUD, 'components', 'update', '-q')
+ session.run(GCLOUD, "components", "update", "-q")
return
tar_path = CLOUD_SDK_ROOT.join(CLOUD_SDK_DIST_FILENAME)
# Download the release.
- session.run(
- 'wget', CLOUD_SDK_DOWNLOAD_URL, '-O', str(tar_path), silent=True)
+ session.run("wget", CLOUD_SDK_DOWNLOAD_URL, "-O", str(tar_path), silent=True)
# Extract the release.
- session.run(
- 'tar', 'xzf', str(tar_path), '-C', str(CLOUD_SDK_ROOT))
+ session.run("tar", "xzf", str(tar_path), "-C", str(CLOUD_SDK_ROOT))
session.run(tar_path.remove)
# Run the install script.
session.run(
- str(CLOUD_SDK_INSTALL_DIR.join('install.sh')),
- '--usage-reporting', 'false',
- '--path-update', 'false',
- '--command-completion', 'false',
- silent=True)
+ str(CLOUD_SDK_INSTALL_DIR.join("install.sh")),
+ "--usage-reporting",
+ "false",
+ "--path-update",
+ "false",
+ "--command-completion",
+ "false",
+ silent=True,
+ )
def copy_credentials(credentials_path):
"""Copies credentials into the SDK root as the application default
credentials."""
- dest = CLOUD_SDK_ROOT.join('application_default_credentials.json')
+ dest = CLOUD_SDK_ROOT.join("application_default_credentials.json")
if dest.exists():
dest.remove()
py.path.local(credentials_path).copy(dest)
-def configure_cloud_sdk(
- session, application_default_credentials, project=False):
+def configure_cloud_sdk(session, application_default_credentials, project=False):
"""Installs and configures the Cloud SDK with the given application default
credentials.
@@ -140,13 +141,13 @@
# change the application default credentials file, which is user
# credentials instead of service account credentials sometimes.
session.run(
- GCLOUD, 'auth', 'activate-service-account', '--key-file',
- SERVICE_ACCOUNT_FILE)
+ GCLOUD, "auth", "activate-service-account", "--key-file", SERVICE_ACCOUNT_FILE
+ )
if project:
- session.run(GCLOUD, 'config', 'set', 'project', 'example-project')
+ session.run(GCLOUD, "config", "set", "project", "example-project")
else:
- session.run(GCLOUD, 'config', 'unset', 'project')
+ session.run(GCLOUD, "config", "unset", "project")
# Copy the credentials file to the config root. This is needed because
# unfortunately gcloud doesn't provide a clean way to tell it to use
@@ -160,8 +161,8 @@
# that our credentials matches the format expected by gcloud.
# Silent is set to True to prevent leaking secrets in test logs.
session.run(
- GCLOUD, 'auth', 'application-default', 'print-access-token',
- silent=True)
+ GCLOUD, "auth", "application-default", "print-access-token", silent=True
+ )
# Test sesssions
@@ -169,99 +170,102 @@
def session_service_account(session):
session.virtualenv = False
- session.run('pytest', 'test_service_account.py')
+ session.run("pytest", "test_service_account.py")
def session_oauth2_credentials(session):
session.virtualenv = False
- session.run('pytest', 'test_oauth2_credentials.py')
+ session.run("pytest", "test_oauth2_credentials.py")
def session_default_explicit_service_account(session):
session.virtualenv = False
session.env[EXPLICIT_CREDENTIALS_ENV] = SERVICE_ACCOUNT_FILE
- session.env[EXPECT_PROJECT_ENV] = '1'
- session.run('pytest', 'test_default.py')
+ session.env[EXPECT_PROJECT_ENV] = "1"
+ session.run("pytest", "test_default.py")
def session_default_explicit_authorized_user(session):
session.virtualenv = False
session.env[EXPLICIT_CREDENTIALS_ENV] = AUTHORIZED_USER_FILE
- session.run('pytest', 'test_default.py')
+ session.run("pytest", "test_default.py")
def session_default_explicit_authorized_user_explicit_project(session):
session.virtualenv = False
session.env[EXPLICIT_CREDENTIALS_ENV] = AUTHORIZED_USER_FILE
- session.env[EXPLICIT_PROJECT_ENV] = 'example-project'
- session.env[EXPECT_PROJECT_ENV] = '1'
- session.run('pytest', 'test_default.py')
+ session.env[EXPLICIT_PROJECT_ENV] = "example-project"
+ session.env[EXPECT_PROJECT_ENV] = "1"
+ session.run("pytest", "test_default.py")
def session_default_cloud_sdk_service_account(session):
session.virtualenv = False
configure_cloud_sdk(session, SERVICE_ACCOUNT_FILE)
- session.env[EXPECT_PROJECT_ENV] = '1'
- session.run('pytest', 'test_default.py')
+ session.env[EXPECT_PROJECT_ENV] = "1"
+ session.run("pytest", "test_default.py")
def session_default_cloud_sdk_authorized_user(session):
session.virtualenv = False
configure_cloud_sdk(session, AUTHORIZED_USER_FILE)
- session.run('pytest', 'test_default.py')
+ session.run("pytest", "test_default.py")
def session_default_cloud_sdk_authorized_user_configured_project(session):
session.virtualenv = False
configure_cloud_sdk(session, AUTHORIZED_USER_FILE, project=True)
- session.env[EXPECT_PROJECT_ENV] = '1'
- session.run('pytest', 'test_default.py')
+ session.env[EXPECT_PROJECT_ENV] = "1"
+ session.run("pytest", "test_default.py")
def session_compute_engine(session):
session.virtualenv = False
- session.run('pytest', 'test_compute_engine.py')
+ session.run("pytest", "test_compute_engine.py")
def session_app_engine(session):
session.virtualenv = False
if SKIP_GAE_TEST_ENV in os.environ:
- session.log('Skipping App Engine tests.')
+ session.log("Skipping App Engine tests.")
return
# Unlike the default tests above, the App Engine system test require a
# 'real' gcloud sdk installation that is configured to deploy to an
# app engine project.
# Grab the project ID from the cloud sdk.
- project_id = subprocess.check_output([
- 'gcloud', 'config', 'list', 'project', '--format',
- 'value(core.project)']).decode('utf-8').strip()
+ project_id = (
+ subprocess.check_output(
+ ["gcloud", "config", "list", "project", "--format", "value(core.project)"]
+ )
+ .decode("utf-8")
+ .strip()
+ )
if not project_id:
session.error(
- 'The Cloud SDK must be installed and configured to deploy to App '
- 'Engine.')
+ "The Cloud SDK must be installed and configured to deploy to App " "Engine."
+ )
- application_url = GAE_APP_URL_TMPL.format(
- GAE_TEST_APP_SERVICE, project_id)
+ application_url = GAE_APP_URL_TMPL.format(GAE_TEST_APP_SERVICE, project_id)
# Vendor in the test application's dependencies
- session.chdir(os.path.join(HERE, 'app_engine_test_app'))
+ session.chdir(os.path.join(HERE, "app_engine_test_app"))
session.run(
- 'pip', 'install', '--target', 'lib', '-r', 'requirements.txt',
- silent=True)
+ "pip", "install", "--target", "lib", "-r", "requirements.txt", silent=True
+ )
# Deploy the application.
- session.run('gcloud', 'app', 'deploy', '-q', 'app.yaml')
+ session.run("gcloud", "app", "deploy", "-q", "app.yaml")
# Run the tests
- session.env['TEST_APP_URL'] = application_url
+ session.env["TEST_APP_URL"] = application_url
session.chdir(HERE)
- session.run('pytest', 'test_app_engine.py')
+ session.run("pytest", "test_app_engine.py")
def session_grpc(session):
session.virtualenv = False
session.env[EXPLICIT_CREDENTIALS_ENV] = SERVICE_ACCOUNT_FILE
- session.run('pytest', 'test_grpc.py')
+ session.run("pytest", "test_grpc.py")
diff --git a/system_tests/test_app_engine.py b/system_tests/test_app_engine.py
index 834f9c8..cdf2be4 100644
--- a/system_tests/test_app_engine.py
+++ b/system_tests/test_app_engine.py
@@ -14,9 +14,9 @@
import os
-TEST_APP_URL = os.environ['TEST_APP_URL']
+TEST_APP_URL = os.environ["TEST_APP_URL"]
def test_live_application(http_request):
- response = http_request(method='GET', url=TEST_APP_URL)
- assert response.status == 200, response.data.decode('utf-8')
+ response = http_request(method="GET", url=TEST_APP_URL)
+ assert response.status == 200, response.data.decode("utf-8")
diff --git a/system_tests/test_compute_engine.py b/system_tests/test_compute_engine.py
index 3873327..3fd420c 100644
--- a/system_tests/test_compute_engine.py
+++ b/system_tests/test_compute_engine.py
@@ -26,7 +26,7 @@
try:
_metadata.get_service_account_info(http_request)
except exceptions.TransportError:
- pytest.skip('Compute Engine metadata service is not available.')
+ pytest.skip("Compute Engine metadata service is not available.")
def test_refresh(http_request, token_info):
@@ -38,7 +38,7 @@
assert credentials.service_account_email is not None
info = token_info(credentials.token)
- info_scopes = _helpers.string_to_scopes(info['scope'])
+ info_scopes = _helpers.string_to_scopes(info["scope"])
assert set(info_scopes) == set(credentials.scopes)
diff --git a/system_tests/test_default.py b/system_tests/test_default.py
index 23f6543..22213e6 100644
--- a/system_tests/test_default.py
+++ b/system_tests/test_default.py
@@ -16,7 +16,7 @@
import google.auth
-EXPECT_PROJECT_ID = os.environ.get('EXPECT_PROJECT_ID')
+EXPECT_PROJECT_ID = os.environ.get("EXPECT_PROJECT_ID")
def test_application_default_credentials(verify_refresh):
diff --git a/system_tests/test_grpc.py b/system_tests/test_grpc.py
index 365bc91..ea52830 100644
--- a/system_tests/test_grpc.py
+++ b/system_tests/test_grpc.py
@@ -22,61 +22,58 @@
def test_grpc_request_with_regular_credentials(http_request):
credentials, project_id = google.auth.default()
credentials = google.auth.credentials.with_scopes_if_required(
- credentials, ['https://www.googleapis.com/auth/pubsub'])
+ credentials, ["https://www.googleapis.com/auth/pubsub"]
+ )
channel = google.auth.transport.grpc.secure_authorized_channel(
- credentials,
- http_request,
- publisher_client.PublisherClient.SERVICE_ADDRESS)
+ credentials, http_request, publisher_client.PublisherClient.SERVICE_ADDRESS
+ )
# Create a pub/sub client.
client = publisher_client.PublisherClient(channel=channel)
# list the topics and drain the iterator to test that an authorized API
# call works.
- list_topics_iter = client.list_topics(
- project='projects/{}'.format(project_id))
+ list_topics_iter = client.list_topics(project="projects/{}".format(project_id))
list(list_topics_iter)
def test_grpc_request_with_jwt_credentials():
credentials, project_id = google.auth.default()
- audience = 'https://{}/google.pubsub.v1.Publisher'.format(
- publisher_client.PublisherClient.SERVICE_ADDRESS)
+ audience = "https://{}/google.pubsub.v1.Publisher".format(
+ publisher_client.PublisherClient.SERVICE_ADDRESS
+ )
credentials = google.auth.jwt.Credentials.from_signing_credentials(
- credentials,
- audience=audience)
+ credentials, audience=audience
+ )
channel = google.auth.transport.grpc.secure_authorized_channel(
- credentials,
- None,
- publisher_client.PublisherClient.SERVICE_ADDRESS)
+ credentials, None, publisher_client.PublisherClient.SERVICE_ADDRESS
+ )
# Create a pub/sub client.
client = publisher_client.PublisherClient(channel=channel)
# list the topics and drain the iterator to test that an authorized API
# call works.
- list_topics_iter = client.list_topics(
- project='projects/{}'.format(project_id))
+ list_topics_iter = client.list_topics(project="projects/{}".format(project_id))
list(list_topics_iter)
def test_grpc_request_with_on_demand_jwt_credentials():
credentials, project_id = google.auth.default()
credentials = google.auth.jwt.OnDemandCredentials.from_signing_credentials(
- credentials)
+ credentials
+ )
channel = google.auth.transport.grpc.secure_authorized_channel(
- credentials,
- None,
- publisher_client.PublisherClient.SERVICE_ADDRESS)
+ credentials, None, publisher_client.PublisherClient.SERVICE_ADDRESS
+ )
# Create a pub/sub client.
client = publisher_client.PublisherClient(channel=channel)
# list the topics and drain the iterator to test that an authorized API
# call works.
- list_topics_iter = client.list_topics(
- project='projects/{}'.format(project_id))
+ list_topics_iter = client.list_topics(project="projects/{}".format(project_id))
list(list_topics_iter)
diff --git a/system_tests/test_oauth2_credentials.py b/system_tests/test_oauth2_credentials.py
index ded0630..a33b89f 100644
--- a/system_tests/test_oauth2_credentials.py
+++ b/system_tests/test_oauth2_credentials.py
@@ -17,19 +17,20 @@
from google.auth import _helpers
import google.oauth2.credentials
-GOOGLE_OAUTH2_TOKEN_ENDPOINT = 'https://accounts.google.com/o/oauth2/token'
+GOOGLE_OAUTH2_TOKEN_ENDPOINT = "https://accounts.google.com/o/oauth2/token"
def test_refresh(authorized_user_file, http_request, token_info):
- with open(authorized_user_file, 'r') as fh:
+ with open(authorized_user_file, "r") as fh:
info = json.load(fh)
credentials = google.oauth2.credentials.Credentials(
None, # No access token, must be refreshed.
- refresh_token=info['refresh_token'],
+ refresh_token=info["refresh_token"],
token_uri=GOOGLE_OAUTH2_TOKEN_ENDPOINT,
- client_id=info['client_id'],
- client_secret=info['client_secret'])
+ client_id=info["client_id"],
+ client_secret=info["client_secret"],
+ )
credentials.refresh(http_request)
@@ -37,7 +38,10 @@
info = token_info(credentials.token)
- info_scopes = _helpers.string_to_scopes(info['scope'])
- assert set(info_scopes) == set([
- 'https://www.googleapis.com/auth/userinfo.email',
- 'https://www.googleapis.com/auth/userinfo.profile'])
+ info_scopes = _helpers.string_to_scopes(info["scope"])
+ assert set(info_scopes) == set(
+ [
+ "https://www.googleapis.com/auth/userinfo.email",
+ "https://www.googleapis.com/auth/userinfo.profile",
+ ]
+ )
diff --git a/system_tests/test_service_account.py b/system_tests/test_service_account.py
index aad1497..7937601 100644
--- a/system_tests/test_service_account.py
+++ b/system_tests/test_service_account.py
@@ -21,8 +21,7 @@
@pytest.fixture
def credentials(service_account_file):
- yield service_account.Credentials.from_service_account_file(
- service_account_file)
+ yield service_account.Credentials.from_service_account_file(service_account_file)
def test_refresh_no_scopes(http_request, credentials):
@@ -31,7 +30,7 @@
def test_refresh_success(http_request, credentials, token_info):
- credentials = credentials.with_scopes(['email', 'profile'])
+ credentials = credentials.with_scopes(["email", "profile"])
credentials.refresh(http_request)
@@ -39,8 +38,11 @@
info = token_info(credentials.token)
- assert info['email'] == credentials.service_account_email
- info_scopes = _helpers.string_to_scopes(info['scope'])
- assert set(info_scopes) == set([
- 'https://www.googleapis.com/auth/userinfo.email',
- 'https://www.googleapis.com/auth/userinfo.profile'])
+ assert info["email"] == credentials.service_account_email
+ info_scopes = _helpers.string_to_scopes(info["scope"])
+ assert set(info_scopes) == set(
+ [
+ "https://www.googleapis.com/auth/userinfo.email",
+ "https://www.googleapis.com/auth/userinfo.profile",
+ ]
+ )