mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 23:55:58 -05:00
Merge branch 'master' into redo-queue-visibitlity-timeout
Conflicts: app/notifications/process_notifications.py app/v2/notifications/post_notifications.py
This commit is contained in:
@@ -7,13 +7,14 @@ from sqlalchemy.exc import SQLAlchemyError
|
||||
from freezegun import freeze_time
|
||||
from collections import namedtuple
|
||||
|
||||
from app.models import Template, Notification, NotificationHistory
|
||||
from app.models import Template, Notification, NotificationHistory, ScheduledNotification
|
||||
from app.notifications import SendNotificationToQueueError
|
||||
from app.notifications.process_notifications import (
|
||||
create_content_for_notification,
|
||||
persist_notification,
|
||||
send_notification_to_queue,
|
||||
simulated_recipient
|
||||
simulated_recipient,
|
||||
persist_scheduled_notification
|
||||
)
|
||||
from notifications_utils.recipients import validate_and_format_phone_number, validate_and_format_email_address
|
||||
from app.utils import cache_key_for_service_template_counter
|
||||
@@ -339,3 +340,75 @@ def test_persist_notification_with_international_info_does_not_store_for_email(
|
||||
assert persisted_notification.international is False
|
||||
assert persisted_notification.phone_prefix is None
|
||||
assert persisted_notification.rate_multiplier is None
|
||||
|
||||
|
||||
def test_persist_scheduled_notification(sample_notification):
|
||||
persist_scheduled_notification(sample_notification.id, '2017-05-12 14:15')
|
||||
scheduled_notification = ScheduledNotification.query.all()
|
||||
assert len(scheduled_notification) == 1
|
||||
assert scheduled_notification[0].notification_id == sample_notification.id
|
||||
assert scheduled_notification[0].scheduled_for == datetime.datetime(2017, 5, 12, 13, 15)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('recipient, expected_recipient_normalised', [
|
||||
('7900900123', '447900900123'),
|
||||
('+447900 900 123', '447900900123'),
|
||||
(' 07700900222', '447700900222'),
|
||||
('07700900222', '447700900222'),
|
||||
(' 73122345678', '73122345678'),
|
||||
('360623400400', '360623400400'),
|
||||
('-077-00900222-', '447700900222'),
|
||||
('(360623(400400)', '360623400400')
|
||||
|
||||
])
|
||||
def test_persist_sms_notification_stores_normalised_number(
|
||||
sample_job,
|
||||
sample_api_key,
|
||||
mocker,
|
||||
recipient,
|
||||
expected_recipient_normalised
|
||||
):
|
||||
persist_notification(
|
||||
template_id=sample_job.template.id,
|
||||
template_version=sample_job.template.version,
|
||||
recipient=recipient,
|
||||
service=sample_job.service,
|
||||
personalisation=None,
|
||||
notification_type='sms',
|
||||
api_key_id=sample_api_key.id,
|
||||
key_type=sample_api_key.key_type,
|
||||
job_id=sample_job.id,
|
||||
)
|
||||
persisted_notification = Notification.query.all()[0]
|
||||
|
||||
assert persisted_notification.to == recipient
|
||||
assert persisted_notification.normalised_to == expected_recipient_normalised
|
||||
|
||||
|
||||
@pytest.mark.parametrize('recipient, expected_recipient_normalised', [
|
||||
('FOO@bar.com', 'foo@bar.com'),
|
||||
('BAR@foo.com', 'bar@foo.com')
|
||||
|
||||
])
|
||||
def test_persist_email_notification_stores_normalised_email(
|
||||
sample_job,
|
||||
sample_api_key,
|
||||
mocker,
|
||||
recipient,
|
||||
expected_recipient_normalised
|
||||
):
|
||||
persist_notification(
|
||||
template_id=sample_job.template.id,
|
||||
template_version=sample_job.template.version,
|
||||
recipient=recipient,
|
||||
service=sample_job.service,
|
||||
personalisation=None,
|
||||
notification_type='email',
|
||||
api_key_id=sample_api_key.id,
|
||||
key_type=sample_api_key.key_type,
|
||||
job_id=sample_job.id,
|
||||
)
|
||||
persisted_notification = Notification.query.all()[0]
|
||||
|
||||
assert persisted_notification.to == recipient
|
||||
assert persisted_notification.normalised_to == expected_recipient_normalised
|
||||
|
||||
Reference in New Issue
Block a user