diff --git a/app/delivery/send_to_providers.py b/app/delivery/send_to_providers.py index c50858ccb..3f92e54d1 100644 --- a/app/delivery/send_to_providers.py +++ b/app/delivery/send_to_providers.py @@ -28,7 +28,8 @@ from app.models import ( EMAIL_TYPE, NOTIFICATION_TECHNICAL_FAILURE, NOTIFICATION_SENT, - NOTIFICATION_SENDING + NOTIFICATION_SENDING, + NOTIFICATION_STATUS_TYPES_COMPLETED ) @@ -125,7 +126,8 @@ def send_email_to_provider(notification): def update_notification_to_sending(notification, provider): notification.sent_at = datetime.utcnow() notification.sent_by = provider.get_name() - notification.status = NOTIFICATION_SENT if notification.international else NOTIFICATION_SENDING + if notification.status not in NOTIFICATION_STATUS_TYPES_COMPLETED: + notification.status = NOTIFICATION_SENT if notification.international else NOTIFICATION_SENDING dao_update_notification(notification) diff --git a/tests/app/delivery/test_send_to_providers.py b/tests/app/delivery/test_send_to_providers.py index dc19ff4ee..367f86059 100644 --- a/tests/app/delivery/test_send_to_providers.py +++ b/tests/app/delivery/test_send_to_providers.py @@ -9,7 +9,7 @@ from notifications_utils.recipients import validate_and_format_phone_number from requests import HTTPError import app -from app import mmg_client, firetext_client +from app import clients, mmg_client, firetext_client from app.dao import notifications_dao from app.dao.provider_details_dao import get_provider_details_by_identifier from app.delivery import send_to_providers @@ -525,6 +525,20 @@ def test_should_not_update_notification_if_research_mode_on_exception( assert update_mock.called +@pytest.mark.parametrize("starting_status, expected_status", [ + ("delivered", "delivered"), + ("created", "sending"), + ("technical-failure", "technical-failure"), +]) +def test_update_notification_to_sending_does_not_update_status_from_a_final_status( + sample_service, notify_db_session, starting_status, expected_status +): + template = create_template(sample_service) + notification = create_notification(template=template, status=starting_status) + send_to_providers.update_notification_to_sending(notification, clients.get_client_by_name_and_type("mmg", "sms")) + assert notification.status == expected_status + + def __update_notification(notification_to_update, research_mode, expected_status): if research_mode or notification_to_update.key_type == KEY_TYPE_TEST: notification_to_update.status = expected_status