mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-22 08:21:13 -05:00
Don't update sent notifications (dao)
This commit is contained in:
@@ -175,11 +175,14 @@ def _update_notification_status(notification, status):
|
||||
def update_notification_status_by_id(notification_id, status):
|
||||
notification = Notification.query.with_lockmode("update").filter(
|
||||
Notification.id == notification_id,
|
||||
or_(Notification.status == NOTIFICATION_CREATED,
|
||||
or_(
|
||||
Notification.status == NOTIFICATION_CREATED,
|
||||
Notification.status == NOTIFICATION_SENDING,
|
||||
Notification.status == NOTIFICATION_PENDING)).first()
|
||||
Notification.status == NOTIFICATION_PENDING,
|
||||
Notification.status == NOTIFICATION_SENT
|
||||
)).first()
|
||||
|
||||
if not notification:
|
||||
if not notification or notification.status == NOTIFICATION_SENT:
|
||||
return None
|
||||
|
||||
return _update_notification_status(
|
||||
@@ -193,10 +196,13 @@ def update_notification_status_by_id(notification_id, status):
|
||||
def update_notification_status_by_reference(reference, status):
|
||||
notification = Notification.query.filter(
|
||||
Notification.reference == reference,
|
||||
or_(Notification.status == NOTIFICATION_SENDING,
|
||||
Notification.status == NOTIFICATION_PENDING)).first()
|
||||
or_(
|
||||
Notification.status == NOTIFICATION_SENDING,
|
||||
Notification.status == NOTIFICATION_PENDING,
|
||||
Notification.status == NOTIFICATION_SENT
|
||||
)).first()
|
||||
|
||||
if not notification:
|
||||
if not notification or notification.status == NOTIFICATION_SENT:
|
||||
return None
|
||||
|
||||
return _update_notification_status(
|
||||
|
||||
@@ -15,6 +15,7 @@ from app.models import (
|
||||
TemplateStatistics,
|
||||
NOTIFICATION_STATUS_TYPES,
|
||||
NOTIFICATION_STATUS_TYPES_FAILED,
|
||||
NOTIFICATION_SENT,
|
||||
KEY_TYPE_NORMAL,
|
||||
KEY_TYPE_TEAM,
|
||||
KEY_TYPE_TEST
|
||||
@@ -353,11 +354,27 @@ def test_should_update_status_by_id_if_created(notify_db, notify_db_session):
|
||||
|
||||
|
||||
def test_should_not_update_status_by_reference_if_in_sent_status(notify_db, notify_db_session):
|
||||
assert 1 == 2
|
||||
notification = sample_notification(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
status=NOTIFICATION_SENT,
|
||||
reference='foo'
|
||||
)
|
||||
|
||||
update_notification_status_by_reference('foo', 'failed')
|
||||
assert Notification.query.get(notification.id).status == NOTIFICATION_SENT
|
||||
|
||||
|
||||
def test_should_not_update_status_by_id_if_in_sent_status(notify_db, notify_db_session):
|
||||
assert 1 == 2
|
||||
notification = sample_notification(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
status=NOTIFICATION_SENT
|
||||
)
|
||||
|
||||
update_notification_status_by_id(notification.id, 'failed')
|
||||
|
||||
assert Notification.query.get(notification.id).status == NOTIFICATION_SENT
|
||||
|
||||
|
||||
def test_should_not_update_status_by_reference_if_not_sending(notify_db, notify_db_session):
|
||||
|
||||
Reference in New Issue
Block a user