Update notification status by message reference

- SES sends a reference to allow us to identify the notification
- use this to update status

If source of email is one of our internal emails (invites or validations) - don't try and update a notification.
This commit is contained in:
Martyn Inglis
2016-03-11 10:19:40 +00:00
parent 901d04605f
commit 62a7b8bcd0
5 changed files with 92 additions and 35 deletions

View File

@@ -18,8 +18,8 @@ from app.dao.notifications_dao import (
delete_failed_notifications_created_more_than_a_week_ago,
dao_get_notification_statistics_for_service_and_day,
update_notification_status_by_id,
update_notification_status_by_to,
update_notification_reference_by_id
update_notification_reference_by_id,
update_notification_status_by_reference
)
from tests.app.conftest import sample_job
from tests.app.conftest import sample_notification
@@ -32,6 +32,13 @@ def test_should_by_able_to_update_reference_by_id(sample_notification):
assert Notification.query.get(sample_notification.id).reference == 'reference'
def test_should_by_able_to_update_status_by_reference(sample_notification):
assert Notification.query.get(sample_notification.id).status == "sent"
update_notification_reference_by_id(sample_notification.id, 'reference')
update_notification_status_by_reference('reference', 'delivered')
assert Notification.query.get(sample_notification.id).status == 'delivered'
def test_should_by_able_to_update_status_by_id(sample_notification):
assert Notification.query.get(sample_notification.id).status == 'sent'
count = update_notification_status_by_id(sample_notification.id, 'delivered')
@@ -43,15 +50,8 @@ def test_should_return_zero_count_if_no_notification_with_id():
assert update_notification_status_by_id(str(uuid.uuid4()), 'delivered') == 0
def test_should_return_zero_count_if_no_notification_with_to():
assert update_notification_status_by_to('something', 'delivered') == 0
def test_should_by_able_to_update_status_by_to(sample_notification):
assert Notification.query.get(sample_notification.id).status == 'sent'
count = update_notification_status_by_to(sample_notification.to, 'delivered')
assert count == 1
assert Notification.query.get(sample_notification.id).status == 'delivered'
def test_should_return_zero_count_if_no_notification_with_reference():
assert update_notification_status_by_reference('something', 'delivered') == 0
def test_should_be_able_to_get_statistics_for_a_service(sample_template):