Set reply_to_text for letter notifications posted to /notifications/letter

This commit is contained in:
Rebecca Law
2017-11-24 16:17:25 +00:00
parent e0d0b2f4fd
commit d779751bae
4 changed files with 29 additions and 7 deletions

View File

@@ -3,7 +3,7 @@ from app.models import LETTER_TYPE
from app.notifications.process_notifications import persist_notification
def create_letter_notification(letter_data, template, api_key, status):
def create_letter_notification(letter_data, template, api_key, status, reply_to_text=None):
notification = persist_notification(
template_id=template.id,
template_version=template.version,
@@ -18,6 +18,7 @@ def create_letter_notification(letter_data, template, api_key, status):
job_row_number=None,
reference=create_random_identifier(),
client_reference=letter_data.get('reference'),
status=status
status=status,
reply_to_text=reply_to_text
)
return notification

View File

@@ -183,8 +183,12 @@ def process_letter_notification(*, letter_data, api_key, template):
# if we don't want to actually send the letter, then start it off in SENDING so we don't pick it up
status = NOTIFICATION_CREATED if should_send else NOTIFICATION_SENDING
notification = create_letter_notification(letter_data, template, api_key, status=status)
letter_contact_block = api_key.service.get_default_letter_contact()
notification = create_letter_notification(letter_data=letter_data,
template=template,
api_key=api_key,
status=status,
reply_to_text=letter_contact_block)
if not should_send:
update_letter_notifications_to_sent_to_dvla.apply_async(

View File

@@ -237,7 +237,6 @@ def valid_email_response():
@freeze_time("2017-05-12 13:00:00")
def test_post_schema_valid_scheduled_for(schema):
j = {"template_id": str(uuid.uuid4()),
"email_address": "joe@gmail.com",
"scheduled_for": "2017-05-12 13:15"}
if schema == post_email_request_schema:
j.update({"email_address": "joe@gmail.com"})

View File

@@ -18,8 +18,7 @@ from app.v2.errors import RateLimitError
from app.v2.notifications.notification_schemas import post_letter_response
from tests import create_authorization_header
from tests.app.db import create_service, create_template
from tests.app.db import create_service, create_template, create_letter_contact
test_address = {
'address_line_1': 'test 1',
@@ -78,6 +77,7 @@ def test_post_letter_notification_returns_201(client, sample_letter_template, mo
) in resp_json['template']['uri']
)
assert not resp_json['scheduled_for']
assert not notification.reply_to_text
def test_post_letter_notification_returns_400_and_missing_template(
@@ -298,3 +298,21 @@ def test_post_letter_notification_fakes_dvla_when_service_is_in_trial_mode_but_u
kwargs={'notification_references': [notification.reference]},
queue='research-mode-tasks'
)
def test_post_letter_notification_persists_notification_reply_to_text(
client, notify_db_session
):
service = create_service(service_permissions=[LETTER_TYPE])
service_address = "12 Main Street, London"
create_letter_contact(service=service, contact_block=service_address, is_default=True)
template = create_template(service=service, template_type='letter')
data = {
"template_id": template.id,
"personalisation": {'address_line_1': 'Foo', 'address_line_2': 'Bar', 'postcode': 'Baz'}
}
letter_request(client, data=data, service_id=service.id, key_type=KEY_TYPE_NORMAL)
notifications = Notification.query.all()
assert len(notifications) == 1
assert notifications[0].reply_to_text == service_address