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

@@ -23,7 +23,7 @@ def test_get_notification_by_id(notify_api, sample_notification):
headers=[auth_header])
notification = json.loads(response.get_data(as_text=True))['data']['notification']
assert notification['status'] == 'sending'
assert notification['status'] == 'created'
assert notification['template'] == {
'id': str(sample_notification.template.id),
'name': sample_notification.template.name,
@@ -63,7 +63,7 @@ def test_get_all_notifications(notify_api, sample_notification):
headers=[auth_header])
notifications = json.loads(response.get_data(as_text=True))
assert notifications['notifications'][0]['status'] == 'sending'
assert notifications['notifications'][0]['status'] == 'created'
assert notifications['notifications'][0]['template'] == {
'id': str(sample_notification.template.id),
'name': sample_notification.template.name,
@@ -459,7 +459,8 @@ def test_filter_by_multiple_statuss(notify_api,
notify_db,
notify_db_session,
service=sample_email_template.service,
template=sample_email_template)
template=sample_email_template,
status='sending')
auth_header = create_authorization_header(service_id=sample_email_template.service_id)
@@ -645,7 +646,7 @@ def test_firetext_callback_should_update_notification_status(notify_api, sample_
with notify_api.test_client() as client:
mocker.patch('app.statsd_client.incr')
original = get_notification_by_id(sample_notification.id)
assert original.status == 'sending'
assert original.status == 'created'
response = client.post(
path='/notifications/sms/firetext',
@@ -674,7 +675,7 @@ def test_firetext_callback_should_update_notification_status_failed(notify_api,
with notify_api.test_client() as client:
mocker.patch('app.statsd_client.incr')
original = get_notification_by_id(sample_notification.id)
assert original.status == 'sending'
assert original.status == 'created'
response = client.post(
path='/notifications/sms/firetext',
@@ -966,7 +967,8 @@ def test_ses_callback_should_update_notification_status(
notify_db,
notify_db_session,
template=sample_email_template,
reference='ref'
reference='ref',
status='sending'
)
assert get_notification_by_id(notification.id).status == 'sending'
@@ -1056,7 +1058,8 @@ def test_ses_callback_should_update_record_statsd(
notify_db,
notify_db_session,
template=sample_email_template,
reference='ref'
reference='ref',
status='sending'
)
assert get_notification_by_id(notification.id).status == 'sending'
@@ -1079,7 +1082,8 @@ def test_ses_callback_should_set_status_to_temporary_failure(notify_api,
notify_db,
notify_db_session,
template=sample_email_template,
reference='ref'
reference='ref',
status='sending'
)
assert get_notification_by_id(notification.id).status == 'sending'
@@ -1138,7 +1142,8 @@ def test_ses_callback_should_set_status_to_permanent_failure(notify_api,
notify_db,
notify_db_session,
template=sample_email_template,
reference='ref'
reference='ref',
status='sending'
)
assert get_notification_by_id(notification.id).status == 'sending'