mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-19 05:58:53 -04:00
Add scheduled letter jobs
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import uuid
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from functools import partial
|
||||
from unittest.mock import call, patch, PropertyMock
|
||||
@@ -20,6 +22,7 @@ from app.celery.scheduled_tasks import (
|
||||
remove_csv_files,
|
||||
remove_transformed_dvla_files,
|
||||
run_scheduled_jobs,
|
||||
run_letter_jobs,
|
||||
s3,
|
||||
send_daily_performance_platform_stats,
|
||||
send_scheduled_notifications,
|
||||
@@ -28,6 +31,7 @@ from app.celery.scheduled_tasks import (
|
||||
timeout_notifications,
|
||||
populate_monthly_billing)
|
||||
from app.clients.performance_platform.performance_platform_client import PerformancePlatformClient
|
||||
from app.config import QueueNames
|
||||
from app.dao.jobs_dao import dao_get_job_by_id
|
||||
from app.dao.notifications_dao import dao_get_scheduled_notifications
|
||||
from app.dao.provider_details_dao import (
|
||||
@@ -677,3 +681,18 @@ def test_populate_monthly_billing_updates_correct_month_in_bst(sample_template):
|
||||
assert monthly_billing[1].notification_type == 'sms'
|
||||
assert monthly_billing[1].monthly_totals[0]['billing_units'] == 1
|
||||
assert monthly_billing[1].monthly_totals[0]['total_cost'] == 0.0123
|
||||
|
||||
|
||||
def test_run_letter_jobs(client, mocker):
|
||||
job_ids = [str(uuid.uuid4()), str(uuid.uuid4())]
|
||||
mocker.patch(
|
||||
"app.celery.scheduled_tasks.dao_get_letter_jobs_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=QueueNames.DVLA_FILES,
|
||||
args=(job_ids),
|
||||
queue=QueueNames.PROCESS_FTP)
|
||||
|
||||
@@ -18,18 +18,24 @@ from app.dao.jobs_dao import (
|
||||
dao_get_all_notifications_for_job,
|
||||
dao_get_jobs_older_than_limited_by,
|
||||
dao_get_job_statistics_for_job,
|
||||
dao_get_job_stats_for_service)
|
||||
dao_get_job_stats_for_service,
|
||||
dao_get_letter_jobs_by_status)
|
||||
from app.dao.statistics_dao import create_or_update_job_sending_statistics, update_job_stats_outcome_count
|
||||
from app.models import (
|
||||
Job, JobStatistics,
|
||||
EMAIL_TYPE, SMS_TYPE, LETTER_TYPE
|
||||
EMAIL_TYPE, SMS_TYPE, LETTER_TYPE,
|
||||
JOB_STATUS_READY_TO_SEND
|
||||
)
|
||||
|
||||
from tests.app.conftest import sample_notification as create_notification
|
||||
from tests.app.conftest import sample_job as create_job
|
||||
from tests.app.conftest import sample_service as create_service
|
||||
from tests.app.conftest import sample_template as create_template
|
||||
from tests.app.db import create_user
|
||||
from tests.app.db import (
|
||||
create_user,
|
||||
create_job as create_db_job,
|
||||
create_template as create_db_template
|
||||
)
|
||||
|
||||
|
||||
def test_should_have_decorated_notifications_dao_functions():
|
||||
@@ -542,3 +548,17 @@ def stats_set_up(notify_db, notify_db_session, service):
|
||||
update_job_stats_outcome_count(notification_delivered)
|
||||
update_job_stats_outcome_count(notification_failed)
|
||||
return job_1, job_2
|
||||
|
||||
|
||||
def test_dao_get_letter_jobs_by_status(sample_service):
|
||||
create_db_template(service=sample_service, template_type=SMS_TYPE)
|
||||
create_db_template(service=sample_service, template_type=EMAIL_TYPE)
|
||||
letter_template = create_db_template(service=sample_service, template_type=LETTER_TYPE)
|
||||
jobs = []
|
||||
jobs.append(create_db_job(letter_template, job_status=JOB_STATUS_READY_TO_SEND, original_file_name='1.csv'))
|
||||
jobs.append(create_db_job(letter_template, job_status=JOB_STATUS_READY_TO_SEND, original_file_name='2.csv'))
|
||||
|
||||
result = dao_get_letter_jobs_by_status(JOB_STATUS_READY_TO_SEND)
|
||||
|
||||
assert len(result) == 2
|
||||
assert set(result) == set(jobs)
|
||||
|
||||
Reference in New Issue
Block a user