mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-21 07:51:13 -05:00
added more unit tests
This commit is contained in:
@@ -23,6 +23,7 @@ from app.celery.tasks import (
|
||||
|
||||
from tests.app.db import create_notification, create_service_callback_api
|
||||
from tests.conftest import set_config
|
||||
from unittest.mock import call
|
||||
|
||||
|
||||
def test_update_job_to_sent_to_dvla(sample_letter_template, sample_letter_job):
|
||||
@@ -114,7 +115,25 @@ def test_update_letter_notifications_statuses_persisted(notify_api, mocker, samp
|
||||
assert failed_letter.status == NOTIFICATION_TECHNICAL_FAILURE
|
||||
assert failed_letter.billable_units == 2
|
||||
assert failed_letter.updated_at
|
||||
assert send_mock.called
|
||||
|
||||
calls = [call([str(failed_letter.id)], queue="notify-internal-tasks"),
|
||||
call([str(sent_letter.id)], queue="notify-internal-tasks")]
|
||||
send_mock.assert_has_calls(calls, any_order=True)
|
||||
|
||||
|
||||
def test_update_letter_notifications_does_not_call_send_callback_if_no_db_entry(notify_api, mocker,
|
||||
sample_letter_template):
|
||||
sent_letter = create_notification(sample_letter_template, reference='ref-foo', status=NOTIFICATION_SENDING,
|
||||
billable_units=0)
|
||||
valid_file = '{}|Sent|1|Unsorted\n'.format(sent_letter.reference)
|
||||
mocker.patch('app.celery.tasks.s3.get_s3_file', return_value=valid_file)
|
||||
|
||||
send_mock = mocker.patch(
|
||||
'app.celery.service_callback_tasks.send_delivery_status_to_service.apply_async'
|
||||
)
|
||||
|
||||
update_letter_notifications_statuses(filename='foo.txt')
|
||||
send_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_update_letter_notifications_to_sent_to_dvla_updates_based_on_notification_references(
|
||||
|
||||
@@ -50,6 +50,35 @@ def test_ses_callback_should_update_notification_status(
|
||||
send_mock.assert_called_once_with([str(notification.id)], queue="notify-internal-tasks")
|
||||
|
||||
|
||||
def test_ses_callback_does_not_call_send_delivery_status_if_no_db_entry(
|
||||
client,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_email_template,
|
||||
mocker):
|
||||
with freeze_time('2001-01-01T12:00:00'):
|
||||
|
||||
send_mock = mocker.patch(
|
||||
'app.celery.service_callback_tasks.send_delivery_status_to_service.apply_async'
|
||||
)
|
||||
notification = create_sample_notification(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
template=sample_email_template,
|
||||
reference='ref',
|
||||
status='sending',
|
||||
sent_at=datetime.utcnow()
|
||||
)
|
||||
|
||||
assert get_notification_by_id(notification.id).status == 'sending'
|
||||
|
||||
errors = process_ses_response(ses_notification_callback(reference='ref'))
|
||||
assert errors is None
|
||||
assert get_notification_by_id(notification.id).status == 'delivered'
|
||||
|
||||
send_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_ses_callback_should_update_multiple_notification_status_sent(
|
||||
client,
|
||||
notify_db,
|
||||
|
||||
@@ -61,10 +61,23 @@ def test_outcome_statistics_called_for_successful_callback(sample_notification,
|
||||
success, error = process_sms_client_response(status='3', reference=reference, client_name='MMG')
|
||||
assert success == "MMG callback succeeded. reference {} updated".format(str(reference))
|
||||
assert error is None
|
||||
assert send_mock.called
|
||||
send_mock.assert_called_once_with([str(sample_notification.id)], queue="notify-internal-tasks")
|
||||
stats_mock.assert_called_once_with(sample_notification)
|
||||
|
||||
|
||||
def test_sms_resonse_does_not_call_send_callback_if_no_db_entry(sample_notification, mocker):
|
||||
mocker.patch(
|
||||
'app.notifications.process_client_response.notifications_dao.update_notification_status_by_id',
|
||||
return_value=sample_notification
|
||||
)
|
||||
send_mock = mocker.patch(
|
||||
'app.celery.service_callback_tasks.send_delivery_status_to_service.apply_async'
|
||||
)
|
||||
reference = str(uuid.uuid4())
|
||||
process_sms_client_response(status='3', reference=reference, client_name='MMG')
|
||||
send_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_process_sms_response_return_success_for_send_sms_code_reference(mocker):
|
||||
stats_mock = mocker.patch('app.notifications.process_client_response.create_outcome_notification_statistic_tasks')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user