mirror of
https://github.com/GAM-team/GAM.git
synced 2026-07-03 20:31:35 +00:00
line formatting
This commit is contained in:
@@ -161,13 +161,17 @@ class Credentials(google.oauth2.credentials.Credentials):
|
|||||||
Raises:
|
Raises:
|
||||||
ValueError: If missing fields are detected in the info.
|
ValueError: If missing fields are detected in the info.
|
||||||
"""
|
"""
|
||||||
keys_needed = set(('token', 'client_id', 'client_secret'))
|
# We need all of these keys
|
||||||
|
keys_needed = set(('client_id', 'client_secret'))
|
||||||
|
# We need 1 or more of these keys
|
||||||
|
keys_need_one_of = set(('refresh_token', 'auth_token', 'token'))
|
||||||
missing = keys_needed.difference(info.keys())
|
missing = keys_needed.difference(info.keys())
|
||||||
|
has_one_of = set(info) & keys_need_one_of
|
||||||
if missing:
|
if missing or not has_one_of:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
'Authorized user info was not in the expected format, missing '
|
'Authorized user info was not in the expected format, missing '
|
||||||
f'fields {", ".join(missing)}.')
|
f'fields {", ".join(missing)} and one of '
|
||||||
|
f'{", ".join(keys_need_one_of)}.'
|
||||||
|
|
||||||
expiry = info.get('token_expiry')
|
expiry = info.get('token_expiry')
|
||||||
if expiry:
|
if expiry:
|
||||||
|
|||||||
@@ -170,16 +170,27 @@ class CredentialsTest(unittest.TestCase):
|
|||||||
oauth.Credentials.from_credentials_file(self.fake_filename)
|
oauth.Credentials.from_credentials_file(self.fake_filename)
|
||||||
|
|
||||||
@patch.object(oauth.fileutils, 'read_file')
|
@patch.object(oauth.fileutils, 'read_file')
|
||||||
def test_from_credentials_file_missing_required_info_raises_error(
|
def test_from_credentials_file_missing_any_token_raises_error(
|
||||||
self, mock_read_file):
|
self, mock_read_file):
|
||||||
mock_read_file.return_value = json.dumps({
|
mock_read_file.return_value = json.dumps({
|
||||||
# This data is missing the required refresh_token key/value pair
|
# This data is missing a token key/value pair
|
||||||
'client_id': self.fake_client_id,
|
'client_id': self.fake_client_id,
|
||||||
'client_secret': self.fake_client_secret,
|
'client_secret': self.fake_client_secret,
|
||||||
})
|
})
|
||||||
with self.assertRaises(oauth.InvalidCredentialsFileError):
|
with self.assertRaises(oauth.InvalidCredentialsFileError):
|
||||||
oauth.Credentials.from_credentials_file(self.fake_filename)
|
oauth.Credentials.from_credentials_file(self.fake_filename)
|
||||||
|
|
||||||
|
@patch.object(oauth.fileutils, 'read_file')
|
||||||
|
def test_from_credentials_file_missing_required_raises_error(
|
||||||
|
self, mock_read_file):
|
||||||
|
mock_read_file.return_value = json.dumps({
|
||||||
|
# This data is missing a client_secret key/value pair
|
||||||
|
'client_id': self.fake_client_id,
|
||||||
|
'refresh_token': self.fake_refresh_token,
|
||||||
|
})
|
||||||
|
with self.assertRaises(oauth.InvalidCredentialsFileError):
|
||||||
|
oauth.Credentials.from_credentials_file(self.fake_filename)
|
||||||
|
|
||||||
@patch.object(oauth._ShortURLFlow, 'from_client_config')
|
@patch.object(oauth._ShortURLFlow, 'from_client_config')
|
||||||
def test_from_client_secrets_console_flow(self, mock_flow):
|
def test_from_client_secrets_console_flow(self, mock_flow):
|
||||||
flow_creds = google.oauth2.credentials.Credentials(
|
flow_creds = google.oauth2.credentials.Credentials(
|
||||||
|
|||||||
Reference in New Issue
Block a user