mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-26 17:23:50 -04:00
Error in task when letter template and in trial mode
This commit is contained in:
@@ -75,6 +75,13 @@ def process_job(job_id):
|
|||||||
|
|
||||||
db_template = dao_get_template_by_id(job.template_id, job.template_version)
|
db_template = dao_get_template_by_id(job.template_id, job.template_version)
|
||||||
|
|
||||||
|
if db_template.template_type == LETTER_TYPE and service.restricted:
|
||||||
|
job.job_status = JOB_STATUS_ERROR
|
||||||
|
dao_update_job(job)
|
||||||
|
current_app.logger.warn(
|
||||||
|
"Job {} has been set to error, service {} is in trial mode".format(job_id, service.id))
|
||||||
|
return
|
||||||
|
|
||||||
TemplateClass = get_template_class(db_template.template_type)
|
TemplateClass = get_template_class(db_template.template_type)
|
||||||
template = TemplateClass(db_template.__dict__)
|
template = TemplateClass(db_template.__dict__)
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ from app.models import (
|
|||||||
SMS_TYPE,
|
SMS_TYPE,
|
||||||
EMAIL_TYPE,
|
EMAIL_TYPE,
|
||||||
LETTER_TYPE,
|
LETTER_TYPE,
|
||||||
Job)
|
Job,
|
||||||
|
JOB_STATUS_ERROR)
|
||||||
|
|
||||||
from tests.app import load_example_csv
|
from tests.app import load_example_csv
|
||||||
from tests.conftest import set_config
|
from tests.conftest import set_config
|
||||||
@@ -977,6 +978,26 @@ def test_should_cancel_job_if_service_is_inactive(sample_service,
|
|||||||
mock_dvla_file_task.assert_not_called()
|
mock_dvla_file_task.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_error_job_if_service_is_restricted_and_letter_template_type(
|
||||||
|
sample_service,
|
||||||
|
sample_letter_job,
|
||||||
|
mocker
|
||||||
|
):
|
||||||
|
sample_service.restricted = True
|
||||||
|
|
||||||
|
mocker.patch('app.celery.tasks.s3.get_job_from_s3')
|
||||||
|
mocker.patch('app.celery.tasks.process_row')
|
||||||
|
mock_dvla_file_task = mocker.patch('app.celery.tasks.build_dvla_file')
|
||||||
|
|
||||||
|
process_job(sample_letter_job.id)
|
||||||
|
|
||||||
|
job = jobs_dao.dao_get_job_by_id(sample_letter_job.id)
|
||||||
|
assert job.job_status == JOB_STATUS_ERROR
|
||||||
|
s3.get_job_from_s3.assert_not_called()
|
||||||
|
tasks.process_row.assert_not_called()
|
||||||
|
mock_dvla_file_task.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('template_type, expected_class', [
|
@pytest.mark.parametrize('template_type, expected_class', [
|
||||||
(SMS_TYPE, SMSMessageTemplate),
|
(SMS_TYPE, SMSMessageTemplate),
|
||||||
(EMAIL_TYPE, WithSubjectTemplate),
|
(EMAIL_TYPE, WithSubjectTemplate),
|
||||||
|
|||||||
@@ -271,6 +271,12 @@ def sample_letter_template(sample_service_full_permissions):
|
|||||||
return create_template(sample_service_full_permissions, template_type=LETTER_TYPE)
|
return create_template(sample_service_full_permissions, template_type=LETTER_TYPE)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sample_trial_letter_template(sample_service_full_permissions):
|
||||||
|
sample_service_full_permissions.restricted = True
|
||||||
|
return create_template(sample_service_full_permissions, template_type=LETTER_TYPE)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def sample_email_template_with_placeholders(notify_db, notify_db_session):
|
def sample_email_template_with_placeholders(notify_db, notify_db_session):
|
||||||
return sample_email_template(
|
return sample_email_template(
|
||||||
|
|||||||
Reference in New Issue
Block a user