def send_notif_to_attendees(order, purchaser_id):
    """
    Send notification to attendees of an order.
    :param order:
    :param purchaser_id:
    :return:
    """
    for holder in order.ticket_holders:
        if holder.user:
            # send notification if the ticket holder is a registered user.
            if holder.user.id != purchaser_id:
                # The ticket holder is not the purchaser
                actions = get_ticket_purchased_attendee_notification_actions(holder.pdf_url)
                send_notification(
                    user=holder.user,
                    title=NOTIFS[TICKET_PURCHASED_ATTENDEE]['title'].format(
                        event_name=order.event.name
                    ),
                    message=NOTIFS[TICKET_PURCHASED_ATTENDEE]['message'],
                    actions=actions
                )
            else:
                # The Ticket purchaser
                actions = get_ticket_purchased_notification_actions(order.id, order.tickets_pdf_url)
                send_notification(
                    user=holder.user,
                    title=NOTIFS[TICKET_PURCHASED]['title'].format(
                        invoice_id=order.invoice_number
                    ),
                    message=NOTIFS[TICKET_PURCHASED]['message'],
                    actions=actions
                )
def send_notif_to_attendees(order, purchaser_id):
    """
    Send notification to attendees of an order.
    :param order:
    :param purchaser_id:
    :return:
    """
    for holder in order.ticket_holders:
        if holder.user:
            # send notification if the ticket holder is a registered user.
            if holder.user.id != purchaser_id:
                # The ticket holder is not the purchaser
                actions = get_ticket_purchased_attendee_notification_actions(
                    holder.pdf_url)
                send_notification(
                    user=holder.user,
                    title=NOTIFS[TICKET_PURCHASED_ATTENDEE]['title'].format(
                        event_name=order.event.name),
                    message=NOTIFS[TICKET_PURCHASED_ATTENDEE]['message'],
                    actions=actions,
                )
            else:
                # The Ticket purchaser
                actions = get_ticket_purchased_notification_actions(
                    order.id, order.tickets_pdf_url)
                send_notification(
                    user=holder.user,
                    title=NOTIFS[TICKET_PURCHASED]['title'].format(
                        invoice_id=order.invoice_number),
                    message=NOTIFS[TICKET_PURCHASED]['message'],
                    actions=actions,
                )
    def test_ticket_purchased_attendee(self):
        """Method to test the actions associated with a notification of tickets purchased for an attendee that is
           not the buyer."""

        with self.app.test_request_context():
            request_pdfurl = 'https://localhost/pdf/e/24324/'
            response = get_ticket_purchased_attendee_notification_actions(request_pdfurl)
            expected_action = NotificationAction(
                subject='tickets-pdf', link=request_pdfurl, action_type='view'
            )
            expected_action = [expected_action]
            expected_length = len(expected_action)
            response_length = len(response)
            self.assertIsInstance(response, list)
            self.assertEqual(expected_action[0].subject, response[0].subject)
            self.assertEqual(expected_length, response_length)