Push letter job to research queue in research mode

This commit is contained in:
Ken Tsang
2017-08-29 12:24:17 +01:00
parent ff860ec242
commit 01830b7e59
2 changed files with 42 additions and 2 deletions

View File

@@ -93,9 +93,11 @@ def process_job(job_id):
process_row(row_number, recipient, personalisation, template, job, service) process_row(row_number, recipient, personalisation, template, job, service)
if template.template_type == LETTER_TYPE: 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 # 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: else:
job.job_status = JOB_STATUS_FINISHED job.job_status = JOB_STATUS_FINISHED

View File

@@ -29,6 +29,7 @@ from app.celery.tasks import (
update_letter_notifications_statuses, update_letter_notifications_statuses,
process_updates_from_file, process_updates_from_file,
send_inbound_sms_to_service) send_inbound_sms_to_service)
from app.config import QueueNames
from app.dao import jobs_dao, services_dao from app.dao import jobs_dao, services_dao
from app.models import ( from app.models import (
Notification, 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): def test_should_send_sms_template_to_and_persist_with_job_id(sample_job, sample_api_key, mocker):
notification = _notification_json( notification = _notification_json(
sample_job.template, sample_job.template,