Пример #1
0
 def test_send_assigned_offer_reminder_email_args(self, mock_remind_email):
     """ Test that the code_expiration_date passed is equal to coupon batch end date """
     serializer = CouponCodeRemindSerializer(
         data=self.data, context={'coupon': self.coupon})
     serializer._trigger_email_sending_task(  # pylint: disable=protected-access
         subject=self.SUBJECT,
         greeting=self.GREETING,
         closing=self.CLOSING,
         assigned_offer=self.offer_assignment,
         redeemed_offer_count=3,
         total_offer_count=5,
         sender_alias=self.SENDER_ALIAS,
     )
     expected_expiration_date = self.coupon.attr.coupon_vouchers.vouchers.first(
     ).end_datetime
     mock_remind_email.assert_called_with(
         subject=self.SUBJECT,
         greeting=self.GREETING,
         closing=self.CLOSING,
         learner_email=self.offer_assignment.user_email,
         code=self.offer_assignment.code,
         redeemed_offer_count=mock.ANY,
         total_offer_count=mock.ANY,
         code_expiration_date=expected_expiration_date.strftime(
             '%d %B, %Y %H:%M %Z'),
         sender_alias=self.SENDER_ALIAS)
Пример #2
0
    def test_send_reminder_email_error(self, mock_email):
        """ Test that we log an appropriate message if the code reminder email cannot be sent. """
        mock_email.side_effect = Exception('Ignore me - reminder')
        serializer = CouponCodeRemindSerializer(
            data=self.data, context={'coupon': self.coupon})
        expected = [
            (self.LOGGER_NAME, 'ERROR',
             '[Offer Reminder] Email for offer_assignment_id: {} with greeting \'{}\' and closing \'{}\' raised '
             'exception: Exception(\'Ignore me - reminder\',)'.format(
                 self.offer_assignment.id,
                 self.GREETING,
                 self.CLOSING,
             )),
        ]

        with self.assertRaises(Exception):
            with LogCapture(self.LOGGER_NAME) as log:
                serializer._trigger_email_sending_task(  # pylint: disable=protected-access
                    greeting=self.GREETING,
                    closing=self.CLOSING,
                    assigned_offer=self.offer_assignment,
                    redeemed_offer_count=3,
                    total_offer_count=5,
                )
        log.check_present(*expected)
Пример #3
0
    def test_send_reminder_email_error(self, mock_email):
        """ Test that we log an appropriate message if the code reminder email cannot be sent. """
        mock_email.side_effect = Exception('Ignore me - reminder')
        serializer = CouponCodeRemindSerializer(
            data=self.data, context={'coupon': self.coupon})
        expected = [
            (self.LOGGER_NAME, 'ERROR',
             '[Offer Reminder] Email for offer_assignment_id: {} with subject \'{}\', greeting \'{}\' '
             'closing \'{}\' attachments {}, and base_enterprise_url \'{}\' raised exception: {}'
             .format(self.offer_assignment.id, self.SUBJECT, self.GREETING,
                     self.CLOSING, self.ATTACHMENTS, self.BASE_ENTERPRISE_URL,
                     repr(Exception('Ignore me - reminder')))),
        ]

        with self.assertRaises(Exception):
            with LogCapture(self.LOGGER_NAME) as log:
                serializer._trigger_email_sending_task(  # pylint: disable=protected-access
                    subject=self.SUBJECT,
                    greeting=self.GREETING,
                    closing=self.CLOSING,
                    assigned_offer=self.offer_assignment,
                    redeemed_offer_count=3,
                    total_offer_count=5,
                    sender_alias=self.SENDER_ALIAS,
                    reply_to=self.REPLY_TO,
                    attachments=self.ATTACHMENTS,
                    base_enterprise_url=self.BASE_ENTERPRISE_URL,
                )
        log.check_present(*expected)