diff --git a/oauth2client/client.py b/oauth2client/client.py index 8bef6e6..a0e4473 100644 --- a/oauth2client/client.py +++ b/oauth2client/client.py @@ -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(): diff --git a/oauth2client/contrib/django_util/__init__.py b/oauth2client/contrib/django_util/__init__.py index 5aa12ac..19ac8b4 100644 --- a/oauth2client/contrib/django_util/__init__.py +++ b/oauth2client/contrib/django_util/__init__.py @@ -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): diff --git a/oauth2client/contrib/flask_util.py b/oauth2client/contrib/flask_util.py index fc6dd3d..ad61963 100644 --- a/oauth2client/contrib/flask_util.py +++ b/oauth2client/contrib/flask_util.py @@ -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 diff --git a/oauth2client/service_account.py b/oauth2client/service_account.py index ed7c904..33fff4e 100644 --- a/oauth2client/service_account.py +++ b/oauth2client/service_account.py @@ -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): diff --git a/tests/contrib/test_django_util.py b/tests/contrib/test_django_util.py index 18eab30..3b01427 100644 --- a/tests/contrib/test_django_util.py +++ b/tests/contrib/test_django_util.py @@ -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)) diff --git a/tests/contrib/test_gce.py b/tests/contrib/test_gce.py index 1974020..49d7599 100644 --- a/tests/contrib/test_gce.py +++ b/tests/contrib/test_gce.py @@ -36,6 +36,7 @@ SERVICE_ACCOUNT_INFO = { 'aliases': ['default'] } + class AppAssertionCredentialsTests(unittest2.TestCase): def test_constructor(self): diff --git a/tests/contrib/test_metadata.py b/tests/contrib/test_metadata.py index 8c6b973..9bf96c9 100644 --- a/tests/contrib/test_metadata.py +++ b/tests/contrib/test_metadata.py @@ -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 ) diff --git a/tests/test__pure_python_crypt.py b/tests/test__pure_python_crypt.py index 754b29d..cbfe728 100644 --- a/tests/test__pure_python_crypt.py +++ b/tests/test__pure_python_crypt.py @@ -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') diff --git a/tests/test_client.py b/tests/test_client.py index 59a80e8..3a2a20a 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -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, []) diff --git a/tests/test_clientsecrets.py b/tests/test_clientsecrets.py index 5065e31..081a2b1 100644 --- a/tests/test_clientsecrets.py +++ b/tests/test_clientsecrets.py @@ -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, diff --git a/tests/test_crypt.py b/tests/test_crypt.py index 55e60d9..278c5e6 100644 --- a/tests/test_crypt.py +++ b/tests/test_crypt.py @@ -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): diff --git a/tests/test_service_account.py b/tests/test_service_account.py index 9c7f444..d9e08f9 100644 --- a/tests/test_service_account.py +++ b/tests/test_service_account.py @@ -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) diff --git a/tests/test_tools.py b/tests/test_tools.py index bd19227..ac0fc70 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -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): diff --git a/tests/test_util.py b/tests/test_util.py index 9f1d7ed..533460f 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -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):