Esempio n. 1
0
 def test_send_assigned_offer_email_via_braze(
     self,
     subject,
     greeting,
     closing,
     tokens,
     side_effect,
     sender_alias,
     base_enterprise_url,
     search_url,
     mock_sailthru_task,
 ):
     """ Test that the offer assignment email message is sent to async task. """
     switch, __ = Switch.objects.get_or_create(name=ENABLE_BRAZE)
     switch.active = True
     switch.save()
     mock_sailthru_task.delay.side_effect = side_effect
     send_assigned_offer_email(
         subject,
         greeting,
         closing,
         tokens.get('offer_assignment_id'),
         tokens.get('learner_email'),
         tokens.get('code'),
         tokens.get('redemptions_remaining'),
         tokens.get('code_expiration_date'),
         sender_alias,
         base_enterprise_url,
     )
     email_body = format_assigned_offer_email(
         greeting, closing, tokens.get('learner_email'), tokens.get('code'),
         tokens.get('redemptions_remaining'),
         tokens.get('code_expiration_date'), search_url)
     mock_sailthru_task.delay.assert_called_once_with(
         tokens.get('learner_email'),
         tokens.get('offer_assignment_id'),
         subject,
         email_body,
         sender_alias,
         None,
         base_enterprise_url,
     )
Esempio n. 2
0
    def get_email_content(self, user_email, code):
        """
        Return the formatted email body and subject.
        """
        email_body = None
        voucher_qs = Voucher.objects.filter(code=code)
        if voucher_qs.exists():
            voucher = voucher_qs.first()
            offer = voucher.best_offer
            max_usage_limit = offer.max_global_applications or OFFER_MAX_USES_DEFAULT

            email_body = format_assigned_offer_email(
                self.email_greeting, self.email_closing, user_email, code,
                max_usage_limit if offer.max_global_applications
                == Voucher.MULTI_USE_PER_CUSTOMER else 1, voucher.end_datetime)
        else:
            logger.warning(
                '[Code Assignment Nudge Email] Unable to send the email for user_email: %s, code: %s because code does '
                'not have associated voucher.', user_email, code)
        return email_body, self.email_subject