From 8b35c1c0076bf5df1db88a5566589889ce66accd Mon Sep 17 00:00:00 2001 From: Ken Tsang Date: Tue, 3 Apr 2018 17:23:10 +0100 Subject: [PATCH 1/2] Fix research mode preview of precompiled letters --- app/v2/notifications/post_notifications.py | 14 ++++++++------ .../test_post_letter_notifications.py | 7 +++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/v2/notifications/post_notifications.py b/app/v2/notifications/post_notifications.py index 7e39ad116..35bbff97b 100644 --- a/app/v2/notifications/post_notifications.py +++ b/app/v2/notifications/post_notifications.py @@ -265,12 +265,6 @@ def process_letter_notification(*, letter_data, api_key, template, reply_to_text [str(notification.id)], queue=QueueNames.CREATE_LETTERS_PDF ) - elif (api_key.service.research_mode and - current_app.config['NOTIFY_ENVIRONMENT'] in ['preview', 'development']): - create_fake_letter_response_file.apply_async( - (notification.reference,), - queue=QueueNames.RESEARCH_MODE - ) else: if precompiled and api_key.key_type == KEY_TYPE_TEST: filename = upload_letter_pdf(notification, letter_content) @@ -281,6 +275,14 @@ def process_letter_notification(*, letter_data, api_key, template, reply_to_text kwargs={'filename': filename}, queue=QueueNames.ANTIVIRUS, ) + elif ( + api_key.service.research_mode and + current_app.config['NOTIFY_ENVIRONMENT'] not in ['staging', 'live'] + ): + create_fake_letter_response_file.apply_async( + (notification.reference,), + queue=QueueNames.RESEARCH_MODE + ) else: update_notification_status_by_reference(notification.reference, NOTIFICATION_DELIVERED) diff --git a/tests/app/v2/notifications/test_post_letter_notifications.py b/tests/app/v2/notifications/test_post_letter_notifications.py index 851cf2e3c..bfcf85ccf 100644 --- a/tests/app/v2/notifications/test_post_letter_notifications.py +++ b/tests/app/v2/notifications/test_post_letter_notifications.py @@ -393,12 +393,15 @@ def test_post_letter_notification_is_delivered_if_in_trial_mode_and_using_test_k assert not fake_create_letter_task.called +@pytest.mark.parametrize('is_research_mode', [True, False]) def test_post_letter_notification_is_delivered_and_has_pdf_uploaded_to_test_letters_bucket_using_test_key( client, notify_user, - mocker + mocker, + is_research_mode ): - sample_letter_service = create_service(service_permissions=['letter', 'precompiled_letter']) + sample_letter_service = create_service( + service_permissions=['letter', 'precompiled_letter'], research_mode=is_research_mode) s3mock = mocker.patch('app.v2.notifications.post_notifications.upload_letter_pdf', return_value='test.pdf') mocker.patch('app.v2.notifications.post_notifications.pdf_page_count', return_value=1) mock_celery = mocker.patch("app.letters.rest.notify_celery.send_task") From 39e4f63b8c588f5a1a4e0756945852f0c54c5ec0 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Fri, 6 Apr 2018 12:01:16 +0100 Subject: [PATCH 2/2] Use the positive condition when checking the environment --- app/v2/notifications/post_notifications.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/v2/notifications/post_notifications.py b/app/v2/notifications/post_notifications.py index 35bbff97b..3af8db0b0 100644 --- a/app/v2/notifications/post_notifications.py +++ b/app/v2/notifications/post_notifications.py @@ -277,7 +277,7 @@ def process_letter_notification(*, letter_data, api_key, template, reply_to_text ) elif ( api_key.service.research_mode and - current_app.config['NOTIFY_ENVIRONMENT'] not in ['staging', 'live'] + current_app.config['NOTIFY_ENVIRONMENT'] in ['preview', 'development'] ): create_fake_letter_response_file.apply_async( (notification.reference,),