示例#1
0
    def test_send_assigned_offer_email_args_with_enterprise_url(
            self, mock_assign_email):
        """ Test that the code_expiration_date passed is equal to coupon batch end date """
        serializer = CouponCodeAssignmentSerializer(
            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,
            voucher_usage_type=Voucher.MULTI_USE_PER_CUSTOMER,
            base_enterprise_url=self.BASE_ENTERPRISE_URL,
        )
        expected_expiration_date = self.coupon.attr.coupon_vouchers.vouchers.first(
        ).end_datetime

        assert mock_assign_email.call_count == 1
        assign_email_args = mock_assign_email.call_args[1]
        assert assign_email_args['subject'] == self.SUBJECT
        assert assign_email_args['greeting'] == self.GREETING
        assert assign_email_args['closing'] == self.CLOSING
        assert assign_email_args[
            'learner_email'] == self.offer_assignment.user_email
        assert assign_email_args[
            'offer_assignment_id'] == self.offer_assignment.id
        assert assign_email_args['code'] == self.offer_assignment.code
        assert assign_email_args[
            'code_expiration_date'] == expected_expiration_date.strftime(
                '%d %B, %Y %H:%M %Z')
        assert assign_email_args[
            'base_enterprise_url'] == self.BASE_ENTERPRISE_URL
    def test_send_assignment_email_error(self, mock_email):
        """ Test that we log an appropriate message if the code assignment email cannot be sent. """
        mock_email.side_effect = Exception('Ignore me - assignment')
        serializer = CouponCodeAssignmentSerializer(data=self.data, context={'coupon': self.coupon})
        expected = [
            (
                self.LOGGER_NAME,
                'ERROR',
                '[Offer Assignment] Email for offer_assignment_id: {} with greeting \'{}\' and closing \'{}\' raised '
                'exception: {}'.format(
                    self.offer_assignment.id,
                    self.GREETING,
                    self.CLOSING,
                    repr(Exception('Ignore me - assignment'))
                )
            ),
        ]

        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,
                voucher_usage_type=Voucher.MULTI_USE_PER_CUSTOMER
            )
            log.check_present(*expected)
示例#3
0
    def test_send_assignment_email_error(self, mock_email):
        """ Test that we log an appropriate message if the code assignment email cannot be sent. """
        mock_email.side_effect = Exception('Ignore me - assignment')
        serializer = CouponCodeAssignmentSerializer(
            data=self.code_assignment_serializer_data,
            context={'coupon': self.coupon})
        expected = [
            (self.LOGGER_NAME, 'ERROR',
             '[Offer Assignment] Email for offer_assignment_id: {} with subject \'{}\', greeting \'{}\' closing '
             '\'{}\' and attachments {}, raised exception: {}'.format(
                 self.offer_assignment.id, self.SUBJECT, self.GREETING,
                 self.CLOSING, self.ATTACHMENTS,
                 repr(Exception('Ignore me - assignment')))),
        ]

        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,
                voucher_usage_type=Voucher.MULTI_USE_PER_CUSTOMER,
                sender_alias=self.SENDER_ALIAS,
                reply_to=self.REPLY_TO,
                attachments=self.ATTACHMENTS,
            )
            log.check_present(*expected)
 def test_send_assigned_offer_email_args(self, mock_assign_email):
     """ Test that the code_expiration_date passed is equal to coupon batch end date """
     serializer = CouponCodeAssignmentSerializer(data=self.data, context={'coupon': self.coupon})
     serializer._trigger_email_sending_task(  # pylint: disable=protected-access
         greeting=self.GREETING,
         closing=self.CLOSING,
         assigned_offer=self.offer_assignment,
         voucher_usage_type=Voucher.MULTI_USE_PER_CUSTOMER
     )
     expected_expiration_date = self.coupon.attr.coupon_vouchers.vouchers.first().end_datetime
     mock_assign_email.assert_called_with(
         greeting=self.GREETING,
         closing=self.CLOSING,
         offer_assignment_id=self.offer_assignment.id,
         learner_email=self.offer_assignment.user_email,
         code=self.offer_assignment.code,
         redemptions_remaining=mock.ANY,
         code_expiration_date=expected_expiration_date.strftime('%d %B, %Y')
     )