Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Getting client.py to 100% coverage. #486

Merged
merged 2 commits into from
Apr 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions oauth2client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
# Expose utcnow() at module level to allow for
# easier testing (by replacing with a stub).
_UTCNOW = datetime.datetime.utcnow
_NOW = datetime.datetime.now


class SETTINGS(object):
Expand Down Expand Up @@ -1862,7 +1863,7 @@ def FromResponse(cls, response):
})
if 'expires_in' in response:
kwargs['user_code_expiry'] = (
datetime.datetime.now() +
_NOW() +
datetime.timedelta(seconds=int(response['expires_in'])))
return cls(**kwargs)

Expand Down Expand Up @@ -2020,17 +2021,17 @@ def step1_get_device_and_user_codes(self, http=None):
if resp.status == http_client.OK:
try:
flow_info = json.loads(content)
except ValueError as e:
except ValueError as exc:
raise OAuth2DeviceCodeError(
'Could not parse server response as JSON: "%s", '
'error: "%s"' % (content, e))
'error: "%s"' % (content, exc))
return DeviceFlowInfo.FromResponse(flow_info)
else:
error_msg = 'Invalid response %s.' % resp.status
error_msg = 'Invalid response %s.' % (resp.status,)
try:
d = json.loads(content)
if 'error' in d:
error_msg += ' Error: %s' % d['error']
error_dict = json.loads(content)
if 'error' in error_dict:
error_msg += ' Error: %s' % (error_dict['error'],)
except ValueError:
# Couldn't decode a JSON response, stick with the
# default message.
Expand Down Expand Up @@ -2201,4 +2202,4 @@ def flow_from_clientsecrets(filename, scope, redirect_uri=None,
raise
else:
raise UnknownClientSecretsFlowError(
'This OAuth 2.0 flow is unsupported: %r' % client_type)
'This OAuth 2.0 flow is unsupported: %r' % (client_type,))
Loading