mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 08:51:30 -05:00
Update save_letter task to save the default letter contact block when creating the notification.
This commit is contained in:
@@ -303,7 +303,8 @@ def save_letter(
|
||||
job_id=notification['job'],
|
||||
job_row_number=notification['row_number'],
|
||||
notification_id=notification_id,
|
||||
reference=create_random_identifier()
|
||||
reference=create_random_identifier(),
|
||||
reply_to_text=service.get_default_letter_contact()
|
||||
)
|
||||
|
||||
current_app.logger.info("Letter {} created at {}".format(saved_notification.id, saved_notification.created_at))
|
||||
|
||||
@@ -200,15 +200,15 @@ def process_letter_notification(*, letter_data, api_key, template):
|
||||
|
||||
|
||||
def get_reply_to_text(notification_type, form):
|
||||
service_email_reply_to_id = form.get("email_reply_to_id", None)
|
||||
service_sms_sender_id = form.get("sms_sender_id", None)
|
||||
reply_to = None
|
||||
if notification_type == EMAIL_TYPE:
|
||||
service_email_reply_to_id = form.get("email_reply_to_id", None)
|
||||
reply_to = check_service_email_reply_to_id(
|
||||
str(authenticated_service.id), service_email_reply_to_id, notification_type
|
||||
) or authenticated_service.get_default_reply_to_email_address()
|
||||
|
||||
elif notification_type == SMS_TYPE:
|
||||
service_sms_sender_id = form.get("sms_sender_id", None)
|
||||
reply_to = check_service_sms_sender_id(
|
||||
str(authenticated_service.id), service_sms_sender_id, notification_type
|
||||
) or authenticated_service.get_default_sms_sender()
|
||||
|
||||
@@ -12,3 +12,6 @@ export FIRETEXT_API_KEY="Firetext"
|
||||
export STATSD_PREFIX="stats-prefix"
|
||||
export NOTIFICATION_QUEUE_PREFIX='testing'
|
||||
export REDIS_URL="redis://localhost:6379/0"
|
||||
export FLASK_APP=application.py
|
||||
export FLASK_DEBUG=1
|
||||
export WERKZEUG_DEBUG_PIN=off
|
||||
@@ -51,7 +51,8 @@ from tests.app.conftest import (
|
||||
sample_template as create_sample_template,
|
||||
sample_job as create_sample_job,
|
||||
sample_email_template as create_sample_email_template,
|
||||
sample_notification as create_sample_notification
|
||||
sample_notification as create_sample_notification,
|
||||
sample_letter_job
|
||||
)
|
||||
from tests.app.db import (
|
||||
create_inbound_sms,
|
||||
@@ -62,7 +63,9 @@ from tests.app.db import (
|
||||
create_service,
|
||||
create_template,
|
||||
create_user,
|
||||
create_reply_to_email, create_service_sms_sender, create_service_with_defined_sms_sender)
|
||||
create_reply_to_email,
|
||||
create_service_with_defined_sms_sender
|
||||
)
|
||||
|
||||
|
||||
class AnyStringWith(str):
|
||||
@@ -986,7 +989,11 @@ def test_save_sms_does_not_send_duplicate_and_does_not_put_in_retry_queue(sample
|
||||
assert not retry.called
|
||||
|
||||
|
||||
def test_save_letter_saves_letter_to_database(sample_letter_job, mocker):
|
||||
def test_save_letter_saves_letter_to_database(mocker, notify_db_session):
|
||||
service = create_service()
|
||||
create_letter_contact(service=service, contact_block="Address contract", is_default=True)
|
||||
template = create_template(service=service, template_type=LETTER_TYPE)
|
||||
job = create_job(template=template)
|
||||
|
||||
mocker.patch('app.celery.tasks.create_random_identifier', return_value="this-is-random-in-real-life")
|
||||
|
||||
@@ -1000,17 +1007,17 @@ def test_save_letter_saves_letter_to_database(sample_letter_job, mocker):
|
||||
'postcode': 'Flob',
|
||||
}
|
||||
notification_json = _notification_json(
|
||||
template=sample_letter_job.template,
|
||||
template=job.template,
|
||||
to='Foo',
|
||||
personalisation=personalisation,
|
||||
job_id=sample_letter_job.id,
|
||||
job_id=job.id,
|
||||
row_number=1
|
||||
)
|
||||
notification_id = uuid.uuid4()
|
||||
created_at = datetime.utcnow()
|
||||
|
||||
save_letter(
|
||||
sample_letter_job.service_id,
|
||||
job.service_id,
|
||||
notification_id,
|
||||
encryption.encrypt(notification_json),
|
||||
)
|
||||
@@ -1018,9 +1025,9 @@ def test_save_letter_saves_letter_to_database(sample_letter_job, mocker):
|
||||
notification_db = Notification.query.one()
|
||||
assert notification_db.id == notification_id
|
||||
assert notification_db.to == 'Foo'
|
||||
assert notification_db.job_id == sample_letter_job.id
|
||||
assert notification_db.template_id == sample_letter_job.template.id
|
||||
assert notification_db.template_version == sample_letter_job.template.version
|
||||
assert notification_db.job_id == job.id
|
||||
assert notification_db.template_id == job.template.id
|
||||
assert notification_db.template_version == job.template.version
|
||||
assert notification_db.status == 'created'
|
||||
assert notification_db.created_at >= created_at
|
||||
assert notification_db.notification_type == 'letter'
|
||||
@@ -1028,6 +1035,7 @@ def test_save_letter_saves_letter_to_database(sample_letter_job, mocker):
|
||||
assert notification_db.sent_by is None
|
||||
assert notification_db.personalisation == personalisation
|
||||
assert notification_db.reference == "this-is-random-in-real-life"
|
||||
assert notification_db.reply_to_text == "Address contract"
|
||||
|
||||
|
||||
def test_should_cancel_job_if_service_is_inactive(sample_service,
|
||||
|
||||
Reference in New Issue
Block a user