From 01830b7e596b75c2d58e710c5fd774f880fd63ad Mon Sep 17 00:00:00 2001 From: Ken Tsang Date: Tue, 29 Aug 2017 12:24:17 +0100 Subject: [PATCH] Push letter job to research queue in research mode --- app/celery/tasks.py | 6 ++++-- tests/app/celery/test_tasks.py | 38 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/app/celery/tasks.py b/app/celery/tasks.py index 0581d346b..52f2fcde9 100644 --- a/app/celery/tasks.py +++ b/app/celery/tasks.py @@ -93,9 +93,11 @@ def process_job(job_id): process_row(row_number, recipient, personalisation, template, job, service) if template.template_type == LETTER_TYPE: - build_dvla_file.apply_async([str(job.id)], queue=QueueNames.JOBS) + build_dvla_file.apply_async( + [str(job.id)], queue=QueueNames.JOBS if not service.research_mode else QueueNames.RESEARCH_MODE) # temporary logging - current_app.logger.info("send job {} to build-dvla-file in the process-job queue".format(job_id)) + current_app.logger.info("send job {} to build-dvla-file in the {} queue".format( + job_id, QueueNames.JOBS if not service.research_mode else QueueNames.RESEARCH_MODE)) else: job.job_status = JOB_STATUS_FINISHED diff --git a/tests/app/celery/test_tasks.py b/tests/app/celery/test_tasks.py index e2fde2d17..20d961f51 100644 --- a/tests/app/celery/test_tasks.py +++ b/tests/app/celery/test_tasks.py @@ -29,6 +29,7 @@ from app.celery.tasks import ( update_letter_notifications_statuses, process_updates_from_file, send_inbound_sms_to_service) +from app.config import QueueNames from app.dao import jobs_dao, services_dao from app.models import ( Notification, @@ -609,6 +610,43 @@ def test_should_put_send_email_task_in_research_mode_queue_if_research_mode_serv ) +@freeze_time("2017-08-29 17:30:00") +def test_should_build_dvla_file_in_research_mode_for_letter_job( + notify_db, notify_db_session, mocker, sample_service, sample_letter_job, fake_uuid +): + test_encrypted_data = 'some encrypted data' + sample_service.research_mode = True + + csv = """address_line_1,address_line_2,address_line_3,address_line_4,postcode,name + A1,A2,A3,A4,A_POST,Alice + """ + s3_mock = mocker.patch('app.celery.tasks.s3.get_job_from_s3', return_value=csv) + # mocker.patch('app.celery.tasks.process_row') + mock_persist_letter = mocker.patch('app.celery.tasks.persist_letter.apply_async') + mocker.patch('app.celery.tasks.create_uuid', return_value=fake_uuid) + mocker.patch('app.celery.tasks.encryption.encrypt', return_value=test_encrypted_data) + mock_dvla_file_task = mocker.patch('app.celery.tasks.build_dvla_file.apply_async') + + process_job(sample_letter_job.id) + + job = jobs_dao.dao_get_job_by_id(sample_letter_job.id) + + persist_letter.apply_async.assert_called_once_with( + ( + str(sample_service.id), + fake_uuid, + test_encrypted_data, + datetime.utcnow().strftime(DATETIME_FORMAT) + ), + queue=QueueNames.RESEARCH_MODE + ) + + build_dvla_file.apply_async.assert_called_once_with( + [str(job.id)], + queue=QueueNames.RESEARCH_MODE + ) + + def test_should_send_sms_template_to_and_persist_with_job_id(sample_job, sample_api_key, mocker): notification = _notification_json( sample_job.template,