Update now to utcnow. All tests passing.

This commit is contained in:
Nicholas Staples
2016-05-11 10:56:24 +01:00
parent 1b82612ea3
commit 03f15d6af9
11 changed files with 21 additions and 21 deletions

View File

@@ -12,7 +12,7 @@ def create_secret_code():
def save_model_user(usr, update_dict={}, pwd=None):
if pwd:
usr.password = pwd
usr.password_changed_at = datetime.now()
usr.password_changed_at = datetime.utcnow()
if update_dict:
if update_dict.get('id'):
del update_dict['id']
@@ -25,7 +25,7 @@ def save_model_user(usr, update_dict={}, pwd=None):
def create_user_code(user, code, code_type):
verify_code = VerifyCode(code_type=code_type,
expiry_datetime=datetime.now() + timedelta(hours=1),
expiry_datetime=datetime.utcnow() + timedelta(hours=1),
user=user)
verify_code.code = code
db.session.add(verify_code)

View File

@@ -205,7 +205,7 @@ def create_history(obj):
if not obj.version:
obj.version = 1
obj.created_at = datetime.datetime.now()
obj.created_at = datetime.datetime.utcnow()
else:
obj.version += 1

View File

@@ -81,13 +81,13 @@ class Service(db.Model, Versioned):
index=False,
unique=False,
nullable=False,
default=datetime.datetime.now)
default=datetime.datetime.utcnow)
updated_at = db.Column(
db.DateTime,
index=False,
unique=False,
nullable=True,
onupdate=datetime.datetime.now)
onupdate=datetime.datetime.utcnow)
active = db.Column(db.Boolean, index=False, unique=False, nullable=False)
message_limit = db.Column(db.BigInteger, index=False, unique=False, nullable=False)
users = db.relationship(
@@ -114,13 +114,13 @@ class ApiKey(db.Model, Versioned):
index=False,
unique=False,
nullable=False,
default=datetime.datetime.now)
default=datetime.datetime.utcnow)
updated_at = db.Column(
db.DateTime,
index=False,
unique=False,
nullable=True,
onupdate=datetime.datetime.now)
onupdate=datetime.datetime.utcnow)
created_by = db.relationship('User')
created_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), index=True, nullable=False)

View File

@@ -35,7 +35,7 @@ def show_delivery_status():
return jsonify(status="ok"), 200
else:
notifications_alert = current_app.config['NOTIFICATIONS_ALERT']
some_number_of_minutes_ago = datetime.now() - timedelta(minutes=notifications_alert)
some_number_of_minutes_ago = datetime.utcnow() - timedelta(minutes=notifications_alert)
notifications = Notification.query.filter(Notification.status == 'sending',
Notification.created_at < some_number_of_minutes_ago).all()
message = "{} notifications in sending state over {} minutes".format(len(notifications), notifications_alert)

View File

@@ -1,3 +1,4 @@
import json
from datetime import datetime
from flask import (jsonify, request, abort, Blueprint, current_app)
from app import encryption
@@ -109,7 +110,7 @@ def verify_user_code(user_id):
code = get_user_code(user_to_verify, txt_code, txt_type)
if not code:
return jsonify(result="error", message="Code not found"), 404
if datetime.now() > code.expiry_datetime or code.code_used:
if datetime.utcnow() > code.expiry_datetime or code.code_used:
return jsonify(result="error", message="Code has expired"), 400
use_user_code(code.id)
return jsonify({}), 204
@@ -210,8 +211,7 @@ def send_user_reset_password():
def _create_reset_password_url(email):
from notifications_utils.url_safe_token import generate_token
import json
data = json.dumps({'email': email, 'created_at': str(datetime.now())})
data = json.dumps({'email': email, 'created_at': str(datetime.utcnow())})
token = generate_token(data, current_app.config['SECRET_KEY'], current_app.config['DANGEROUS_SALT'])
return current_app.config['ADMIN_BASE_URL'] + '/new-password/' + token
@@ -219,7 +219,6 @@ def _create_reset_password_url(email):
def _create_verification_url(user, secret_code):
from notifications_utils.url_safe_token import generate_token
import json
data = json.dumps({'user_id': str(user.id), 'email': user.email_address, 'secret_code': secret_code})
token = generate_token(data, current_app.config['SECRET_KEY'], current_app.config['DANGEROUS_SALT'])