mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
Persist normalised email
This commit is contained in:
@@ -4,7 +4,8 @@ from flask import current_app
|
|||||||
|
|
||||||
from notifications_utils.recipients import (
|
from notifications_utils.recipients import (
|
||||||
get_international_phone_info,
|
get_international_phone_info,
|
||||||
validate_and_format_phone_number
|
validate_and_format_phone_number,
|
||||||
|
format_email_address
|
||||||
)
|
)
|
||||||
|
|
||||||
from app import redis_store
|
from app import redis_store
|
||||||
@@ -76,6 +77,8 @@ def persist_notification(
|
|||||||
notification.international = recipient_info.international
|
notification.international = recipient_info.international
|
||||||
notification.phone_prefix = recipient_info.country_prefix
|
notification.phone_prefix = recipient_info.country_prefix
|
||||||
notification.rate_multiplier = recipient_info.billable_units
|
notification.rate_multiplier = recipient_info.billable_units
|
||||||
|
elif notification_type == EMAIL_TYPE:
|
||||||
|
notification.normalised_to = format_email_address(notification.to)
|
||||||
|
|
||||||
# if simulated create a Notification model to return but do not persist the Notification to the dB
|
# if simulated create a Notification model to return but do not persist the Notification to the dB
|
||||||
if not simulated:
|
if not simulated:
|
||||||
|
|||||||
@@ -383,3 +383,32 @@ def test_persist_sms_notification_stores_normalised_number(
|
|||||||
|
|
||||||
assert persisted_notification.to == recipient
|
assert persisted_notification.to == recipient
|
||||||
assert persisted_notification.normalised_to == expected_recipient_normalised
|
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