Only send to the provider if the notification has a created status.

If the notification ends up in the retry queue and the delivery app is restarted the notification will get sent twice.
This is because when the app is restarted another message will be in the retry queue as message available which is a
duplicate of the one in the queue that is a  message in flight.

This should complete https://www.pivotaltracker.com/story/show/121844427
This commit is contained in:
Rebecca Law
2016-06-27 14:47:20 +01:00
parent 8f19ad19f8
commit 8a0211b3eb
6 changed files with 69 additions and 58 deletions

View File

@@ -5,6 +5,8 @@ from datetime import (
timedelta
)
from tests.app.conftest import sample_notification
def test_get_delivery_status_all_ok(notify_api, notify_db):
with notify_api.test_request_context():
@@ -17,11 +19,12 @@ def test_get_delivery_status_all_ok(notify_api, notify_db):
assert resp_json['message'] == '0 notifications in sending state over 5 minutes'
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, notify_db_session):
notification = sample_notification(notify_db=notify_db, notify_db_session=notify_db_session, status='sending')
more_than_five_mins_ago = datetime.utcnow() - timedelta(minutes=10)
sample_notification.created_at = more_than_five_mins_ago
notify_db.session.add(sample_notification)
notification.created_at = more_than_five_mins_ago
notify_db.session.add(notification)
notify_db.session.commit()
with notify_api.test_request_context():