mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-11 02:23:32 -04:00
Add a task for the FTP app to call that will update the job to sent to dvla and all the notifications for that job as sending.
This commit is contained in:
+23
-2
@@ -24,7 +24,8 @@ 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
|
from app.dao.notifications_dao import get_notification_by_id, dao_update_notification
|
||||||
|
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
|
||||||
from app.models import (
|
from app.models import (
|
||||||
@@ -32,7 +33,12 @@ from app.models import (
|
|||||||
SMS_TYPE,
|
SMS_TYPE,
|
||||||
LETTER_TYPE,
|
LETTER_TYPE,
|
||||||
KEY_TYPE_NORMAL,
|
KEY_TYPE_NORMAL,
|
||||||
JOB_STATUS_CANCELLED, JOB_STATUS_PENDING, JOB_STATUS_IN_PROGRESS, JOB_STATUS_FINISHED, JOB_STATUS_READY_TO_SEND)
|
JOB_STATUS_CANCELLED,
|
||||||
|
JOB_STATUS_PENDING,
|
||||||
|
JOB_STATUS_IN_PROGRESS,
|
||||||
|
JOB_STATUS_FINISHED,
|
||||||
|
JOB_STATUS_READY_TO_SEND,
|
||||||
|
JOB_STATUS_SENT_TO_DVLA, NOTIFICATION_SENDING)
|
||||||
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
|
||||||
@@ -286,6 +292,21 @@ def build_dvla_file(self, job_id):
|
|||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
|
@notify_celery.task(bind=True, name='update-letter-job-to-sent')
|
||||||
|
@statsd(namespace="tasks")
|
||||||
|
def update_job_to_sent_to_dvla(self, job_id):
|
||||||
|
# This task will be called by the FTP app to update the job to sent to dvla
|
||||||
|
# and update all notifications for this job to sending, provider = DVLA
|
||||||
|
provider = get_current_provider(LETTER_TYPE)
|
||||||
|
notifications = dao_get_all_notifications_for_job(job_id)
|
||||||
|
for n in notifications:
|
||||||
|
n.status = NOTIFICATION_SENDING
|
||||||
|
n.sent_by = provider.identifier
|
||||||
|
dao_update_notification(n)
|
||||||
|
|
||||||
|
dao_update_job_status(job_id, JOB_STATUS_SENT_TO_DVLA)
|
||||||
|
|
||||||
|
|
||||||
def create_dvla_file_contents(job_id):
|
def create_dvla_file_contents(job_id):
|
||||||
file_contents = '\n'.join(
|
file_contents = '\n'.join(
|
||||||
str(LetterDVLATemplate(
|
str(LetterDVLATemplate(
|
||||||
|
|||||||
+3
-1
@@ -454,7 +454,9 @@ JOB_STATUS_TYPES = [
|
|||||||
JOB_STATUS_FINISHED,
|
JOB_STATUS_FINISHED,
|
||||||
JOB_STATUS_SENDING_LIMITS_EXCEEDED,
|
JOB_STATUS_SENDING_LIMITS_EXCEEDED,
|
||||||
JOB_STATUS_SCHEDULED,
|
JOB_STATUS_SCHEDULED,
|
||||||
JOB_STATUS_CANCELLED
|
JOB_STATUS_CANCELLED,
|
||||||
|
JOB_STATUS_READY_TO_SEND,
|
||||||
|
JOB_STATUS_SENT_TO_DVLA
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ from app.celery.tasks import (
|
|||||||
send_sms,
|
send_sms,
|
||||||
send_email,
|
send_email,
|
||||||
persist_letter,
|
persist_letter,
|
||||||
get_template_class
|
get_template_class,
|
||||||
|
update_job_to_sent_to_dvla
|
||||||
)
|
)
|
||||||
from app.dao import jobs_dao, services_dao
|
from app.dao import jobs_dao, services_dao
|
||||||
from app.models import (
|
from app.models import (
|
||||||
@@ -1036,3 +1037,14 @@ def test_dvla_letter_template(sample_letter_notification):
|
|||||||
sample_letter_notification.personalisation,
|
sample_letter_notification.personalisation,
|
||||||
12345)
|
12345)
|
||||||
assert str(letter) == "140|500|001||201703230012345|||||||||||||A1|A2|A3|A4|A5|A6||A_POST|||||||||23 March 2017<cr><cr><h1>Template subject<normal><cr><cr>Dear Sir/Madam, Hello. Yours Truly, The Government.<cr><cr>" # noqa
|
assert str(letter) == "140|500|001||201703230012345|||||||||||||A1|A2|A3|A4|A5|A6||A_POST|||||||||23 March 2017<cr><cr><h1>Template subject<normal><cr><cr>Dear Sir/Madam, Hello. Yours Truly, The Government.<cr><cr>" # noqa
|
||||||
|
|
||||||
|
|
||||||
|
def test_update_job_to_sent_to_dvla(sample_letter_template, sample_letter_job):
|
||||||
|
create_notification(template=sample_letter_template, job=sample_letter_job)
|
||||||
|
create_notification(template=sample_letter_template, job=sample_letter_job)
|
||||||
|
update_job_to_sent_to_dvla(job_id=sample_letter_job.id)
|
||||||
|
|
||||||
|
updated_notifications = Notification.query.all()
|
||||||
|
assert [(n.status == 'sending', n.sent_by == 'dvla') for n in updated_notifications]
|
||||||
|
|
||||||
|
assert 'sent to dvla' == Job.query.filter_by(id=sample_letter_job.id).one().job_status
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ from tests.app.conftest import (
|
|||||||
sample_email_template,
|
sample_email_template,
|
||||||
sample_service,
|
sample_service,
|
||||||
sample_job,
|
sample_job,
|
||||||
sample_api_key,
|
|
||||||
sample_notification_history as create_notification_history
|
sample_notification_history as create_notification_history
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -673,7 +673,8 @@ def test_get_jobs_accepts_page_parameter(
|
|||||||
@pytest.mark.parametrize('statuses_filter, expected_statuses', [
|
@pytest.mark.parametrize('statuses_filter, expected_statuses', [
|
||||||
('', JOB_STATUS_TYPES),
|
('', JOB_STATUS_TYPES),
|
||||||
('pending', [JOB_STATUS_PENDING]),
|
('pending', [JOB_STATUS_PENDING]),
|
||||||
('pending, in progress, finished, sending limits exceeded, scheduled, cancelled', JOB_STATUS_TYPES),
|
('pending, in progress, finished, sending limits exceeded, scheduled, cancelled, ready to send, sent to dvla',
|
||||||
|
JOB_STATUS_TYPES),
|
||||||
# bad statuses are accepted, just return no data
|
# bad statuses are accepted, just return no data
|
||||||
('foo', [])
|
('foo', [])
|
||||||
])
|
])
|
||||||
@@ -691,6 +692,8 @@ def test_get_jobs_can_filter_on_statuses(
|
|||||||
create_job(notify_db, notify_db_session, job_status='sending limits exceeded')
|
create_job(notify_db, notify_db_session, job_status='sending limits exceeded')
|
||||||
create_job(notify_db, notify_db_session, job_status='scheduled')
|
create_job(notify_db, notify_db_session, job_status='scheduled')
|
||||||
create_job(notify_db, notify_db_session, job_status='cancelled')
|
create_job(notify_db, notify_db_session, job_status='cancelled')
|
||||||
|
create_job(notify_db, notify_db_session, job_status='ready to send')
|
||||||
|
create_job(notify_db, notify_db_session, job_status='sent to dvla')
|
||||||
|
|
||||||
path = '/service/{}/job'.format(sample_service.id)
|
path = '/service/{}/job'.format(sample_service.id)
|
||||||
response = client.get(
|
response = client.get(
|
||||||
|
|||||||
Reference in New Issue
Block a user