Source code for report.customer_notifcation_report

from exceptions.task_exception import ReportNotificationStatusError
from report import report_messages as message


[docs]class CustomerNotificationReport:
[docs] def __init__(self, order_id, retailer_customer_id, phone_number_format_success, email_address_format_success, sms_sent, email_sent, timestamp): """ Class to handle the report to BQ Object Args: order_id (str): order number retailer_customer_id (str): customer number phone_number_format_success (bool): Was the phone number able to be processed email_address_format_success (bool): Was the email address able to be processed sms_sent (bool): Was the sms sent email_sent (bool): Was the email sent timestamp (str): timestamp to add to the report data """ self.order_id = order_id self.retailer_customer_id = retailer_customer_id self.phone_number_format_success = phone_number_format_success self.email_address_format_success = email_address_format_success self.sms_sent = sms_sent self.email_sent = email_sent self.timestamp = timestamp self.notification_status = self._create_notification_message()
def _create_notification_message(self): """ Uses if statements to determine which notification status message is returned Returns: str: message with the notification status for the current customer Raises: ReportNotificationStatusError: If the parameters given to the class are of invalid type """ if self.phone_number_format_success is True and self.email_address_format_success is True and \ self.sms_sent is True and self.email_sent is True: return message.SUCCESS elif self.phone_number_format_success is False and self.email_address_format_success is False: return message.INVALID_PHONE_NUMBER_AND_EMAIL elif self.email_address_format_success is False: return message.INVALID_EMAIL elif self.phone_number_format_success is False: return message.INVALID_PHONE_NUMBER elif self.sms_sent is False and self.email_sent is False: return message.FAILED_TO_SEND_EMAIL_AND_SMS elif self.sms_sent is False: return message.FAILED_TO_SEND_SMS elif self.email_sent is False: return message.FAILED_TO_SEND_EMAIL else: raise ReportNotificationStatusError
[docs] def get_object_for_report_data(self): """ Formats the report data into a form that can be sent to the notification report big query table class Returns: dict: all the required schemas and matching details for the bigquery report table """ report_data = {"OrderId": self.order_id, "RetailerCustomerId": self.retailer_customer_id, "Sms": self.sms_sent, "Email": self.email_sent, "NotificationStatus": self.notification_status, "Timestamp": self.timestamp} return report_data