Add exception text to exit message (#530)

If `clientsecrets.InvalidClientSecretsError` is raised with additional
text and a predefined failure message is given, include exception text
in the exit message.
This commit is contained in:
Pat Ferate
2016-06-29 09:26:04 -07:00
committed by Jon Wayne Parrott
parent 61c61a0140
commit a4e34317d5
2 changed files with 18 additions and 2 deletions

View File

@@ -2210,8 +2210,10 @@ def flow_from_clientsecrets(filename, scope, redirect_uri=None,
client_info['client_id'], client_info['client_secret'], client_info['client_id'], client_info['client_secret'],
scope, **constructor_kwargs) scope, **constructor_kwargs)
except clientsecrets.InvalidClientSecretsError: except clientsecrets.InvalidClientSecretsError as e:
if message: if message is not None:
if e.args:
message = 'The client secrets were invalid: \n{0}\n{1}'.format(e, message)
sys.exit(message) sys.exit(message)
else: else:
raise raise

View File

@@ -2150,6 +2150,20 @@ class FlowFromCachedClientsecrets(unittest2.TestCase):
sys_exit.assert_called_once_with(message) sys_exit.assert_called_once_with(message)
loadfile_mock.assert_called_once_with(filename, cache=cache) loadfile_mock.assert_called_once_with(filename, cache=cache)
@mock.patch('oauth2client.clientsecrets.loadfile',
side_effect=InvalidClientSecretsError('foobar'))
@mock.patch('sys.exit')
def test_flow_from_clientsecrets_invalid_w_msg_and_text(self, sys_exit,
loadfile_mock):
filename = object()
cache = object()
message = 'hi mom'
expected = 'The client secrets were invalid: \n{0}\n{1}'.format('foobar', 'hi mom')
flow_from_clientsecrets(filename, None, cache=cache, message=message)
sys_exit.assert_called_once_with(expected)
loadfile_mock.assert_called_once_with(filename, cache=cache)
@mock.patch('oauth2client.clientsecrets.loadfile') @mock.patch('oauth2client.clientsecrets.loadfile')
def test_flow_from_clientsecrets_unknown_flow(self, loadfile_mock): def test_flow_from_clientsecrets_unknown_flow(self, loadfile_mock):
client_type = 'UNKNOWN' client_type = 'UNKNOWN'