Merge pull request #488 from dhermes/swap-to-utcnow

Replacing now() with utcnow() in device info code.
This commit is contained in:
Nathaniel Manista
2016-05-20 08:26:07 -07:00
2 changed files with 4 additions and 5 deletions

View File

@@ -120,7 +120,6 @@ _DESIRED_METADATA_FLAVOR = 'Google'
# Expose utcnow() at module level to allow for # Expose utcnow() at module level to allow for
# easier testing (by replacing with a stub). # easier testing (by replacing with a stub).
_UTCNOW = datetime.datetime.utcnow _UTCNOW = datetime.datetime.utcnow
_NOW = datetime.datetime.now
class SETTINGS(object): class SETTINGS(object):
@@ -1879,7 +1878,7 @@ class DeviceFlowInfo(collections.namedtuple('DeviceFlowInfo', (
}) })
if 'expires_in' in response: if 'expires_in' in response:
kwargs['user_code_expiry'] = ( kwargs['user_code_expiry'] = (
_NOW() + _UTCNOW() +
datetime.timedelta(seconds=int(response['expires_in']))) datetime.timedelta(seconds=int(response['expires_in'])))
return cls(**kwargs) return cls(**kwargs)

View File

@@ -2351,8 +2351,8 @@ class TestDeviceFlowInfo(unittest2.TestCase):
with self.assertRaises(client.OAuth2DeviceCodeError): with self.assertRaises(client.OAuth2DeviceCodeError):
DeviceFlowInfo.FromResponse(response) DeviceFlowInfo.FromResponse(response)
@mock.patch('oauth2client.client._NOW') @mock.patch('oauth2client.client._UTCNOW')
def test_FromResponse_with_expires_in(self, dt_now): def test_FromResponse_with_expires_in(self, utcnow):
expires_in = 23 expires_in = 23
response = { response = {
'device_code': self.DEVICE_CODE, 'device_code': self.DEVICE_CODE,
@@ -2362,7 +2362,7 @@ class TestDeviceFlowInfo(unittest2.TestCase):
} }
now = datetime.datetime(1999, 1, 1, 12, 30, 27) now = datetime.datetime(1999, 1, 1, 12, 30, 27)
expire = datetime.datetime(1999, 1, 1, 12, 30, 27 + expires_in) expire = datetime.datetime(1999, 1, 1, 12, 30, 27 + expires_in)
dt_now.return_value = now utcnow.return_value = now
result = DeviceFlowInfo.FromResponse(response) result = DeviceFlowInfo.FromResponse(response)
expected_result = DeviceFlowInfo(self.DEVICE_CODE, self.USER_CODE, expected_result = DeviceFlowInfo(self.DEVICE_CODE, self.USER_CODE,