From 7408a645fe930a10bf559fdb346df6352ebd3d35 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Thu, 7 Apr 2016 12:10:27 -0700 Subject: [PATCH] Replacing now() with utcnow() in device info code. --- oauth2client/client.py | 3 +-- tests/test_client.py | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/oauth2client/client.py b/oauth2client/client.py index 3c958d2..c3fb379 100644 --- a/oauth2client/client.py +++ b/oauth2client/client.py @@ -120,7 +120,6 @@ _DESIRED_METADATA_FLAVOR = 'Google' # 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): @@ -1863,7 +1862,7 @@ class DeviceFlowInfo(collections.namedtuple('DeviceFlowInfo', ( }) if 'expires_in' in response: kwargs['user_code_expiry'] = ( - _NOW() + + _UTCNOW() + datetime.timedelta(seconds=int(response['expires_in']))) return cls(**kwargs) diff --git a/tests/test_client.py b/tests/test_client.py index 6e0d997..9a3a04c 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -2337,8 +2337,8 @@ class TestDeviceFlowInfo(unittest2.TestCase): with self.assertRaises(client.OAuth2DeviceCodeError): DeviceFlowInfo.FromResponse(response) - @mock.patch('oauth2client.client._NOW') - def test_FromResponse_with_expires_in(self, dt_now): + @mock.patch('oauth2client.client._UTCNOW') + def test_FromResponse_with_expires_in(self, utcnow): expires_in = 23 response = { 'device_code': self.DEVICE_CODE, @@ -2348,7 +2348,7 @@ class TestDeviceFlowInfo(unittest2.TestCase): } now = datetime.datetime(1999, 1, 1, 12, 30, 27) expire = datetime.datetime(1999, 1, 1, 12, 30, 27 + expires_in) - dt_now.return_value = now + utcnow.return_value = now result = DeviceFlowInfo.FromResponse(response) expected_result = DeviceFlowInfo(self.DEVICE_CODE, self.USER_CODE,