Converted application to use utcnow()

This patch fixes inconsistent usage of now() and utcnow() in
storyboard. The default oslo timestamp mixin prescribes the use
of utcnow() as the default method of determining datetimes,
and blending this with the use of now() in many locations resulted
in inconsistent date calculations. While on infra this was not a
problem as both server and database use UTC as their server time,
it becomes a problem on developer systems that use local timezones,
as the default python datetime.now() does not return a datetime
object with a properly set tzinfo.

Change-Id: I7470164f448e09916f84daaf91b68c07a876c501
This commit is contained in:
Michael Krotscheck 2014-12-08 13:16:09 -08:00 committed by Elizabeth K. Joseph
parent b1d230b77a
commit 169bd86abc
6 changed files with 11 additions and 11 deletions

View File

@ -123,7 +123,7 @@ class SkeletonValidator(RequestValidator):
email = request._params["openid.sreg.email"]
full_name = request._params["openid.sreg.fullname"]
username = request._params["openid.sreg.nickname"]
last_login = datetime.now()
last_login = datetime.utcnow()
user = user_api.user_get_by_openid(openid)
user_dict = {"full_name": full_name,

View File

@ -48,7 +48,7 @@ class DBTokenStorage(storage.StorageBase):
access_token_values = {
"access_token": access_token,
"expires_in": expires_in,
"expires_at": datetime.datetime.now() + datetime.timedelta(
"expires_at": datetime.datetime.utcnow() + datetime.timedelta(
seconds=expires_in),
"user_id": user_id
}
@ -61,7 +61,7 @@ class DBTokenStorage(storage.StorageBase):
"refresh_token": refresh_token,
"user_id": user_id,
"expires_in": refresh_expires_in,
"expires_at": datetime.datetime.now() + datetime.timedelta(
"expires_at": datetime.datetime.utcnow() + datetime.timedelta(
seconds=refresh_expires_in),
}
@ -77,7 +77,7 @@ class DBTokenStorage(storage.StorageBase):
if not token_info:
return False
if datetime.datetime.now() > token_info.expires_at:
if datetime.datetime.utcnow() > token_info.expires_at:
token_api.access_token_delete(access_token)
return False
@ -92,7 +92,7 @@ class DBTokenStorage(storage.StorageBase):
if not refresh_token_entry:
return False
if datetime.datetime.now() > refresh_token_entry.expires_at:
if datetime.datetime.utcnow() > refresh_token_entry.expires_at:
auth_api.refresh_token_delete(refresh_token)
return False

View File

@ -24,7 +24,7 @@ class Token(object):
self.access_token = access_token
self.refresh_token = refresh_token
self.expires_in = expires_in
self.expires_at = datetime.datetime.now() + \
self.expires_at = datetime.datetime.utcnow() + \
datetime.timedelta(seconds=expires_in)
self.user_id = user_id
self.is_valid = is_valid
@ -59,7 +59,7 @@ class MemoryTokenStorage(storage.StorageBase):
if not token_entry:
return False
now = datetime.datetime.now()
now = datetime.datetime.utcnow()
if now > token_entry.expires_at:
token_entry.is_valid = False
return False

View File

@ -73,8 +73,8 @@ def access_token_get_count(**kwargs):
def access_token_create(values):
# Update the expires_at date.
values['created_at'] = datetime.datetime.now()
values['expires_at'] = datetime.datetime.now() + datetime.timedelta(
values['created_at'] = datetime.datetime.utcnow()
values['expires_at'] = datetime.datetime.utcnow() + datetime.timedelta(
seconds=values['expires_in'])
return api_base.entity_create(models.AccessToken, values)

View File

@ -179,7 +179,7 @@ class TokenTest(BaseDbTestCase):
"access_token": u'an_access_token',
"refresh_token": u'a_refresh_token',
"expires_in": 3600,
"expires_at": datetime.now(),
"expires_at": datetime.utcnow(),
"user_id": 1
}

View File

@ -28,7 +28,7 @@ def load():
"""Load a batch of useful data into the database that our tests can work
with.
"""
now = datetime.datetime.now()
now = datetime.datetime.utcnow()
expires_at = now + datetime.timedelta(seconds=3600)
expired_at = now + datetime.timedelta(seconds=-3600)