From a052020f8467f46910f0c16793fcce8f7e0d841a Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Mon, 8 Jan 2018 16:54:19 +0000 Subject: [PATCH] - simplify if statement - use the template.get_reply_to_text() in send_notification, it's already using the right thing. --- app/models.py | 3 +-- app/notifications/rest.py | 12 +----------- tests/app/celery/test_tasks.py | 3 +-- tests/app/template/test_rest.py | 1 + 4 files changed, 4 insertions(+), 15 deletions(-) diff --git a/app/models.py b/app/models.py index e6a3d0bad..1a54b19cb 100644 --- a/app/models.py +++ b/app/models.py @@ -633,8 +633,7 @@ class TemplateBase(db.Model): def get_reply_to_text(self): if self.template_type == LETTER_TYPE: - if self.service_letter_contact_id is not None: - return self.service_letter_contact.contact_block + return self.service_letter_contact.contact_block if self.service_letter_contact else None elif self.template_type == EMAIL_TYPE: return self.service.get_default_reply_to_email_address() elif self.template_type == SMS_TYPE: diff --git a/app/notifications/rest.py b/app/notifications/rest.py index 9d9e1f6a4..750505834 100644 --- a/app/notifications/rest.py +++ b/app/notifications/rest.py @@ -119,7 +119,6 @@ def send_notification(notification_type): if notification_type == SMS_TYPE: _service_can_send_internationally(authenticated_service, notification_form['to']) - reply_to = get_reply_to_text(notification_type) # Do not persist or send notification to the queue if it is a simulated recipient simulated = simulated_recipient(notification_form['to'], notification_type) notification_model = persist_notification(template_id=template.id, @@ -131,7 +130,7 @@ def send_notification(notification_type): api_key_id=api_user.id, key_type=api_user.key_type, simulated=simulated, - reply_to_text=reply_to + reply_to_text=template.get_reply_to_text() ) if not simulated: queue_name = QueueNames.PRIORITY if template.process_type == PRIORITY else None @@ -150,15 +149,6 @@ def send_notification(notification_type): ), 201 -def get_reply_to_text(notification_type): - if notification_type == EMAIL_TYPE: - return authenticated_service.get_default_reply_to_email_address() - if notification_type == SMS_TYPE: - return authenticated_service.get_default_sms_sender() - if notification_type == LETTER_TYPE: - return authenticated_service.get_default_letter_contact() - - def get_notification_return_data(notification_id, notification, template): output = { 'body': str(template), diff --git a/tests/app/celery/test_tasks.py b/tests/app/celery/test_tasks.py index 8c00bd4a7..4e1937370 100644 --- a/tests/app/celery/test_tasks.py +++ b/tests/app/celery/test_tasks.py @@ -1256,10 +1256,9 @@ def test_build_dvla_file_retries_if_s3_err(sample_letter_template, mocker): def test_create_dvla_file_contents(notify_db_session, mocker): service = create_service(service_permissions=SERVICE_PERMISSION_TYPES) - create_letter_contact(service=service, contact_block='London,\nNW1A 1AA') letter_template = create_template(service=service, template_type=LETTER_TYPE) job = create_job(template=letter_template, notification_count=2) - create_notification(template=job.template, job=job, reference=1, reply_to_text=service.get_default_letter_contact()) + create_notification(template=job.template, job=job, reference=1, reply_to_text='London,\nNW1A 1AA') create_notification(template=job.template, job=job, reference=2, reply_to_text='Not the default address') mocked_letter_template = mocker.patch("app.celery.tasks.LetterDVLATemplate") mocked_letter_template_instance = mocked_letter_template.return_value diff --git a/tests/app/template/test_rest.py b/tests/app/template/test_rest.py index 5c732808e..ffa2147f5 100644 --- a/tests/app/template/test_rest.py +++ b/tests/app/template/test_rest.py @@ -615,6 +615,7 @@ def test_create_a_template_with_foreign_service_reply_to(admin_request, sample_u [('template address', 'service address'), (None, 'service address'), ('template address', None), + (None, None) ]) def test_get_template_reply_to(client, sample_service, template_default, service_default): auth_header = create_authorization_header()