mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
Updated send_to_providers.py to use the notification email_reply_to address if there is one present otherwise it uses the service email_reply_to so now users can choose a per notification email_reply_to address.
This commit is contained in:
@@ -28,7 +28,7 @@ from app.models import (
|
||||
KEY_TYPE_NORMAL,
|
||||
ServiceInboundApi,
|
||||
ServiceEmailReplyTo,
|
||||
ServiceLetterContact, ServiceSmsSender)
|
||||
ServiceLetterContact, ServiceSmsSender, NotificationEmailReplyTo)
|
||||
from app.dao.users_dao import save_model_user
|
||||
from app.dao.notifications_dao import dao_create_notification, dao_created_scheduled_notification
|
||||
from app.dao.templates_dao import dao_create_template
|
||||
@@ -384,3 +384,21 @@ def create_letter_contact(
|
||||
db.session.commit()
|
||||
|
||||
return letter_content
|
||||
|
||||
|
||||
def create_reply_to_email_for_notification(
|
||||
notification_id,
|
||||
service,
|
||||
email_address,
|
||||
is_default=True
|
||||
):
|
||||
reply_to = create_reply_to_email(service, email_address, is_default)
|
||||
|
||||
notification_email_reply_to = NotificationEmailReplyTo(
|
||||
notification_id=str(notification_id),
|
||||
service_email_reply_to_id=str(reply_to.id)
|
||||
)
|
||||
db.session.add(notification_email_reply_to)
|
||||
db.session.commit()
|
||||
|
||||
return reply_to
|
||||
|
||||
@@ -6,6 +6,7 @@ from unittest.mock import ANY, call
|
||||
import pytest
|
||||
from notifications_utils.recipients import validate_and_format_phone_number
|
||||
from flask import current_app
|
||||
from requests_mock import mock
|
||||
|
||||
import app
|
||||
from app import mmg_client, firetext_client
|
||||
@@ -21,10 +22,10 @@ from app.models import (
|
||||
BRANDING_ORG,
|
||||
BRANDING_GOVUK,
|
||||
BRANDING_BOTH,
|
||||
BRANDING_ORG_BANNER)
|
||||
BRANDING_ORG_BANNER, NotificationEmailReplyTo)
|
||||
|
||||
from tests.app.db import create_service, create_template, create_notification, create_inbound_number, \
|
||||
create_reply_to_email
|
||||
create_reply_to_email, create_reply_to_email_for_notification
|
||||
|
||||
|
||||
def test_should_return_highest_priority_active_provider(restore_provider_details):
|
||||
@@ -697,3 +698,65 @@ def test_should_use_inbound_number_as_sender_if_set(
|
||||
reference=str(notification.id),
|
||||
sender=inbound_number.number
|
||||
)
|
||||
|
||||
|
||||
def test_send_email_to_provider_get_linked_email_reply_to_default_is_false(
|
||||
sample_service,
|
||||
sample_email_template,
|
||||
mocker):
|
||||
mocker.patch('app.aws_ses_client.send_email', return_value='reference')
|
||||
mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
db_notification = create_notification(template=sample_email_template)
|
||||
create_reply_to_email(service=sample_service, email_address='foo@bar.com')
|
||||
|
||||
reply_to = create_reply_to_email_for_notification(
|
||||
db_notification.id,
|
||||
sample_service,
|
||||
"test@test.com",
|
||||
is_default=False
|
||||
)
|
||||
|
||||
send_to_providers.send_email_to_provider(
|
||||
db_notification,
|
||||
)
|
||||
|
||||
app.aws_ses_client.send_email.assert_called_once_with(
|
||||
ANY,
|
||||
ANY,
|
||||
ANY,
|
||||
body=ANY,
|
||||
html_body=ANY,
|
||||
reply_to_address=reply_to.email_address
|
||||
)
|
||||
|
||||
|
||||
def test_send_email_to_provider_get_linked_email_reply_to_create_service_email_after_notification_mapping(
|
||||
sample_service,
|
||||
sample_email_template,
|
||||
mocker):
|
||||
mocker.patch('app.aws_ses_client.send_email', return_value='reference')
|
||||
mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
db_notification = create_notification(template=sample_email_template)
|
||||
|
||||
reply_to = create_reply_to_email_for_notification(
|
||||
db_notification.id,
|
||||
sample_service,
|
||||
"test@test.com"
|
||||
)
|
||||
|
||||
create_reply_to_email(service=sample_service, email_address='foo@bar.com', is_default=False)
|
||||
|
||||
send_to_providers.send_email_to_provider(
|
||||
db_notification,
|
||||
)
|
||||
|
||||
app.aws_ses_client.send_email.assert_called_once_with(
|
||||
ANY,
|
||||
ANY,
|
||||
ANY,
|
||||
body=ANY,
|
||||
html_body=ANY,
|
||||
reply_to_address=reply_to.email_address
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user