mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 09:51:11 -05:00
Fixed up dates so that we respect mills
This commit is contained in:
@@ -13,6 +13,8 @@ from app.clients.sms.firetext import FiretextClient
|
||||
from app.clients.email.aws_ses import AwsSesClient
|
||||
from app.encryption import Encryption
|
||||
|
||||
DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%f"
|
||||
|
||||
db = SQLAlchemy()
|
||||
ma = Marshmallow()
|
||||
notify_celery = NotifyCelery()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from app import create_uuid
|
||||
from app import create_uuid, DATETIME_FORMAT
|
||||
from app import notify_celery, encryption, firetext_client, aws_ses_client
|
||||
from app.clients.email.aws_ses import AwsSesClientException
|
||||
from app.clients.sms.firetext import FiretextClientException
|
||||
@@ -38,7 +38,7 @@ def process_job(job_id):
|
||||
str(job.service_id),
|
||||
str(create_uuid()),
|
||||
encrypted,
|
||||
str(datetime.utcnow())),
|
||||
datetime.utcnow().strftime(DATETIME_FORMAT)),
|
||||
queue='bulk-sms'
|
||||
)
|
||||
|
||||
@@ -49,7 +49,7 @@ def process_job(job_id):
|
||||
job.template.subject,
|
||||
"{}@{}".format(job.service.email_from, current_app.config['NOTIFY_EMAIL_DOMAIN']),
|
||||
encrypted,
|
||||
str(datetime.utcnow())),
|
||||
datetime.utcnow().strftime(DATETIME_FORMAT)),
|
||||
queue='bulk-email')
|
||||
|
||||
finished = datetime.utcnow()
|
||||
@@ -88,7 +88,7 @@ def send_sms(service_id, notification_id, encrypted_notification, created_at):
|
||||
service_id=service_id,
|
||||
job_id=notification.get('job', None),
|
||||
status=status,
|
||||
created_at=created_at,
|
||||
created_at=datetime.strptime(created_at, DATETIME_FORMAT),
|
||||
sent_at=sent_at,
|
||||
sent_by=client.get_name()
|
||||
)
|
||||
@@ -158,11 +158,11 @@ def send_email(service_id, notification_id, subject, from_address, encrypted_not
|
||||
service_id=service_id,
|
||||
job_id=notification.get('job', None),
|
||||
status=status,
|
||||
created_at=created_at,
|
||||
created_at=datetime.strptime(created_at, DATETIME_FORMAT),
|
||||
sent_at=sent_at,
|
||||
sent_by=client.get_name()
|
||||
)
|
||||
dao_create_notification(notification_db_object, TEMPLATE_TYPE_SMS)
|
||||
dao_create_notification(notification_db_object, TEMPLATE_TYPE_EMAIL)
|
||||
|
||||
if can_send:
|
||||
try:
|
||||
|
||||
@@ -10,7 +10,7 @@ from flask import (
|
||||
|
||||
from utils.template import Template, NeededByTemplateError, NoPlaceholderForDataError
|
||||
|
||||
from app import api_user, encryption, create_uuid
|
||||
from app import api_user, encryption, create_uuid, DATETIME_FORMAT
|
||||
from app.authentication.auth import require_admin
|
||||
from app.dao import (
|
||||
templates_dao,
|
||||
@@ -178,7 +178,7 @@ def send_notification(notification_type):
|
||||
service_id,
|
||||
notification_id,
|
||||
encryption.encrypt(notification),
|
||||
str(datetime.utcnow())
|
||||
datetime.utcnow().strftime(DATETIME_FORMAT)
|
||||
), queue='sms')
|
||||
else:
|
||||
if service.restricted and notification['to'] not in [user.email_address for user in service.users]:
|
||||
@@ -190,6 +190,6 @@ def send_notification(notification_type):
|
||||
template.subject,
|
||||
"{}@{}".format(service.email_from, current_app.config['NOTIFY_EMAIL_DOMAIN']),
|
||||
encryption.encrypt(notification),
|
||||
str(datetime.utcnow())
|
||||
datetime.utcnow().strftime(DATETIME_FORMAT)
|
||||
), queue='email')
|
||||
return jsonify({'notification_id': notification_id}), 201
|
||||
|
||||
@@ -2,7 +2,7 @@ import uuid
|
||||
import pytest
|
||||
from flask import current_app
|
||||
from app.celery.tasks import (send_sms, send_sms_code, send_email_code, send_email, process_job, email_invited_user)
|
||||
from app import (firetext_client, aws_ses_client, encryption)
|
||||
from app import (firetext_client, aws_ses_client, encryption, DATETIME_FORMAT)
|
||||
from app.clients.email.aws_ses import AwsSesClientException
|
||||
from app.clients.sms.firetext import FiretextClientException
|
||||
from app.dao import notifications_dao, jobs_dao
|
||||
@@ -34,7 +34,7 @@ def test_should_process_sms_job(sample_job, mocker):
|
||||
(str(sample_job.service_id),
|
||||
"uuid",
|
||||
"something_encrypted",
|
||||
"2016-01-01 11:09:00.061258"),
|
||||
"2016-01-01T11:09:00.061258"),
|
||||
queue="bulk-sms"
|
||||
)
|
||||
job = jobs_dao.dao_get_job_by_id(sample_job.id)
|
||||
@@ -69,7 +69,7 @@ def test_should_process_email_job(sample_email_job, mocker):
|
||||
sample_email_job.template.subject,
|
||||
"{}@{}".format(sample_email_job.service.email_from, "test.notify.com"),
|
||||
"something_encrypted",
|
||||
"2016-01-01 11:09:00.061258"),
|
||||
"2016-01-01T11:09:00.061258"),
|
||||
queue="bulk-email"
|
||||
)
|
||||
job = jobs_dao.dao_get_job_by_id(sample_email_job.id)
|
||||
@@ -106,7 +106,7 @@ def test_should_send_template_to_correct_sms_provider_and_persist(sample_templat
|
||||
sample_template_with_placeholders.service_id,
|
||||
notification_id,
|
||||
"encrypted-in-reality",
|
||||
now
|
||||
now.strftime(DATETIME_FORMAT)
|
||||
)
|
||||
|
||||
firetext_client.send_sms.assert_called_once_with("+441234123123", "Sample service: Hello Jo")
|
||||
@@ -138,7 +138,7 @@ def test_should_send_sms_without_personalisation(sample_template, mocker):
|
||||
sample_template.service_id,
|
||||
notification_id,
|
||||
"encrypted-in-reality",
|
||||
now
|
||||
now.strftime(DATETIME_FORMAT)
|
||||
)
|
||||
|
||||
firetext_client.send_sms.assert_called_once_with("+441234123123", "Sample service: This is a template")
|
||||
@@ -164,7 +164,7 @@ def test_should_send_sms_if_restricted_service_and_valid_number(notify_db, notif
|
||||
service.id,
|
||||
notification_id,
|
||||
"encrypted-in-reality",
|
||||
now
|
||||
now.strftime(DATETIME_FORMAT)
|
||||
)
|
||||
|
||||
firetext_client.send_sms.assert_called_once_with("+441234123123", "Sample service: This is a template")
|
||||
@@ -190,7 +190,7 @@ def test_should_not_send_sms_if_restricted_service_and_invalid_number(notify_db,
|
||||
service.id,
|
||||
notification_id,
|
||||
"encrypted-in-reality",
|
||||
now
|
||||
now.strftime(DATETIME_FORMAT)
|
||||
)
|
||||
|
||||
firetext_client.send_sms.assert_not_called()
|
||||
@@ -217,7 +217,8 @@ def test_should_send_email_if_restricted_service_and_valid_email(notify_db, noti
|
||||
'subject',
|
||||
'email_from',
|
||||
"encrypted-in-reality",
|
||||
now)
|
||||
now.strftime(DATETIME_FORMAT)
|
||||
)
|
||||
|
||||
aws_ses_client.send_email.assert_called_once_with(
|
||||
"email_from",
|
||||
@@ -243,8 +244,8 @@ def test_should_send_template_to_correct_sms_provider_and_persist_with_job_id(sa
|
||||
sample_job.service.id,
|
||||
notification_id,
|
||||
"encrypted-in-reality",
|
||||
now)
|
||||
|
||||
now.strftime(DATETIME_FORMAT)
|
||||
)
|
||||
firetext_client.send_sms.assert_called_once_with("+441234123123", "Sample service: This is a template")
|
||||
persisted_notification = notifications_dao.get_notification(sample_job.template.service_id, notification_id)
|
||||
assert persisted_notification.id == notification_id
|
||||
@@ -275,8 +276,8 @@ def test_should_use_email_template_and_persist(sample_email_template_with_placeh
|
||||
'subject',
|
||||
'email_from',
|
||||
"encrypted-in-reality",
|
||||
now)
|
||||
|
||||
now.strftime(DATETIME_FORMAT)
|
||||
)
|
||||
aws_ses_client.send_email.assert_called_once_with(
|
||||
"email_from",
|
||||
"my_email@my_email.com",
|
||||
@@ -313,8 +314,8 @@ def test_should_use_email_template_and_persist_without_personalisation(
|
||||
'subject',
|
||||
'email_from',
|
||||
"encrypted-in-reality",
|
||||
now)
|
||||
|
||||
now.strftime(DATETIME_FORMAT)
|
||||
)
|
||||
aws_ses_client.send_email.assert_called_once_with(
|
||||
"email_from",
|
||||
"my_email@my_email.com",
|
||||
@@ -339,8 +340,8 @@ def test_should_persist_notification_as_failed_if_sms_client_fails(sample_templa
|
||||
sample_template.service_id,
|
||||
notification_id,
|
||||
"encrypted-in-reality",
|
||||
now)
|
||||
|
||||
now.strftime(DATETIME_FORMAT)
|
||||
)
|
||||
firetext_client.send_sms.assert_called_once_with("+441234123123", "Sample service: This is a template")
|
||||
persisted_notification = notifications_dao.get_notification(sample_template.service_id, notification_id)
|
||||
assert persisted_notification.id == notification_id
|
||||
@@ -371,8 +372,8 @@ def test_should_persist_notification_as_failed_if_email_client_fails(sample_emai
|
||||
'subject',
|
||||
'email_from',
|
||||
"encrypted-in-reality",
|
||||
now)
|
||||
|
||||
now.strftime(DATETIME_FORMAT)
|
||||
)
|
||||
aws_ses_client.send_email.assert_called_once_with(
|
||||
"email_from",
|
||||
"my_email@my_email.com",
|
||||
@@ -405,8 +406,8 @@ def test_should_not_send_sms_if_db_peristance_failed(sample_template, mocker):
|
||||
sample_template.service_id,
|
||||
notification_id,
|
||||
"encrypted-in-reality",
|
||||
now)
|
||||
|
||||
now.strftime(DATETIME_FORMAT)
|
||||
)
|
||||
firetext_client.send_sms.assert_not_called()
|
||||
with pytest.raises(NoResultFound) as e:
|
||||
notifications_dao.get_notification(sample_template.service_id, notification_id)
|
||||
@@ -431,8 +432,8 @@ def test_should_not_send_email_if_db_peristance_failed(sample_email_template, mo
|
||||
'subject',
|
||||
'email_from',
|
||||
"encrypted-in-reality",
|
||||
now)
|
||||
|
||||
now.strftime(DATETIME_FORMAT)
|
||||
)
|
||||
aws_ses_client.send_email.assert_not_called()
|
||||
with pytest.raises(NoResultFound) as e:
|
||||
notifications_dao.get_notification(sample_email_template.service_id, notification_id)
|
||||
|
||||
@@ -359,7 +359,7 @@ def test_send_notification_with_placeholders_replaced(notify_api, sample_templat
|
||||
(str(sample_template_with_placeholders.service.id),
|
||||
notification_id,
|
||||
"something_encrypted",
|
||||
"2016-01-01 11:09:00.061258"),
|
||||
"2016-01-01T11:09:00.061258"),
|
||||
queue="sms"
|
||||
)
|
||||
assert response.status_code == 201
|
||||
@@ -525,7 +525,7 @@ def test_should_allow_valid_sms_notification(notify_api, sample_template, mocker
|
||||
(str(sample_template.service_id),
|
||||
notification_id,
|
||||
"something_encrypted",
|
||||
"2016-01-01 11:09:00.061258"),
|
||||
"2016-01-01T11:09:00.061258"),
|
||||
queue="sms"
|
||||
)
|
||||
assert response.status_code == 201
|
||||
@@ -747,7 +747,7 @@ def test_should_allow_valid_email_notification(notify_api, sample_email_template
|
||||
"Email Subject",
|
||||
"sample.service@test.notify.com",
|
||||
"something_encrypted",
|
||||
"2016-01-01 11:09:00.061258"),
|
||||
"2016-01-01T11:09:00.061258"),
|
||||
queue="email"
|
||||
)
|
||||
assert response.status_code == 201
|
||||
|
||||
Reference in New Issue
Block a user