From c14dde3be2b3de0bc1b588a0f9294644b244f5f7 Mon Sep 17 00:00:00 2001 From: Kyle MacMillan <16893311+k-macmillan@users.noreply.github.com> Date: Thu, 26 Dec 2024 17:10:07 -0500 Subject: [PATCH] removed unused code --- app/celery/process_comp_and_pen.py | 9 +- .../comp_and_pen/scheduled_message_helpers.py | 102 ------------------ .../test_scheduled_message_helpers.py | 12 --- 3 files changed, 8 insertions(+), 115 deletions(-) delete mode 100644 app/integrations/comp_and_pen/scheduled_message_helpers.py delete mode 100644 tests/app/integrations/comp_and_pen/test_scheduled_message_helpers.py diff --git a/app/celery/process_comp_and_pen.py b/app/celery/process_comp_and_pen.py index 11cda923c8..895c4f563f 100644 --- a/app/celery/process_comp_and_pen.py +++ b/app/celery/process_comp_and_pen.py @@ -1,3 +1,4 @@ +from dataclasses import dataclass from uuid import uuid4 from flask import current_app @@ -11,11 +12,17 @@ Service, Template, ) -from app.integrations.comp_and_pen.scheduled_message_helpers import DynamoRecord from app.notifications.send_notifications import lookup_notification_sms_setup_data, send_notification_bypass_route from app.va.identifier import IdentifierType +@dataclass +class DynamoRecord: + participant_id: str + payment_amount: str + vaprofile_id: str + + @notify_celery.task(name='comp-and-pen-batch-process') @statsd(namespace='tasks') def comp_and_pen_batch_process(records: list[dict[str, str]]) -> None: diff --git a/app/integrations/comp_and_pen/scheduled_message_helpers.py b/app/integrations/comp_and_pen/scheduled_message_helpers.py deleted file mode 100644 index 8a138ecf7e..0000000000 --- a/app/integrations/comp_and_pen/scheduled_message_helpers.py +++ /dev/null @@ -1,102 +0,0 @@ -from dataclasses import dataclass -from uuid import uuid4 - -from flask import current_app -from sqlalchemy.orm.exc import NoResultFound - -from app.constants import SMS_TYPE -from app.dao.service_sms_sender_dao import dao_get_service_sms_sender_by_id -from app.models import ( - Service, - Template, -) -from app.notifications.send_notifications import send_notification_bypass_route -from app.va.identifier import IdentifierType - - -@dataclass -class DynamoRecord: - participant_id: str - payment_amount: str - vaprofile_id: str - - -class CompPenMsgHelper: - dynamodb_table = None - - def __init__(self, dynamodb_table_name: str) -> None: - """ - This class is a collection of helper methods to facilitate the delivery of schedule Comp and Pen notifications. - - :param dynamodb_table_name (str): the name of the dynamodb table for the db operations, required - """ - self.dynamodb_table_name = dynamodb_table_name - - def batch_send_comp_and_pen_sms( - self, - service: Service, - template: Template, - sms_sender_id: str, - comp_and_pen_messages: list[DynamoRecord], - perf_to_number: str, - ) -> None: - """ - Sends scheduled SMS notifications to recipients based on the provided parameters. - - Args: - :param service (Service): The service used to send the SMS notifications. - :param template (Template): The template used for the SMS notifications. - :param sms_sender_id (str): The ID of the SMS sender. - :param comp_and_pen_messages (list[DynamoRecord): A list of dictionaries from the dynamodb table containing - the details needed to send the messages. - :param perf_to_number (str): The recipient's phone number. - - Raises: - Exception: If there is an error while sending the SMS notification. - """ - try: - reply_to_text = dao_get_service_sms_sender_by_id(service.id, sms_sender_id).sms_sender - except (NoResultFound, AttributeError): - current_app.logger.exception('Unable to send comp and pen notifications due to improper sms_sender') - raise - - for item in comp_and_pen_messages: - current_app.logger.debug('sending - record from dynamodb: %s', item.participant_id) - - # Use perf_to_number as the recipient if available. Otherwise, use vaprofile_id as recipient_item. - recipient = perf_to_number - recipient_item = ( - None - if perf_to_number is not None - else { - 'id_type': IdentifierType.VA_PROFILE_ID.value, - 'id_value': item.vaprofile_id, - } - ) - - try: - # call generic method to send messages - send_notification_bypass_route( - service=service, - template=template, - notification_type=SMS_TYPE, - reply_to_text=reply_to_text, - personalisation={'amount': item.payment_amount}, - sms_sender_id=sms_sender_id, - recipient=recipient, - recipient_item=recipient_item, - notification_id=uuid4(), - ) - except Exception: - current_app.logger.exception( - 'Error attempting to send Comp and Pen notification with ' - 'send_comp_and_pen_sms | record from dynamodb: %s', - item.participant_id, - ) - else: - if perf_to_number is not None: - current_app.logger.info( - 'Notification sent using Perf simulated number %s instead of vaprofile_id', perf_to_number - ) - - current_app.logger.info('Notification sent to queue for record from dynamodb: %s', item.participant_id) diff --git a/tests/app/integrations/comp_and_pen/test_scheduled_message_helpers.py b/tests/app/integrations/comp_and_pen/test_scheduled_message_helpers.py deleted file mode 100644 index 6b384e89af..0000000000 --- a/tests/app/integrations/comp_and_pen/test_scheduled_message_helpers.py +++ /dev/null @@ -1,12 +0,0 @@ -import pytest - -from app.integrations.comp_and_pen.scheduled_message_helpers import CompPenMsgHelper - - -@pytest.fixture -def msg_helper(mocker, dynamodb_mock) -> CompPenMsgHelper: - # Mocks necessary for dynamodb - mocker.patch('boto3.resource') - helper = CompPenMsgHelper('test') - mocker.patch.object(helper, 'dynamodb_table', dynamodb_mock) - return helper