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_notification(self): """Method to test the actions associated with a notification of tickets purchased.""" with self.app.test_request_context(): request_url = 'https://localhost/e/345525/order' request_order_id = 1 response = get_ticket_purchased_notification_actions( request_order_id, request_url) expected_action = NotificationAction(subject='order', link=request_url, subject_id=request_order_id, 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)