diff --git a/app/celery/letters_pdf_tasks.py b/app/celery/letters_pdf_tasks.py index 1dd15c770..e7b453364 100644 --- a/app/celery/letters_pdf_tasks.py +++ b/app/celery/letters_pdf_tasks.py @@ -207,7 +207,7 @@ def send_letters_volume_email_to_dvla(letters_volumes, date): personalisation["international_sheets"] += item.sheets_count template = dao_get_template_by_id(current_app.config['LETTERS_VOLUME_EMAIL_TEMPLATE_ID']) - recipient = current_app.config['DVLA_EMAIL_ADDRESS'] + recipients = current_app.config['DVLA_EMAIL_ADDRESSES'] reply_to = template.service.get_default_reply_to_email_address() service = Service.query.get(current_app.config['NOTIFY_SERVICE_ID']) @@ -216,20 +216,20 @@ def send_letters_volume_email_to_dvla(letters_volumes, date): persist_notification, send_notification_to_queue ) + for recipient in recipients: + saved_notification = persist_notification( + template_id=template.id, + template_version=template.version, + recipient=recipient, + service=service, + personalisation=personalisation, + notification_type=template.template_type, + api_key_id=None, + key_type=KEY_TYPE_NORMAL, + reply_to_text=reply_to + ) - saved_notification = persist_notification( - template_id=template.id, - template_version=template.version, - recipient=recipient, - service=service, - personalisation=personalisation, - notification_type=template.template_type, - api_key_id=None, - key_type=KEY_TYPE_NORMAL, - reply_to_text=reply_to - ) - - send_notification_to_queue(saved_notification, False, queue=QueueNames.NOTIFY) + send_notification_to_queue(saved_notification, False, queue=QueueNames.NOTIFY) def get_key_and_size_of_letters_to_be_sent_to_print(print_run_deadline, postage): diff --git a/app/config.py b/app/config.py index 3338fe8c0..7251df405 100644 --- a/app/config.py +++ b/app/config.py @@ -181,7 +181,7 @@ class Config(object): NOTIFY_INTERNATIONAL_SMS_SENDER = '07984404008' LETTERS_VOLUME_EMAIL_TEMPLATE_ID = '11fad854-fd38-4a7c-bd17-805fb13dfc12' # we only need real email in Live environment (production) - DVLA_EMAIL_ADDRESS = 'success@simulator.amazonses.com' + DVLA_EMAIL_ADDRESSES = ['success@simulator.amazonses.com'] BROKER_URL = 'sqs://' BROKER_TRANSPORT_OPTIONS = { @@ -482,6 +482,8 @@ class Test(Development): CBC_PROXY_ENABLED = True + DVLA_EMAIL_ADDRESSES = ['success@simulator.amazonses.com', 'success+2@simulator.amazonses.com'] + class Preview(Config): NOTIFY_EMAIL_DOMAIN = 'notify.works' @@ -515,7 +517,7 @@ class Staging(Config): FROM_NUMBER = 'stage' API_RATE_LIMIT_ENABLED = True CHECK_PROXY_HEADER = True - DVLA_EMAIL_ADDRESS = os.getenv('DVLA_EMAIL_ADDRESS') + DVLA_EMAIL_ADDRESSES = os.getenv('DVLA_EMAIL_ADDRESSES') class Live(Config): @@ -539,7 +541,7 @@ class Live(Config): CRONITOR_ENABLED = True ENABLED_CBCS = {BroadcastProvider.THREE, BroadcastProvider.O2, BroadcastProvider.VODAFONE} - DVLA_EMAIL_ADDRESS = os.getenv('DVLA_EMAIL_ADDRESS') + DVLA_EMAIL_ADDRESSES = os.getenv('DVLA_EMAIL_ADDRESSES') class CloudFoundryConfig(Config): diff --git a/manifest.yml.j2 b/manifest.yml.j2 index 615a002ca..2ec9ee910 100644 --- a/manifest.yml.j2 +++ b/manifest.yml.j2 @@ -150,7 +150,7 @@ applications: TEMPLATE_PREVIEW_API_HOST: '{{ TEMPLATE_PREVIEW_API_HOST }}' TEMPLATE_PREVIEW_API_KEY: '{{ TEMPLATE_PREVIEW_API_KEY }}' - DVLA_EMAIL_ADDRESS: '{{ DVLA_EMAIL_ADDRESS }}' + DVLA_EMAIL_ADDRESSES: '{{ DVLA_EMAIL_ADDRESSES | tojson }}' {% for key, value in app.get('additional_env_vars', {}).items() %} {{key}}: '{{value}}' diff --git a/tests/app/celery/test_letters_pdf_tasks.py b/tests/app/celery/test_letters_pdf_tasks.py index f4dd907f3..db49dec1d 100644 --- a/tests/app/celery/test_letters_pdf_tasks.py +++ b/tests/app/celery/test_letters_pdf_tasks.py @@ -478,23 +478,25 @@ def test_send_letters_volume_email_to_dvla(notify_api, notify_db_session, mocker send_letters_volume_email_to_dvla(letters_volumes, datetime(2020, 2, 17).date()) - email_to_dvla = get_notifications().all()[0] - - send_mock.assert_called_once_with([str(email_to_dvla.id)], queue=QueueNames.NOTIFY) - - assert str(email_to_dvla.template_id) == current_app.config['LETTERS_VOLUME_EMAIL_TEMPLATE_ID'] - assert email_to_dvla.to == current_app.config['DVLA_EMAIL_ADDRESS'] - assert email_to_dvla.personalisation == { - 'total_volume': 11, - 'first_class_volume': 5, - 'second_class_volume': 4, - 'international_volume': 2, - 'total_sheets': 24, - 'first_class_sheets': 7, - "second_class_sheets": 12, - 'international_sheets': 5, - 'date': '17 February 2020' - } + emails_to_dvla = get_notifications().all() + assert len(emails_to_dvla) == 2 + send_mock.called = 2 + send_mock.assert_any_call([str(emails_to_dvla[0].id)], queue=QueueNames.NOTIFY) + send_mock.assert_any_call([str(emails_to_dvla[1].id)], queue=QueueNames.NOTIFY) + for email in emails_to_dvla: + assert str(email.template_id) == current_app.config['LETTERS_VOLUME_EMAIL_TEMPLATE_ID'] + assert email.to in current_app.config['DVLA_EMAIL_ADDRESSES'] + assert email.personalisation == { + 'total_volume': 11, + 'first_class_volume': 5, + 'second_class_volume': 4, + 'international_volume': 2, + 'total_sheets': 24, + 'first_class_sheets': 7, + "second_class_sheets": 12, + 'international_sheets': 5, + 'date': '17 February 2020' + } def test_group_letters_splits_on_file_size(notify_api):