Exemplo n.º 1
0
    def test_send_revocation_email_error(self, mock_email):
        """ Test that we log an appropriate message if the code revocation email cannot be sent. """
        mock_email.side_effect = Exception('Ignore me - revocation')
        validated_data = {
            'code': self.code,
            'email': self.email,
            'offer_assignments': self.offer_assignments,
        }
        context = {
            'coupon': self.coupon,
            'greeting': self.GREETING,
            'closing': self.CLOSING,
        }
        serializer = CouponCodeRevokeSerializer(data=self.data,
                                                context=context)

        expected = [
            (self.LOGGER_NAME, 'ERROR',
             '[Offer Revocation] Encountered error when revoking code {} for user {} with greeting \'{}\' and '
             'closing \'{}\''.format(
                 self.code,
                 self.email,
                 self.GREETING,
                 self.CLOSING,
             )),
        ]
        with LogCapture(self.LOGGER_NAME) as log:
            serializer.create(validated_data=validated_data)
            log.check_present(*expected)
Exemplo n.º 2
0
    def test_send_revocation_email_error_no_greeting(self):
        """ Test that we log an appropriate message if the code revocation email cannot be sent. """
        serializer = CouponCodeRevokeSerializer(
            data=self.data, context={'coupon': self.coupon})

        expected = [
            (  # pylint: disable=too-many-format-args
                self.LOGGER_NAME, 'ERROR',
                '[Offer Revocation] Encountered error when revoking code {} for user {} with subject {}, '
                'greeting {} closing {} base_enterprise_url \'{}\' and files []'
                .format(
                    None,
                    None,
                    None,
                    None,
                    None,
                    '',
                )),
        ]
        with LogCapture(self.LOGGER_NAME) as log:
            serializer.create(
                validated_data={
                    'sender_id': None,
                    'template': None,
                    'user': {
                        'email': None
                    },
                    'enterprise_customer_uuid': uuid4()
                })
            log.check_present(*expected)
Exemplo n.º 3
0
 def test_send_revoke_email_args_with_base_url(self, mock_revoke_email):
     """ Test that revoke email is passed correct enterprise_base_url """
     context = {
         'coupon': self.coupon,
         'subject': self.SUBJECT,
         'greeting': self.GREETING,
         'closing': self.CLOSING,
         'files': self.ATTACHMENTS,
         'base_enterprise_url': self.BASE_ENTERPRISE_URL,
     }
     validated_data = {
         'code': self.code,
         'user': {
             'email': self.email
         },
         'offer_assignments': self.offer_assignments,
         'sender_id': None,
         'template': None,
         'enterprise_customer_uuid': uuid4()
     }
     serializer = CouponCodeRevokeSerializer(data=self.data,
                                             context=context)
     serializer.create(validated_data=validated_data)
     mock_revoke_email.assert_called_with(
         subject=self.SUBJECT,
         greeting=self.GREETING,
         closing=self.CLOSING,
         learner_email=self.email,
         code=self.code,
         sender_alias=self.SENDER_ALIAS,
         reply_to='',
         base_enterprise_url=self.BASE_ENTERPRISE_URL,
         attachments=self.ATTACHMENTS)
Exemplo n.º 4
0
    def test_send_revocation_email_error_no_greeting(self):
        """ Test that we log an appropriate message if the code revocation email cannot be sent. """
        serializer = CouponCodeRevokeSerializer(
            data=self.data, context={'coupon': self.coupon})

        expected = [
            (self.LOGGER_NAME, 'ERROR',
             '[Offer Revocation] Encountered error when revoking code {} for user {} with greeting {} and '
             'closing {}'.format(None, None, None, None)),
        ]
        with LogCapture(self.LOGGER_NAME) as log:
            serializer.create(validated_data={})
            log.check_present(*expected)
Exemplo n.º 5
0
    def test_send_revocation_email_error(self, mock_email):
        """ Test that we log an appropriate message if the code revocation email cannot be sent. """
        mock_email.side_effect = Exception('Ignore me - revocation')
        validated_data = {
            'code': self.code,
            'user': {
                'email': self.email
            },
            'offer_assignments': self.offer_assignments,
            'sender_id': None,
            'template': None,
            'enterprise_customer_uuid': uuid4()
        }
        context = {
            'coupon': self.coupon,
            'subject': self.SUBJECT,
            'greeting': self.GREETING,
            'closing': self.CLOSING,
            'base_enterprise_url': self.BASE_ENTERPRISE_URL,
            'files': self.ATTACHMENTS
        }
        serializer = CouponCodeRevokeSerializer(data=self.data,
                                                context=context)

        expected = [
            (self.LOGGER_NAME, 'ERROR',
             '[Offer Revocation] Encountered error when revoking code {} for user {} with subject \'{}\', '
             'greeting \'{}\' closing \'{}\' base_enterprise_url \'{}\' and files {}'
             .format(
                 self.code,
                 self.email,
                 self.SUBJECT,
                 self.GREETING,
                 self.CLOSING,
                 self.BASE_ENTERPRISE_URL,
                 self.ATTACHMENTS,
             )),
        ]
        with LogCapture(self.LOGGER_NAME) as log:
            serializer.create(validated_data=validated_data)
            log.check_present(*expected)