mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-10 10:03:38 -04:00
Update build_dvla_file with a mocked notify_celery.send_task.
Check the task is being called with the right parameters.
This commit is contained in:
@@ -22,8 +22,7 @@ from app.dao.jobs_dao import (
|
|||||||
all_notifications_are_created_for_job,
|
all_notifications_are_created_for_job,
|
||||||
dao_get_all_notifications_for_job,
|
dao_get_all_notifications_for_job,
|
||||||
dao_update_job_status)
|
dao_update_job_status)
|
||||||
from app.dao.notifications_dao import get_notification_by_id, dao_update_notification, \
|
from app.dao.notifications_dao import get_notification_by_id, dao_update_notifications_sent_to_dvla
|
||||||
dao_update_notifications_sent_to_dvla
|
|
||||||
from app.dao.provider_details_dao import get_current_provider
|
from app.dao.provider_details_dao import get_current_provider
|
||||||
from app.dao.services_dao import dao_fetch_service_by_id, fetch_todays_total_message_count
|
from app.dao.services_dao import dao_fetch_service_by_id, fetch_todays_total_message_count
|
||||||
from app.dao.templates_dao import dao_get_template_by_id
|
from app.dao.templates_dao import dao_get_template_by_id
|
||||||
@@ -37,7 +36,7 @@ from app.models import (
|
|||||||
JOB_STATUS_IN_PROGRESS,
|
JOB_STATUS_IN_PROGRESS,
|
||||||
JOB_STATUS_FINISHED,
|
JOB_STATUS_FINISHED,
|
||||||
JOB_STATUS_READY_TO_SEND,
|
JOB_STATUS_READY_TO_SEND,
|
||||||
JOB_STATUS_SENT_TO_DVLA, NOTIFICATION_SENDING, Notification)
|
JOB_STATUS_SENT_TO_DVLA)
|
||||||
from app.notifications.process_notifications import persist_notification
|
from app.notifications.process_notifications import persist_notification
|
||||||
from app.service.utils import service_allowed_to_send_to
|
from app.service.utils import service_allowed_to_send_to
|
||||||
from app.statsd_decorators import statsd
|
from app.statsd_decorators import statsd
|
||||||
|
|||||||
@@ -979,6 +979,7 @@ def test_build_dvla_file(sample_letter_template, mocker):
|
|||||||
create_notification(template=job.template, job=job)
|
create_notification(template=job.template, job=job)
|
||||||
create_notification(template=job.template, job=job)
|
create_notification(template=job.template, job=job)
|
||||||
mocked_upload = mocker.patch("app.celery.tasks.s3upload")
|
mocked_upload = mocker.patch("app.celery.tasks.s3upload")
|
||||||
|
mocked_send_task = mocker.patch("app.celery.tasks.notify_celery.send_task")
|
||||||
mocked_letter_template = mocker.patch("app.celery.tasks.LetterDVLATemplate")
|
mocked_letter_template = mocker.patch("app.celery.tasks.LetterDVLATemplate")
|
||||||
mocked_letter_template_instance = mocked_letter_template.return_value
|
mocked_letter_template_instance = mocked_letter_template.return_value
|
||||||
mocked_letter_template_instance.__str__.return_value = "dvla|string"
|
mocked_letter_template_instance.__str__.return_value = "dvla|string"
|
||||||
@@ -991,6 +992,7 @@ def test_build_dvla_file(sample_letter_template, mocker):
|
|||||||
file_location="{}-dvla-job.text".format(job.id)
|
file_location="{}-dvla-job.text".format(job.id)
|
||||||
)
|
)
|
||||||
assert Job.query.get(job.id).job_status == 'ready to send'
|
assert Job.query.get(job.id).job_status == 'ready to send'
|
||||||
|
mocked_send_task.assert_called_once_with("aggregrate-dvla-files", ([str(job.id)], ), queue='aggregate-dvla-files')
|
||||||
|
|
||||||
|
|
||||||
def test_build_dvla_file_retries_if_all_notifications_are_not_created(sample_letter_template, mocker):
|
def test_build_dvla_file_retries_if_all_notifications_are_not_created(sample_letter_template, mocker):
|
||||||
@@ -998,6 +1000,7 @@ def test_build_dvla_file_retries_if_all_notifications_are_not_created(sample_let
|
|||||||
create_notification(template=job.template, job=job)
|
create_notification(template=job.template, job=job)
|
||||||
|
|
||||||
mocked = mocker.patch("app.celery.tasks.s3upload")
|
mocked = mocker.patch("app.celery.tasks.s3upload")
|
||||||
|
mocked_send_task = mocker.patch("app.celery.tasks.notify_celery.send_task")
|
||||||
mocker.patch('app.celery.tasks.build_dvla_file.retry', side_effect=Retry)
|
mocker.patch('app.celery.tasks.build_dvla_file.retry', side_effect=Retry)
|
||||||
with pytest.raises(Retry):
|
with pytest.raises(Retry):
|
||||||
build_dvla_file(job.id)
|
build_dvla_file(job.id)
|
||||||
@@ -1006,6 +1009,7 @@ def test_build_dvla_file_retries_if_all_notifications_are_not_created(sample_let
|
|||||||
tasks.build_dvla_file.retry.assert_called_with(queue='retry',
|
tasks.build_dvla_file.retry.assert_called_with(queue='retry',
|
||||||
exc="All notifications for job {} are not persisted".format(job.id))
|
exc="All notifications for job {} are not persisted".format(job.id))
|
||||||
assert Job.query.get(job.id).job_status == 'in progress'
|
assert Job.query.get(job.id).job_status == 'in progress'
|
||||||
|
mocked_send_task.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
def test_create_dvla_file_contents(sample_letter_template, mocker):
|
def test_create_dvla_file_contents(sample_letter_template, mocker):
|
||||||
|
|||||||
Reference in New Issue
Block a user