From 6a73c3f7b6a4379818e39766ebaa8f3c2a13b26f Mon Sep 17 00:00:00 2001 From: Kyle MacMillan <16893311+k-macmillan@users.noreply.github.com> Date: Thu, 26 Dec 2024 16:16:29 -0500 Subject: [PATCH] Updated to cover 100% of the code --- tests/app/celery/test_process_comp_and_pen.py | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/tests/app/celery/test_process_comp_and_pen.py b/tests/app/celery/test_process_comp_and_pen.py index 7b0e1c0909..10abdd2dc1 100644 --- a/tests/app/celery/test_process_comp_and_pen.py +++ b/tests/app/celery/test_process_comp_and_pen.py @@ -1,10 +1,13 @@ +from unittest.mock import patch + import pytest from sqlalchemy.orm.exc import NoResultFound from app.celery.process_comp_and_pen import comp_and_pen_batch_process +from app.exceptions import NotificationTechnicalFailureException -def test_comp_and_pen_batch_process_happy_path(mocker, sample_template) -> None: +def test_comp_and_pen_batch_process_happy_path(mocker, sample_template, perf_number) -> None: template = sample_template() mocker.patch( 'app.celery.process_comp_and_pen.lookup_notification_sms_setup_data', @@ -20,7 +23,26 @@ def test_comp_and_pen_batch_process_happy_path(mocker, sample_template) -> None: ] comp_and_pen_batch_process(records) - # comp_and_pen_batch_process can fail without raising an exception, so test it called the send_to_queue... + # comp_and_pen_batch_process can fail without raising an exception, so test it called send_to_queue_for_recipient... + mock_send.call_count == len(records) + + +def test_comp_and_pen_batch_process_perf_number_happy_path(mocker, sample_template) -> None: + template = sample_template() + mocker.patch( + 'app.celery.process_comp_and_pen.lookup_notification_sms_setup_data', + return_value=(template.service, template, str(template.service.get_default_sms_sender_id())), + ) + mock_send = mocker.patch('app.notifications.send_notifications.send_notification_to_queue') + + records = [ + {'participant_id': '55', 'payment_amount': '55.56', 'vaprofile_id': '57'}, + {'participant_id': '42', 'payment_amount': '42.42', 'vaprofile_id': '43627'}, + ] + with patch.dict('os.environ', {'COMP_AND_PEN_PERF_TO_NUMBER': '8675309'}): + comp_and_pen_batch_process(records) + + # comp_and_pen_batch_process can fail without raising an exception, so test it called send_notification_to_queue mock_send.call_count == len(records) @@ -33,3 +55,22 @@ def test_comp_and_pen_batch_process_exception(mocker, exception_tested) -> None: with pytest.raises(exception_tested): comp_and_pen_batch_process({}) + + +def test_comp_and_pen_batch_process_bypass_exception(mocker, sample_template) -> None: + template = sample_template() + mocker.patch( + 'app.celery.process_comp_and_pen.lookup_notification_sms_setup_data', + return_value=(template.service, template, str(template.service.get_default_sms_sender_id())), + ) + mocker.patch( + 'app.celery.process_comp_and_pen.send_notification_bypass_route', + side_effect=NotificationTechnicalFailureException, + ) + mock_logger = mocker.patch('app.celery.process_comp_and_pen.current_app.logger') + + comp_and_pen_batch_process([{'participant_id': '55', 'payment_amount': '55.56', 'vaprofile_id': '57'}]) + + # comp_and_pen_batch_process can fail without raising an exception + mock_logger.exception.assert_called_once() + mock_logger.info.assert_not_called()