Skip to content

Commit

Permalink
Added test around params building for delivery tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
jimleroyer committed Oct 26, 2023
1 parent 77dd00f commit d80087a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/notifications/process_notifications.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand Down
28 changes: 28 additions & 0 deletions tests/app/notifications/test_process_notification.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import uuid
from typing import Any, Dict
from unittest.mock import call

import pytest
Expand All @@ -14,14 +15,20 @@
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,
Template,
)
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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d80087a

Please sign in to comment.