Added the mapping between notification and reply to email to the database and persisted the mapping when the request is received by the end point. the end point also checks if the reply to email id exists and if not returns an error. Also added tests to test the functionality.

This commit is contained in:
Richard Chapman
2017-10-05 11:33:20 +01:00
parent 68d8999b1c
commit d2168b7985
7 changed files with 171 additions and 13 deletions

View File

@@ -40,7 +40,7 @@ from app.models import (
KEY_TYPE_NORMAL, KEY_TYPE_TEST,
LETTER_TYPE,
NOTIFICATION_SENT,
)
NotificationEmailReplyTo, ServiceEmailReplyTo)
from app.dao.dao_utils import transactional
from app.statsd_decorators import statsd
@@ -603,3 +603,23 @@ def dao_set_created_live_letter_api_notifications_to_pending():
db.session.commit()
return notifications
@transactional
def dao_create_notification_email_reply_to_mapping(notification_id, email_reply_to_id):
notification_email_reply_to = NotificationEmailReplyTo(
notification_id=notification_id,
service_email_reply_to_id=email_reply_to_id
)
db.session.add(notification_email_reply_to)
def dao_get_notification_email_reply_for_notification(notification_id):
email_reply_to = ServiceEmailReplyTo.query.join(
NotificationEmailReplyTo
).filter(
NotificationEmailReplyTo.notification_id == notification_id
).all()
if len(email_reply_to) == 1:
return email_reply_to[0].email_address