Clean up whitespace
This commit is contained in:
@@ -1193,7 +1193,7 @@ class GoogleCredentials(OAuth2Credentials):
|
||||
print(response)
|
||||
"""
|
||||
|
||||
NON_SERIALIZED_MEMBERS = (
|
||||
NON_SERIALIZED_MEMBERS = (
|
||||
frozenset(['_private_key']) |
|
||||
OAuth2Credentials.NON_SERIALIZED_MEMBERS)
|
||||
"""Members that aren't serialized when object is converted to JSON."""
|
||||
@@ -1251,12 +1251,11 @@ class GoogleCredentials(OAuth2Credentials):
|
||||
# We handle service_account.ServiceAccountCredentials since it is a
|
||||
# possible return type of GoogleCredentials.get_application_default()
|
||||
if (data['_module'] == 'oauth2client.service_account' and
|
||||
data['_class'] == 'ServiceAccountCredentials'):
|
||||
data['_class'] == 'ServiceAccountCredentials'):
|
||||
return ServiceAccountCredentials.from_json(data)
|
||||
elif (data['_module'] == 'oauth2client.service_account' and
|
||||
data['_class'] == '_JWTAccessCredentials'):
|
||||
data['_class'] == '_JWTAccessCredentials'):
|
||||
return _JWTAccessCredentials.from_json(data)
|
||||
|
||||
|
||||
token_expiry = _parse_expiry(data.get('token_expiry'))
|
||||
google_credentials = cls(
|
||||
@@ -1466,8 +1465,7 @@ def save_to_well_known_file(credentials, well_known_file=None):
|
||||
|
||||
def _get_environment_variable_file():
|
||||
application_default_credential_filename = (
|
||||
os.environ.get(GOOGLE_APPLICATION_CREDENTIALS,
|
||||
None))
|
||||
os.environ.get(GOOGLE_APPLICATION_CREDENTIALS, None))
|
||||
|
||||
if application_default_credential_filename:
|
||||
if os.path.isfile(application_default_credential_filename):
|
||||
@@ -1550,8 +1548,8 @@ def _raise_exception_for_reading_json(credential_file,
|
||||
extra_help,
|
||||
error):
|
||||
raise ApplicationDefaultCredentialsError(
|
||||
'An error was encountered while reading json file: ' +
|
||||
credential_file + extra_help + ': ' + str(error))
|
||||
'An error was encountered while reading json file: ' +
|
||||
credential_file + extra_help + ': ' + str(error))
|
||||
|
||||
|
||||
def _get_application_default_credential_GAE():
|
||||
|
||||
@@ -290,8 +290,8 @@ class UserOAuth2(object):
|
||||
def has_credentials(self):
|
||||
"""Returns True if there are valid credentials for the current user
|
||||
and required scopes."""
|
||||
return (self.credentials and not self.credentials.invalid
|
||||
and self.credentials.has_scopes(self.scopes))
|
||||
return (self.credentials and not self.credentials.invalid and
|
||||
self.credentials.has_scopes(self.scopes))
|
||||
|
||||
@property
|
||||
def credentials(self):
|
||||
|
||||
@@ -446,8 +446,8 @@ class UserOAuth2(object):
|
||||
if not self.credentials:
|
||||
return False
|
||||
# Is the access token expired? If so, do we have an refresh token?
|
||||
elif (self.credentials.access_token_expired
|
||||
and not self.credentials.refresh_token):
|
||||
elif (self.credentials.access_token_expired and
|
||||
not self.credentials.refresh_token):
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
@@ -90,7 +90,7 @@ class ServiceAccountCredentials(AssertionCredentials):
|
||||
MAX_TOKEN_LIFETIME_SECS = 3600
|
||||
"""Max lifetime of the token (one hour, in seconds)."""
|
||||
|
||||
NON_SERIALIZED_MEMBERS = (
|
||||
NON_SERIALIZED_MEMBERS = (
|
||||
frozenset(['_signer']) |
|
||||
AssertionCredentials.NON_SERIALIZED_MEMBERS)
|
||||
"""Members that aren't serialized when object is converted to JSON."""
|
||||
@@ -498,7 +498,7 @@ class ServiceAccountCredentials(AssertionCredentials):
|
||||
result._private_key_pkcs12 = self._private_key_pkcs12
|
||||
result._private_key_password = self._private_key_password
|
||||
return result
|
||||
|
||||
|
||||
def create_with_claims(self, claims):
|
||||
"""Create credentials that specify additional claims.
|
||||
|
||||
@@ -548,11 +548,11 @@ class ServiceAccountCredentials(AssertionCredentials):
|
||||
|
||||
|
||||
def _datetime_to_secs(utc_time):
|
||||
# TODO(issue 298): use time_delta.total_seconds()
|
||||
# time_delta.total_seconds() not supported in Python 2.6
|
||||
epoch = datetime.datetime(1970, 1, 1)
|
||||
time_delta = utc_time - epoch
|
||||
return time_delta.days * 86400 + time_delta.seconds
|
||||
# TODO(issue 298): use time_delta.total_seconds()
|
||||
# time_delta.total_seconds() not supported in Python 2.6
|
||||
epoch = datetime.datetime(1970, 1, 1)
|
||||
time_delta = utc_time - epoch
|
||||
return time_delta.days * 86400 + time_delta.seconds
|
||||
|
||||
|
||||
class _JWTAccessCredentials(ServiceAccountCredentials):
|
||||
|
||||
@@ -242,9 +242,8 @@ class Oauth2AuthorizeTest(TestWithSession):
|
||||
self.assertTrue(isinstance(response, http.HttpResponseRedirect))
|
||||
|
||||
def test_authorize_works_explicit_return_url(self):
|
||||
request = self.factory.get('oauth2/oauth2authorize', data={
|
||||
'return_url': '/return_endpoint'
|
||||
})
|
||||
request = self.factory.get('oauth2/oauth2authorize',
|
||||
data={'return_url': '/return_endpoint'})
|
||||
request.session = self.session
|
||||
response = views.oauth2_authorize(request)
|
||||
self.assertTrue(isinstance(response, http.HttpResponseRedirect))
|
||||
|
||||
@@ -36,6 +36,7 @@ SERVICE_ACCOUNT_INFO = {
|
||||
'aliases': ['default']
|
||||
}
|
||||
|
||||
|
||||
class AppAssertionCredentialsTests(unittest2.TestCase):
|
||||
|
||||
def test_constructor(self):
|
||||
|
||||
@@ -81,7 +81,7 @@ class TestMetadata(unittest2.TestCase):
|
||||
self.assertEqual(
|
||||
expiry, datetime.datetime.min + datetime.timedelta(seconds=100))
|
||||
http_request.assert_called_once_with(
|
||||
EXPECTED_URL+'/token',
|
||||
EXPECTED_URL + '/token',
|
||||
**EXPECTED_KWARGS
|
||||
)
|
||||
now.assert_called_once_with()
|
||||
@@ -92,6 +92,6 @@ class TestMetadata(unittest2.TestCase):
|
||||
info = _metadata.get_service_account_info(http_request)
|
||||
self.assertEqual(info, DATA)
|
||||
http_request.assert_called_once_with(
|
||||
EXPECTED_URL+'/?recursive=True',
|
||||
EXPECTED_URL + '/?recursive=True',
|
||||
**EXPECTED_KWARGS
|
||||
)
|
||||
|
||||
@@ -33,7 +33,7 @@ class TestRsaVerifier(unittest2.TestCase):
|
||||
PUBLIC_KEY_FILENAME = os.path.join(os.path.dirname(__file__),
|
||||
'data', 'privatekey.pub')
|
||||
PUBLIC_CERT_FILENAME = os.path.join(os.path.dirname(__file__),
|
||||
'data', 'public_cert.pem')
|
||||
'data', 'public_cert.pem')
|
||||
PRIVATE_KEY_FILENAME = os.path.join(os.path.dirname(__file__),
|
||||
'data', 'privatekey.pem')
|
||||
|
||||
|
||||
@@ -457,7 +457,7 @@ class GoogleCredentialsTests(unittest2.TestCase):
|
||||
client._METADATA_FLAVOR_HEADER)
|
||||
else:
|
||||
self.assertEqual(
|
||||
http_client_module.HTTPConnection.mock_calls, [])
|
||||
http_client_module.HTTPConnection.mock_calls, [])
|
||||
self.assertEqual(connection.getresponse.mock_calls, [])
|
||||
# Remaining calls are not "getresponse"
|
||||
self.assertEqual(connection.method_calls, [])
|
||||
|
||||
@@ -121,11 +121,11 @@ class Test__validate_clientsecrets(unittest2.TestCase):
|
||||
|
||||
def test_success_type_web(self):
|
||||
client_info = {
|
||||
'client_id': 'eye-dee',
|
||||
'client_secret': 'seekrit',
|
||||
'redirect_uris': None,
|
||||
'auth_uri': None,
|
||||
'token_uri': None,
|
||||
'client_id': 'eye-dee',
|
||||
'client_secret': 'seekrit',
|
||||
'redirect_uris': None,
|
||||
'auth_uri': None,
|
||||
'token_uri': None,
|
||||
}
|
||||
clientsecrets_dict = {
|
||||
clientsecrets.TYPE_WEB: client_info,
|
||||
@@ -135,11 +135,11 @@ class Test__validate_clientsecrets(unittest2.TestCase):
|
||||
|
||||
def test_success_type_installed(self):
|
||||
client_info = {
|
||||
'client_id': 'eye-dee',
|
||||
'client_secret': 'seekrit',
|
||||
'redirect_uris': None,
|
||||
'auth_uri': None,
|
||||
'token_uri': None,
|
||||
'client_id': 'eye-dee',
|
||||
'client_secret': 'seekrit',
|
||||
'redirect_uris': None,
|
||||
'auth_uri': None,
|
||||
'token_uri': None,
|
||||
}
|
||||
clientsecrets_dict = {
|
||||
clientsecrets.TYPE_INSTALLED: client_info,
|
||||
|
||||
@@ -48,7 +48,7 @@ class Test_pkcs12_key_as_pem(unittest2.TestCase):
|
||||
'some_account@example.com',
|
||||
filename,
|
||||
scopes='read+write')
|
||||
credentials._kwargs['sub'] ='joe@example.org'
|
||||
credentials._kwargs['sub'] = 'joe@example.org'
|
||||
return credentials
|
||||
|
||||
def _succeeds_helper(self, password=None):
|
||||
@@ -171,6 +171,7 @@ class Test__check_audience(unittest2.TestCase):
|
||||
with self.assertRaises(crypt.AppIdentityError):
|
||||
crypt._check_audience(payload_dict, audience2)
|
||||
|
||||
|
||||
class Test__verify_time_range(unittest2.TestCase):
|
||||
|
||||
def _exception_helper(self, payload_dict):
|
||||
|
||||
@@ -114,7 +114,7 @@ class ServiceAccountCredentialsTests(unittest2.TestCase):
|
||||
return_value=object())
|
||||
def test_from_json_keyfile_name_factory(self, signer_factory):
|
||||
client_id = 'id123'
|
||||
client_email= 'foo@bar.com'
|
||||
client_email = 'foo@bar.com'
|
||||
private_key_id = 'pkid456'
|
||||
private_key = 's3kr3tz'
|
||||
payload = {
|
||||
@@ -435,13 +435,13 @@ class JWTAccessCredentialsTests(unittest2.TestCase):
|
||||
utcnow.return_value = T1_DATE
|
||||
time.return_value = T1
|
||||
|
||||
token_info = self.jwt.get_access_token(additional_claims=
|
||||
{'aud': 'https://test2.url.com',
|
||||
'sub': 'dummy2@google.com'
|
||||
})
|
||||
token_info = self.jwt.get_access_token(
|
||||
additional_claims={'aud': 'https://test2.url.com',
|
||||
'sub': 'dummy2@google.com'
|
||||
})
|
||||
payload = crypt.verify_signed_jwt_with_certs(
|
||||
token_info.access_token,
|
||||
{'key' : datafile('public_cert.pem')},
|
||||
{'key': datafile('public_cert.pem')},
|
||||
audience='https://test2.url.com')
|
||||
expires_in = token_info.expires_in
|
||||
self.assertEqual(payload['iss'], self.service_account_email)
|
||||
@@ -449,13 +449,13 @@ class JWTAccessCredentialsTests(unittest2.TestCase):
|
||||
self.assertEqual(payload['iat'], T1)
|
||||
self.assertEqual(payload['exp'], T1_EXPIRY)
|
||||
self.assertEqual(expires_in, T1_EXPIRY - T1)
|
||||
|
||||
|
||||
def test_revoke(self):
|
||||
self.jwt.revoke(None)
|
||||
|
||||
|
||||
def test_create_scoped_required(self):
|
||||
self.assertTrue(self.jwt.create_scoped_required())
|
||||
|
||||
|
||||
def test_create_scoped(self):
|
||||
self.jwt._private_key_pkcs12 = ''
|
||||
self.jwt._private_key_password = ''
|
||||
@@ -464,7 +464,7 @@ class JWTAccessCredentialsTests(unittest2.TestCase):
|
||||
self.assertNotEqual(self.jwt, new_credentials)
|
||||
self.assertIsInstance(new_credentials, ServiceAccountCredentials)
|
||||
self.assertEqual('dummy_scope', new_credentials._scopes)
|
||||
|
||||
|
||||
@mock.patch('oauth2client.service_account._UTCNOW')
|
||||
@mock.patch('oauth2client.client._UTCNOW')
|
||||
@mock.patch('time.time')
|
||||
@@ -479,7 +479,7 @@ class JWTAccessCredentialsTests(unittest2.TestCase):
|
||||
bearer, token = headers[b'Authorization'].split()
|
||||
payload = crypt.verify_signed_jwt_with_certs(
|
||||
token,
|
||||
{'key': datafile('public_cert.pem')},
|
||||
{'key': datafile('public_cert.pem')},
|
||||
audience=self.url)
|
||||
self.assertEqual(payload['iss'], self.service_account_email)
|
||||
self.assertEqual(payload['sub'], self.service_account_email)
|
||||
|
||||
@@ -68,11 +68,10 @@ class TestRunFlow(unittest2.TestCase):
|
||||
self.server_flags = argparse.Namespace(
|
||||
noauth_local_webserver=False,
|
||||
logging_level='INFO',
|
||||
auth_host_port=[8080,],
|
||||
auth_host_port=[8080, ],
|
||||
auth_host_name='localhost')
|
||||
|
||||
@mock.patch.object(sys, 'argv',
|
||||
['ignored', '--noauth_local_webserver'])
|
||||
@mock.patch.object(sys, 'argv', ['ignored', '--noauth_local_webserver'])
|
||||
@mock.patch('oauth2client.tools.logging')
|
||||
@mock.patch('oauth2client.tools.input')
|
||||
def test_run_flow_no_webserver(self, input_mock, logging_mock):
|
||||
|
||||
@@ -9,7 +9,6 @@ from oauth2client import util
|
||||
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
|
||||
|
||||
|
||||
|
||||
class PositionalTests(unittest2.TestCase):
|
||||
|
||||
def test_usage(self):
|
||||
@@ -45,7 +44,6 @@ class PositionalTests(unittest2.TestCase):
|
||||
with self.assertRaises(TypeError):
|
||||
fn3(1, 2)
|
||||
|
||||
|
||||
@mock.patch('oauth2client.util.logger')
|
||||
def test_enforcement_warning(self, mock_logger):
|
||||
util.positional_parameters_enforcement = util.POSITIONAL_WARNING
|
||||
@@ -57,7 +55,6 @@ class PositionalTests(unittest2.TestCase):
|
||||
self.assertTrue(fn(1, 2))
|
||||
self.assertTrue(mock_logger.warning.called)
|
||||
|
||||
|
||||
@mock.patch('oauth2client.util.logger')
|
||||
def test_enforcement_ignore(self, mock_logger):
|
||||
util.positional_parameters_enforcement = util.POSITIONAL_IGNORE
|
||||
@@ -104,7 +101,6 @@ class StringToScopeTests(unittest2.TestCase):
|
||||
self.assertEqual(expected, util.string_to_scopes(case))
|
||||
|
||||
|
||||
|
||||
class AddQueryParameterTests(unittest2.TestCase):
|
||||
|
||||
def test__add_query_parameter(self):
|
||||
|
||||
Reference in New Issue
Block a user