mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-24 16:23:44 -04:00
Update now to utcnow. All tests passing.
This commit is contained in:
@@ -12,7 +12,7 @@ def create_secret_code():
|
|||||||
def save_model_user(usr, update_dict={}, pwd=None):
|
def save_model_user(usr, update_dict={}, pwd=None):
|
||||||
if pwd:
|
if pwd:
|
||||||
usr.password = pwd
|
usr.password = pwd
|
||||||
usr.password_changed_at = datetime.now()
|
usr.password_changed_at = datetime.utcnow()
|
||||||
if update_dict:
|
if update_dict:
|
||||||
if update_dict.get('id'):
|
if update_dict.get('id'):
|
||||||
del update_dict['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):
|
def create_user_code(user, code, code_type):
|
||||||
verify_code = VerifyCode(code_type=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)
|
user=user)
|
||||||
verify_code.code = code
|
verify_code.code = code
|
||||||
db.session.add(verify_code)
|
db.session.add(verify_code)
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ def create_history(obj):
|
|||||||
|
|
||||||
if not obj.version:
|
if not obj.version:
|
||||||
obj.version = 1
|
obj.version = 1
|
||||||
obj.created_at = datetime.datetime.now()
|
obj.created_at = datetime.datetime.utcnow()
|
||||||
else:
|
else:
|
||||||
obj.version += 1
|
obj.version += 1
|
||||||
|
|
||||||
|
|||||||
@@ -81,13 +81,13 @@ class Service(db.Model, Versioned):
|
|||||||
index=False,
|
index=False,
|
||||||
unique=False,
|
unique=False,
|
||||||
nullable=False,
|
nullable=False,
|
||||||
default=datetime.datetime.now)
|
default=datetime.datetime.utcnow)
|
||||||
updated_at = db.Column(
|
updated_at = db.Column(
|
||||||
db.DateTime,
|
db.DateTime,
|
||||||
index=False,
|
index=False,
|
||||||
unique=False,
|
unique=False,
|
||||||
nullable=True,
|
nullable=True,
|
||||||
onupdate=datetime.datetime.now)
|
onupdate=datetime.datetime.utcnow)
|
||||||
active = db.Column(db.Boolean, index=False, unique=False, nullable=False)
|
active = db.Column(db.Boolean, index=False, unique=False, nullable=False)
|
||||||
message_limit = db.Column(db.BigInteger, index=False, unique=False, nullable=False)
|
message_limit = db.Column(db.BigInteger, index=False, unique=False, nullable=False)
|
||||||
users = db.relationship(
|
users = db.relationship(
|
||||||
@@ -114,13 +114,13 @@ class ApiKey(db.Model, Versioned):
|
|||||||
index=False,
|
index=False,
|
||||||
unique=False,
|
unique=False,
|
||||||
nullable=False,
|
nullable=False,
|
||||||
default=datetime.datetime.now)
|
default=datetime.datetime.utcnow)
|
||||||
updated_at = db.Column(
|
updated_at = db.Column(
|
||||||
db.DateTime,
|
db.DateTime,
|
||||||
index=False,
|
index=False,
|
||||||
unique=False,
|
unique=False,
|
||||||
nullable=True,
|
nullable=True,
|
||||||
onupdate=datetime.datetime.now)
|
onupdate=datetime.datetime.utcnow)
|
||||||
created_by = db.relationship('User')
|
created_by = db.relationship('User')
|
||||||
created_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), index=True, nullable=False)
|
created_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), index=True, nullable=False)
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ def show_delivery_status():
|
|||||||
return jsonify(status="ok"), 200
|
return jsonify(status="ok"), 200
|
||||||
else:
|
else:
|
||||||
notifications_alert = current_app.config['NOTIFICATIONS_ALERT']
|
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',
|
notifications = Notification.query.filter(Notification.status == 'sending',
|
||||||
Notification.created_at < some_number_of_minutes_ago).all()
|
Notification.created_at < some_number_of_minutes_ago).all()
|
||||||
message = "{} notifications in sending state over {} minutes".format(len(notifications), notifications_alert)
|
message = "{} notifications in sending state over {} minutes".format(len(notifications), notifications_alert)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from flask import (jsonify, request, abort, Blueprint, current_app)
|
from flask import (jsonify, request, abort, Blueprint, current_app)
|
||||||
from app import encryption
|
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)
|
code = get_user_code(user_to_verify, txt_code, txt_type)
|
||||||
if not code:
|
if not code:
|
||||||
return jsonify(result="error", message="Code not found"), 404
|
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
|
return jsonify(result="error", message="Code has expired"), 400
|
||||||
use_user_code(code.id)
|
use_user_code(code.id)
|
||||||
return jsonify({}), 204
|
return jsonify({}), 204
|
||||||
@@ -210,8 +211,7 @@ def send_user_reset_password():
|
|||||||
|
|
||||||
def _create_reset_password_url(email):
|
def _create_reset_password_url(email):
|
||||||
from notifications_utils.url_safe_token import generate_token
|
from notifications_utils.url_safe_token import generate_token
|
||||||
import json
|
data = json.dumps({'email': email, 'created_at': str(datetime.utcnow())})
|
||||||
data = json.dumps({'email': email, 'created_at': str(datetime.now())})
|
|
||||||
token = generate_token(data, current_app.config['SECRET_KEY'], current_app.config['DANGEROUS_SALT'])
|
token = generate_token(data, current_app.config['SECRET_KEY'], current_app.config['DANGEROUS_SALT'])
|
||||||
|
|
||||||
return current_app.config['ADMIN_BASE_URL'] + '/new-password/' + token
|
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):
|
def _create_verification_url(user, secret_code):
|
||||||
from notifications_utils.url_safe_token import generate_token
|
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})
|
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'])
|
token = generate_token(data, current_app.config['SECRET_KEY'], current_app.config['DANGEROUS_SALT'])
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ def test_authentication_passes_when_service_has_multiple_keys_some_expired(
|
|||||||
with notify_api.test_client() as client:
|
with notify_api.test_client() as client:
|
||||||
expired_key_data = {'service': sample_api_key.service,
|
expired_key_data = {'service': sample_api_key.service,
|
||||||
'name': 'expired_key',
|
'name': 'expired_key',
|
||||||
'expiry_date': datetime.now(),
|
'expiry_date': datetime.utcnow(),
|
||||||
'created_by': sample_api_key.created_by
|
'created_by': sample_api_key.created_by
|
||||||
}
|
}
|
||||||
expired_key = ApiKey(**expired_key_data)
|
expired_key = ApiKey(**expired_key_data)
|
||||||
@@ -166,7 +166,7 @@ def test_authentication_returns_token_expired_when_service_uses_expired_key_and_
|
|||||||
expire_the_key = {'id': expired_api_key.id,
|
expire_the_key = {'id': expired_api_key.id,
|
||||||
'service': sample_api_key.service,
|
'service': sample_api_key.service,
|
||||||
'name': 'expired_key',
|
'name': 'expired_key',
|
||||||
'expiry_date': datetime.now() + timedelta(hours=-2),
|
'expiry_date': datetime.utcnow() + timedelta(hours=-2),
|
||||||
'created_by': sample_api_key.created_by}
|
'created_by': sample_api_key.created_by}
|
||||||
save_model_api_key(expired_api_key, expire_the_key)
|
save_model_api_key(expired_api_key, expire_the_key)
|
||||||
response = client.get(
|
response = client.get(
|
||||||
|
|||||||
@@ -781,7 +781,7 @@ def test_email_invited_user_should_send_email(notify_api, mocker):
|
|||||||
'service_id': '123123',
|
'service_id': '123123',
|
||||||
'service_name': 'Blacksmith Service',
|
'service_name': 'Blacksmith Service',
|
||||||
'token': 'the-token',
|
'token': 'the-token',
|
||||||
'expiry_date': str(datetime.now() + timedelta(days=1))
|
'expiry_date': str(datetime.utcnow() + timedelta(days=1))
|
||||||
}
|
}
|
||||||
|
|
||||||
mocker.patch('app.aws_ses_client.send_email')
|
mocker.patch('app.aws_ses_client.send_email')
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from app.models import ProviderRates
|
|||||||
|
|
||||||
|
|
||||||
def test_create_provider_rates(notify_db, notify_db_session, mmg_provider_name):
|
def test_create_provider_rates(notify_db, notify_db_session, mmg_provider_name):
|
||||||
now = datetime.now()
|
now = datetime.utcnow()
|
||||||
rate = Decimal("1.00000")
|
rate = Decimal("1.00000")
|
||||||
create_provider_rates(mmg_provider_name, now, rate)
|
create_provider_rates(mmg_provider_name, now, rate)
|
||||||
assert ProviderRates.query.count() == 1
|
assert ProviderRates.query.count() == 1
|
||||||
|
|||||||
@@ -41,9 +41,10 @@ def test_create_invited_user(notify_api, sample_service, mocker):
|
|||||||
assert json_resp['data']['permissions'] == 'send_messages,manage_service,manage_api_keys'
|
assert json_resp['data']['permissions'] == 'send_messages,manage_service,manage_api_keys'
|
||||||
assert json_resp['data']['id']
|
assert json_resp['data']['id']
|
||||||
invitation_expiration_days = notify_api.config['INVITATION_EXPIRATION_DAYS']
|
invitation_expiration_days = notify_api.config['INVITATION_EXPIRATION_DAYS']
|
||||||
expiry_date = (datetime.now() + timedelta(days=invitation_expiration_days)).replace(hour=0, minute=0,
|
expiry_date = (datetime.utcnow() + timedelta(days=invitation_expiration_days)).replace(hour=0,
|
||||||
second=0,
|
minute=0,
|
||||||
microsecond=0)
|
second=0,
|
||||||
|
microsecond=0)
|
||||||
encrypted_invitation = {'to': email_address,
|
encrypted_invitation = {'to': email_address,
|
||||||
'user_name': invite_from.name,
|
'user_name': invite_from.name,
|
||||||
'service_id': str(sample_service.id),
|
'service_id': str(sample_service.id),
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ def test_get_delivery_status_all_ok(notify_api, notify_db):
|
|||||||
|
|
||||||
def test_get_delivery_status_with_undelivered_notification(notify_api, notify_db, sample_notification):
|
def test_get_delivery_status_with_undelivered_notification(notify_api, notify_db, sample_notification):
|
||||||
|
|
||||||
more_than_five_mins_ago = datetime.now() - timedelta(minutes=10)
|
more_than_five_mins_ago = datetime.utcnow() - timedelta(minutes=10)
|
||||||
sample_notification.created_at = more_than_five_mins_ago
|
sample_notification.created_at = more_than_five_mins_ago
|
||||||
notify_db.session.add(sample_notification)
|
notify_db.session.add(sample_notification)
|
||||||
notify_db.session.commit()
|
notify_db.session.commit()
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ def test_user_verify_code_email_expired_code(notify_api,
|
|||||||
with notify_api.test_client() as client:
|
with notify_api.test_client() as client:
|
||||||
assert not VerifyCode.query.first().code_used
|
assert not VerifyCode.query.first().code_used
|
||||||
sample_email_code.expiry_datetime = (
|
sample_email_code.expiry_datetime = (
|
||||||
datetime.now() - timedelta(hours=1))
|
datetime.utcnow() - timedelta(hours=1))
|
||||||
db.session.add(sample_email_code)
|
db.session.add(sample_email_code)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
data = json.dumps({
|
data = json.dumps({
|
||||||
|
|||||||
Reference in New Issue
Block a user