From 65733a30a1b20d2f164ae800faede05932a51ae9 Mon Sep 17 00:00:00 2001 From: Ken Tsang Date: Mon, 19 Mar 2018 16:25:13 +0000 Subject: [PATCH] Add send_task to antivirus app for scanning precompiled letters --- app/v2/notifications/post_notifications.py | 18 ++++++++++++++---- .../test_post_letter_notifications.py | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/v2/notifications/post_notifications.py b/app/v2/notifications/post_notifications.py index 42e7180c0..5a3bf6e41 100644 --- a/app/v2/notifications/post_notifications.py +++ b/app/v2/notifications/post_notifications.py @@ -4,12 +4,11 @@ import io import math from flask import request, jsonify, current_app, abort - from notifications_utils.pdf import pdf_page_count, PdfReadError from notifications_utils.recipients import try_validate_and_format_phone_number -from app import api_user, authenticated_service -from app.config import QueueNames +from app import api_user, authenticated_service, notify_celery +from app.config import QueueNames, TaskNames from app.dao.notifications_dao import dao_update_notification, update_notification_status_by_reference from app.dao.templates_dao import dao_create_template from app.dao.users_dao import get_user_by_id @@ -246,10 +245,21 @@ def process_letter_notification(*, letter_data, api_key, template, reply_to_text if should_send: if precompiled: - upload_letter_pdf(notification, letter_content) + filename = upload_letter_pdf(notification, letter_content) pages_per_sheet = 2 notification.billable_units = math.ceil(pages / pages_per_sheet) dao_update_notification(notification) + + current_app.logger.info( + 'Calling task scan-file for {}'.format(filename) + ) + + # call task to add the filename to anti virus queue + notify_celery.send_task( + name=TaskNames.SCAN_FILE, + kwargs={'filename': filename}, + queue=QueueNames.ANTIVIRUS, + ) else: create_letters_pdf.apply_async( [str(notification.id)], diff --git a/tests/app/v2/notifications/test_post_letter_notifications.py b/tests/app/v2/notifications/test_post_letter_notifications.py index efda61e7e..00aef4770 100644 --- a/tests/app/v2/notifications/test_post_letter_notifications.py +++ b/tests/app/v2/notifications/test_post_letter_notifications.py @@ -479,6 +479,7 @@ def test_post_precompiled_letter_notification_returns_201(client, notify_user, m sample_service = create_service(service_permissions=['letter', 'precompiled_letter']) s3mock = mocker.patch('app.v2.notifications.post_notifications.upload_letter_pdf') mocker.patch('app.v2.notifications.post_notifications.pdf_page_count', return_value=5) + mocker.patch("app.letters.rest.notify_celery.send_task") data = { "reference": "letter-reference", "content": "bGV0dGVyLWNvbnRlbnQ="