Refactored to check trial when running scheduled job

This commit is contained in:
Ken Tsang
2017-08-30 16:03:05 +01:00
parent 225c85832c
commit d391919677
6 changed files with 100 additions and 17 deletions

View File

@@ -41,7 +41,7 @@ from app.dao.provider_details_dao import (
from app.models import (
Service, Template,
SMS_TYPE, LETTER_TYPE,
JOB_STATUS_READY_TO_SEND,
JOB_STATUS_READY_TO_SEND, JOB_STATUS_ERROR,
MonthlyBilling)
from app.utils import get_london_midnight_in_utc, convert_utc_to_bst
from tests.app.db import create_notification, create_service, create_template, create_job, create_rate
@@ -680,7 +680,9 @@ def test_populate_monthly_billing_updates_correct_month_in_bst(sample_template):
def test_run_letter_jobs(client, mocker, sample_letter_template):
job_ids = [str(uuid.uuid4()), str(uuid.uuid4())]
jobs = [create_job(template=sample_letter_template, job_status=JOB_STATUS_READY_TO_SEND),
create_job(template=sample_letter_template, job_status=JOB_STATUS_READY_TO_SEND)]
job_ids = [str(j.id) for j in jobs]
mocker.patch(
"app.celery.scheduled_tasks.dao_get_letter_job_ids_by_status",
return_value=job_ids
@@ -692,3 +694,42 @@ def test_run_letter_jobs(client, mocker, sample_letter_template):
mock_celery.assert_called_once_with(name=TaskNames.DVLA_FILES,
args=(job_ids,),
queue=QueueNames.PROCESS_FTP)
def test_run_letter_jobs_in_trial_sets_job_to_error(client, mocker, sample_letter_template):
sample_letter_template.service.restricted = True
job = create_job(sample_letter_template)
job_ids = [str(job.id)]
mocker.patch(
"app.celery.scheduled_tasks.dao_get_letter_job_ids_by_status",
return_value=job_ids
)
mock_celery = mocker.patch("app.celery.tasks.notify_celery.send_task")
run_letter_jobs()
assert not mock_celery.called
assert job.job_status == JOB_STATUS_ERROR
def test_run_letter_jobs_in_trial_sets_job_to_error_and_process_live_services(
client, mocker, sample_letter_template):
live_job = create_job(sample_letter_template)
service = create_service(service_name="Sample service 2", restricted=True)
template = create_template(service, template_type=LETTER_TYPE)
trial_job = create_job(template)
job_ids = [str(live_job.id), str(trial_job.id)]
mocker.patch(
"app.celery.scheduled_tasks.dao_get_letter_job_ids_by_status",
return_value=job_ids
)
mock_celery = mocker.patch("app.celery.tasks.notify_celery.send_task")
run_letter_jobs()
mock_celery.assert_called_once_with(name=TaskNames.DVLA_FILES,
args=([str(live_job.id)],),
queue=QueueNames.PROCESS_FTP)
assert trial_job.job_status == JOB_STATUS_ERROR

View File

@@ -5,11 +5,15 @@ from flask import json
from app.variables import LETTER_TEST_API_FILENAME
from tests import create_authorization_header
from tests.app.db import create_job
def test_send_letter_jobs(client, mocker):
def test_send_letter_jobs(client, mocker, sample_letter_template):
mock_celery = mocker.patch("app.letters.rest.notify_celery.send_task")
job_ids = {"job_ids": [str(uuid.uuid4()), str(uuid.uuid4()), str(uuid.uuid4())]}
job_1 = create_job(sample_letter_template)
job_2 = create_job(sample_letter_template)
job_3 = create_job(sample_letter_template)
job_ids = {"job_ids": [str(job_1.id), str(job_2.id), str(job_3.id)]}
auth_header = create_authorization_header()