diff --git a/app/notifications/process_notifications.py b/app/notifications/process_notifications.py index 204574bc8d..ce979d9b71 100644 --- a/app/notifications/process_notifications.py +++ b/app/notifications/process_notifications.py @@ -1,6 +1,6 @@ import uuid from datetime import datetime -from typing import Any, List +from typing import Any, Dict, List from flask import current_app from notifications_utils.clients import redis @@ -224,7 +224,7 @@ def db_save_and_send_notification(notification: Notification): ) -def build_delivery_task_params(notification_type: str, notification_process_type: str): +def build_delivery_task_params(notification_type: str, notification_process_type: str) -> Dict[str, Any]: """ Build task params for the sending parameter tasks. diff --git a/tests/app/notifications/test_process_notification.py b/tests/app/notifications/test_process_notification.py index 6b4f4f7467..25aa093630 100644 --- a/tests/app/notifications/test_process_notification.py +++ b/tests/app/notifications/test_process_notification.py @@ -1,5 +1,6 @@ import datetime import uuid +from typing import Any, Dict from unittest.mock import call import pytest @@ -14,7 +15,12 @@ from app.config import QueueNames from app.dao.service_sms_sender_dao import dao_update_service_sms_sender from app.models import ( + BULK, + EMAIL_TYPE, LETTER_TYPE, + NORMAL, + PRIORITY, + SMS_TYPE, Notification, NotificationHistory, ScheduledNotification, @@ -22,6 +28,7 @@ ) from app.notifications import RETRY_POLICY_DEFAULT from app.notifications.process_notifications import ( + build_delivery_task_params, choose_queue, create_content_for_notification, db_save_and_send_notification, @@ -1090,6 +1097,27 @@ def test_db_save_and_send_notification_throws_exception_deletes_notification( assert Notification.query.count() == 0 assert NotificationHistory.query.count() == 0 + @pytest.mark.parametrize( + ("notification_type, process_type, expected_retry, expected_retry_period"), + [ + (EMAIL_TYPE, BULK, 48, 300), + (EMAIL_TYPE, NORMAL, 48, 300), + (EMAIL_TYPE, PRIORITY, 48, 300), + (SMS_TYPE, BULK, 48, 300), + (SMS_TYPE, NORMAL, 48, 300), + (SMS_TYPE, PRIORITY, 48, 26), + ], + ) + def test_delivery_task_parameters(self, notification_type, process_type, expected_retry, expected_retry_period): + params: Dict[str, Any] = build_delivery_task_params(notification_type, process_type) + assert params["retry"] is True + + retry_policy: Dict[str, Any] = params["retry_policy"] + assert retry_policy["max_retries"] == expected_retry + assert retry_policy["interval_start"] == expected_retry_period + assert retry_policy["interval_step"] == expected_retry_period + assert retry_policy["interval_max"] == expected_retry_period + def test_db_save_and_send_notification_throws_exception_when_missing_template(self, sample_api_key, mocker): mocker.patch("app.celery.provider_tasks.deliver_sms.apply_async") assert Notification.query.count() == 0