mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-16 20:48:37 -04:00
This massive set of changes uses the new queue names object throughout the app and tests.
Lots of changes, all changing the line of code that puts things into queues, and the code that tests that.
This commit is contained in:
@@ -61,7 +61,7 @@ def test_should_add_to_retry_queue_if_notification_not_found_in_deliver_sms_task
|
||||
|
||||
deliver_sms(notification_id)
|
||||
app.delivery.send_to_providers.send_sms_to_provider.assert_not_called()
|
||||
app.celery.provider_tasks.deliver_sms.retry.assert_called_with(queue="retry", countdown=10)
|
||||
app.celery.provider_tasks.deliver_sms.retry.assert_called_with(queue="retry-tasks", countdown=10)
|
||||
|
||||
|
||||
def test_should_call_send_email_to_provider_from_deliver_email_task(
|
||||
@@ -83,7 +83,7 @@ def test_should_add_to_retry_queue_if_notification_not_found_in_deliver_email_ta
|
||||
|
||||
deliver_email(notification_id)
|
||||
app.delivery.send_to_providers.send_email_to_provider.assert_not_called()
|
||||
app.celery.provider_tasks.deliver_email.retry.assert_called_with(queue="retry", countdown=10)
|
||||
app.celery.provider_tasks.deliver_email.retry.assert_called_with(queue="retry-tasks", countdown=10)
|
||||
|
||||
|
||||
# DO THESE FOR THE 4 TYPES OF TASK
|
||||
@@ -94,7 +94,7 @@ def test_should_go_into_technical_error_if_exceeds_retries_on_deliver_sms_task(s
|
||||
|
||||
deliver_sms(sample_notification.id)
|
||||
|
||||
provider_tasks.deliver_sms.retry.assert_called_with(queue='retry', countdown=10)
|
||||
provider_tasks.deliver_sms.retry.assert_called_with(queue="retry-tasks", countdown=10)
|
||||
|
||||
assert sample_notification.status == 'technical-failure'
|
||||
|
||||
@@ -105,7 +105,7 @@ def test_should_go_into_technical_error_if_exceeds_retries_on_deliver_email_task
|
||||
|
||||
deliver_email(sample_notification.id)
|
||||
|
||||
provider_tasks.deliver_email.retry.assert_called_with(queue='retry', countdown=10)
|
||||
provider_tasks.deliver_email.retry.assert_called_with(queue="retry-tasks", countdown=10)
|
||||
assert sample_notification.status == 'technical-failure'
|
||||
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ def test_should_update_scheduled_jobs_and_put_on_queue(notify_db, notify_db_sess
|
||||
|
||||
updated_job = dao_get_job_by_id(job.id)
|
||||
assert updated_job.job_status == 'pending'
|
||||
mocked.assert_called_with([str(job.id)], queue='process-job')
|
||||
mocked.assert_called_with([str(job.id)], queue="job-tasks")
|
||||
|
||||
|
||||
def test_should_update_all_scheduled_jobs_and_put_on_queue(notify_db, notify_db_session, mocker):
|
||||
@@ -200,9 +200,9 @@ def test_should_update_all_scheduled_jobs_and_put_on_queue(notify_db, notify_db_
|
||||
assert dao_get_job_by_id(job_2.id).job_status == 'pending'
|
||||
|
||||
mocked.assert_has_calls([
|
||||
call([str(job_3.id)], queue='process-job'),
|
||||
call([str(job_2.id)], queue='process-job'),
|
||||
call([str(job_1.id)], queue='process-job')
|
||||
call([str(job_3.id)], queue="job-tasks"),
|
||||
call([str(job_2.id)], queue="job-tasks"),
|
||||
call([str(job_1.id)], queue="job-tasks")
|
||||
])
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ def test_should_create_initial_job_task_if_notification_is_related_to_a_job(
|
||||
mock = mocker.patch("app.celery.statistics_tasks.record_initial_job_statistics.apply_async")
|
||||
notification = sample_notification(notify_db, notify_db_session, job=sample_job)
|
||||
create_initial_notification_statistic_tasks(notification)
|
||||
mock.assert_called_once_with((str(notification.id), ), queue="statistics")
|
||||
mock.assert_called_once_with((str(notification.id), ), queue="statistics-tasks")
|
||||
|
||||
|
||||
@pytest.mark.parametrize('status', [
|
||||
@@ -29,7 +29,7 @@ def test_should_create_intial_job_task_if_notification_is_not_in_completed_state
|
||||
mock = mocker.patch("app.celery.statistics_tasks.record_initial_job_statistics.apply_async")
|
||||
notification = sample_notification(notify_db, notify_db_session, job=sample_job, status=status)
|
||||
create_initial_notification_statistic_tasks(notification)
|
||||
mock.assert_called_once_with((str(notification.id), ), queue="statistics")
|
||||
mock.assert_called_once_with((str(notification.id), ), queue="statistics-tasks")
|
||||
|
||||
|
||||
def test_should_not_create_initial_job_task_if_notification_is_not_related_to_a_job(
|
||||
@@ -47,7 +47,7 @@ def test_should_create_outcome_job_task_if_notification_is_related_to_a_job(
|
||||
mock = mocker.patch("app.celery.statistics_tasks.record_outcome_job_statistics.apply_async")
|
||||
notification = sample_notification(notify_db, notify_db_session, job=sample_job, status=NOTIFICATION_DELIVERED)
|
||||
create_outcome_notification_statistic_tasks(notification)
|
||||
mock.assert_called_once_with((str(notification.id), ), queue="statistics")
|
||||
mock.assert_called_once_with((str(notification.id), ), queue="statistics-tasks")
|
||||
|
||||
|
||||
@pytest.mark.parametrize('status', NOTIFICATION_STATUS_TYPES_COMPLETED)
|
||||
@@ -57,7 +57,7 @@ def test_should_create_outcome_job_task_if_notification_is_in_completed_state(
|
||||
mock = mocker.patch("app.celery.statistics_tasks.record_outcome_job_statistics.apply_async")
|
||||
notification = sample_notification(notify_db, notify_db_session, job=sample_job, status=status)
|
||||
create_outcome_notification_statistic_tasks(notification)
|
||||
mock.assert_called_once_with((str(notification.id), ), queue='statistics')
|
||||
mock.assert_called_once_with((str(notification.id), ), queue="statistics-tasks")
|
||||
|
||||
|
||||
@pytest.mark.parametrize('status', [
|
||||
@@ -100,7 +100,7 @@ def test_should_retry_if_persisting_the_job_stats_has_a_sql_alchemy_exception(
|
||||
|
||||
record_initial_job_statistics(str(sample_notification.id))
|
||||
dao_mock.assert_called_once_with(sample_notification)
|
||||
retry_mock.assert_called_with(queue="retry")
|
||||
retry_mock.assert_called_with(queue="retry-tasks")
|
||||
|
||||
|
||||
def test_should_call_update_job_stats_dao_outcome_methods(notify_db, notify_db_session, sample_notification, mocker):
|
||||
@@ -123,7 +123,7 @@ def test_should_retry_if_persisting_the_job_outcome_stats_has_a_sql_alchemy_exce
|
||||
|
||||
record_outcome_job_statistics(str(sample_notification.id))
|
||||
dao_mock.assert_called_once_with(sample_notification)
|
||||
retry_mock.assert_called_with(queue="retry")
|
||||
retry_mock.assert_called_with(queue="retry-tasks")
|
||||
|
||||
|
||||
def test_should_retry_if_persisting_the_job_outcome_stats_updates_zero_rows(
|
||||
@@ -136,7 +136,7 @@ def test_should_retry_if_persisting_the_job_outcome_stats_updates_zero_rows(
|
||||
|
||||
record_outcome_job_statistics(str(sample_notification.id))
|
||||
dao_mock.assert_called_once_with(sample_notification)
|
||||
retry_mock.assert_called_with(queue="retry")
|
||||
retry_mock.assert_called_with(queue="retry-tasks")
|
||||
|
||||
|
||||
def test_should_retry_if_persisting_the_job_stats_creation_cant_find_notification_by_id(
|
||||
@@ -148,7 +148,7 @@ def test_should_retry_if_persisting_the_job_stats_creation_cant_find_notificatio
|
||||
|
||||
record_initial_job_statistics(str(create_uuid()))
|
||||
dao_mock.assert_not_called()
|
||||
retry_mock.assert_called_with(queue="retry")
|
||||
retry_mock.assert_called_with(queue="retry-tasks")
|
||||
|
||||
|
||||
def test_should_retry_if_persisting_the_job_stats_outcome_cant_find_notification_by_id(
|
||||
@@ -161,4 +161,4 @@ def test_should_retry_if_persisting_the_job_stats_outcome_cant_find_notification
|
||||
|
||||
record_outcome_job_statistics(str(create_uuid()))
|
||||
dao_mock.assert_not_called()
|
||||
retry_mock.assert_called_with(queue="retry")
|
||||
retry_mock.assert_called_with(queue="retry-tasks")
|
||||
|
||||
@@ -108,7 +108,7 @@ def test_should_process_sms_job(sample_job, mocker):
|
||||
"uuid",
|
||||
"something_encrypted",
|
||||
"2016-01-01T11:09:00.061258Z"),
|
||||
queue="db-sms"
|
||||
queue="database-tasks"
|
||||
)
|
||||
job = jobs_dao.dao_get_job_by_id(sample_job.id)
|
||||
assert job.job_status == 'finished'
|
||||
@@ -237,7 +237,7 @@ def test_should_process_email_job_if_exactly_on_send_limits(notify_db,
|
||||
"something_encrypted",
|
||||
"2016-01-01T11:09:00.061258Z"
|
||||
),
|
||||
queue="db-email"
|
||||
queue="database-tasks"
|
||||
)
|
||||
|
||||
|
||||
@@ -283,7 +283,7 @@ def test_should_process_email_job(email_job_with_placeholders, mocker):
|
||||
"something_encrypted",
|
||||
"2016-01-01T11:09:00.061258Z"
|
||||
),
|
||||
queue="db-email"
|
||||
queue="database-tasks"
|
||||
)
|
||||
job = jobs_dao.dao_get_job_by_id(email_job_with_placeholders.id)
|
||||
assert job.job_status == 'finished'
|
||||
@@ -324,7 +324,7 @@ def test_should_process_letter_job(sample_letter_job, mocker):
|
||||
assert process_row_mock.call_count == 1
|
||||
|
||||
assert sample_letter_job.job_status == 'in progress'
|
||||
tasks.build_dvla_file.apply_async.assert_called_once_with([str(sample_letter_job.id)], queue="process-job")
|
||||
tasks.build_dvla_file.apply_async.assert_called_once_with([str(sample_letter_job.id)], queue="job-tasks")
|
||||
|
||||
|
||||
def test_should_process_all_sms_job(sample_job_with_placeholdered_template,
|
||||
@@ -355,12 +355,12 @@ def test_should_process_all_sms_job(sample_job_with_placeholdered_template,
|
||||
|
||||
@freeze_time('2001-01-01T12:00:00')
|
||||
@pytest.mark.parametrize('template_type, research_mode, expected_function, expected_queue', [
|
||||
(SMS_TYPE, False, 'send_sms', 'db-sms'),
|
||||
(SMS_TYPE, True, 'send_sms', 'research-mode'),
|
||||
(EMAIL_TYPE, False, 'send_email', 'db-email'),
|
||||
(EMAIL_TYPE, True, 'send_email', 'research-mode'),
|
||||
(LETTER_TYPE, False, 'persist_letter', 'db-letter'),
|
||||
(LETTER_TYPE, True, 'persist_letter', 'research-mode'),
|
||||
(SMS_TYPE, False, 'send_sms', 'database-tasks'),
|
||||
(SMS_TYPE, True, 'send_sms', 'research-mode-tasks'),
|
||||
(EMAIL_TYPE, False, 'send_email', 'database-tasks'),
|
||||
(EMAIL_TYPE, True, 'send_email', 'research-mode-tasks'),
|
||||
(LETTER_TYPE, False, 'persist_letter', 'database-tasks'),
|
||||
(LETTER_TYPE, True, 'persist_letter', 'research-mode-tasks'),
|
||||
])
|
||||
def test_process_row_sends_letter_task(template_type, research_mode, expected_function, expected_queue, mocker):
|
||||
mocker.patch('app.celery.tasks.create_uuid', return_value='noti_uuid')
|
||||
@@ -420,7 +420,7 @@ def test_should_send_template_to_correct_sms_task_and_persist(sample_template_wi
|
||||
assert persisted_notification.notification_type == 'sms'
|
||||
mocked_deliver_sms.assert_called_once_with(
|
||||
[str(persisted_notification.id)],
|
||||
queue="send-sms"
|
||||
queue="send-tasks"
|
||||
)
|
||||
|
||||
|
||||
@@ -446,7 +446,7 @@ def test_should_put_send_sms_task_in_research_mode_queue_if_research_mode_servic
|
||||
persisted_notification = Notification.query.one()
|
||||
provider_tasks.deliver_sms.apply_async.assert_called_once_with(
|
||||
[str(persisted_notification.id)],
|
||||
queue="research-mode"
|
||||
queue="research-mode-tasks"
|
||||
)
|
||||
assert mocked_deliver_sms.called
|
||||
|
||||
@@ -481,7 +481,7 @@ def test_should_send_sms_if_restricted_service_and_valid_number(notify_db, notif
|
||||
assert persisted_notification.notification_type == 'sms'
|
||||
provider_tasks.deliver_sms.apply_async.assert_called_once_with(
|
||||
[str(persisted_notification.id)],
|
||||
queue="send-sms"
|
||||
queue="send-tasks"
|
||||
)
|
||||
|
||||
|
||||
@@ -507,7 +507,7 @@ def test_should_send_sms_if_restricted_service_and_non_team_number_with_test_key
|
||||
persisted_notification = Notification.query.one()
|
||||
mocked_deliver_sms.assert_called_once_with(
|
||||
[str(persisted_notification.id)],
|
||||
queue="send-sms"
|
||||
queue="send-tasks"
|
||||
)
|
||||
|
||||
|
||||
@@ -535,7 +535,7 @@ def test_should_send_email_if_restricted_service_and_non_team_email_address_with
|
||||
persisted_notification = Notification.query.one()
|
||||
mocked_deliver_email.assert_called_once_with(
|
||||
[str(persisted_notification.id)],
|
||||
queue="send-email"
|
||||
queue="send-tasks"
|
||||
)
|
||||
|
||||
|
||||
@@ -602,7 +602,7 @@ def test_should_put_send_email_task_in_research_mode_queue_if_research_mode_serv
|
||||
persisted_notification = Notification.query.one()
|
||||
provider_tasks.deliver_email.apply_async.assert_called_once_with(
|
||||
[str(persisted_notification.id)],
|
||||
queue="research-mode"
|
||||
queue="research-mode-tasks"
|
||||
)
|
||||
|
||||
|
||||
@@ -639,7 +639,7 @@ def test_should_send_sms_template_to_and_persist_with_job_id(sample_job, sample_
|
||||
|
||||
provider_tasks.deliver_sms.apply_async.assert_called_once_with(
|
||||
[str(persisted_notification.id)],
|
||||
queue="send-sms"
|
||||
queue="send-tasks"
|
||||
)
|
||||
|
||||
|
||||
@@ -736,7 +736,7 @@ def test_should_use_email_template_and_persist(sample_email_template_with_placeh
|
||||
assert persisted_notification.notification_type == 'email'
|
||||
|
||||
provider_tasks.deliver_email.apply_async.assert_called_once_with(
|
||||
[str(persisted_notification.id)], queue='send-email')
|
||||
[str(persisted_notification.id)], queue='send-tasks')
|
||||
|
||||
|
||||
def test_send_email_should_use_template_version_from_job_not_latest(sample_email_template, mocker):
|
||||
@@ -767,7 +767,7 @@ def test_send_email_should_use_template_version_from_job_not_latest(sample_email
|
||||
assert not persisted_notification.sent_by
|
||||
assert persisted_notification.notification_type == 'email'
|
||||
provider_tasks.deliver_email.apply_async.assert_called_once_with([str(persisted_notification.id)],
|
||||
queue='send-email')
|
||||
queue='send-tasks')
|
||||
|
||||
|
||||
def test_should_use_email_template_subject_placeholders(sample_email_template_with_placeholders, mocker):
|
||||
@@ -793,7 +793,7 @@ def test_should_use_email_template_subject_placeholders(sample_email_template_wi
|
||||
assert not persisted_notification.reference
|
||||
assert persisted_notification.notification_type == 'email'
|
||||
provider_tasks.deliver_email.apply_async.assert_called_once_with(
|
||||
[str(persisted_notification.id)], queue='send-email'
|
||||
[str(persisted_notification.id)], queue='send-tasks'
|
||||
)
|
||||
|
||||
|
||||
@@ -821,7 +821,7 @@ def test_should_use_email_template_and_persist_without_personalisation(sample_em
|
||||
assert not persisted_notification.reference
|
||||
assert persisted_notification.notification_type == 'email'
|
||||
provider_tasks.deliver_email.apply_async.assert_called_once_with([str(persisted_notification.id)],
|
||||
queue='send-email')
|
||||
queue='send-tasks')
|
||||
|
||||
|
||||
def test_send_sms_should_go_to_retry_queue_if_database_errors(sample_template, mocker):
|
||||
@@ -844,7 +844,7 @@ def test_send_sms_should_go_to_retry_queue_if_database_errors(sample_template, m
|
||||
now.strftime(DATETIME_FORMAT)
|
||||
)
|
||||
assert provider_tasks.deliver_sms.apply_async.called is False
|
||||
tasks.send_sms.retry.assert_called_with(exc=expected_exception, queue='retry')
|
||||
tasks.send_sms.retry.assert_called_with(exc=expected_exception, queue="retry-tasks")
|
||||
|
||||
assert Notification.query.count() == 0
|
||||
|
||||
@@ -869,7 +869,7 @@ def test_send_email_should_go_to_retry_queue_if_database_errors(sample_email_tem
|
||||
now.strftime(DATETIME_FORMAT)
|
||||
)
|
||||
assert not provider_tasks.deliver_email.apply_async.called
|
||||
tasks.send_email.retry.assert_called_with(exc=expected_exception, queue='retry')
|
||||
tasks.send_email.retry.assert_called_with(exc=expected_exception, queue="retry-tasks")
|
||||
|
||||
assert Notification.query.count() == 0
|
||||
|
||||
@@ -1002,7 +1002,6 @@ def test_build_dvla_file(sample_letter_template, mocker):
|
||||
file_location="{}-dvla-job.text".format(job.id)
|
||||
)
|
||||
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):
|
||||
@@ -1016,7 +1015,7 @@ def test_build_dvla_file_retries_if_all_notifications_are_not_created(sample_let
|
||||
build_dvla_file(job.id)
|
||||
mocked.assert_not_called()
|
||||
|
||||
tasks.build_dvla_file.retry.assert_called_with(queue='retry',
|
||||
tasks.build_dvla_file.retry.assert_called_with(queue="retry-tasks",
|
||||
exc="All notifications for job {} are not persisted".format(job.id))
|
||||
assert Job.query.get(job.id).job_status == 'in progress'
|
||||
mocked_send_task.assert_not_called()
|
||||
|
||||
Reference in New Issue
Block a user