def test_RetrySendUntilFail(self, mock_log):
        """
        Tests retries when the activation email doesn't send
        """
        from_address = '*****@*****.**'
        email_max_attempts = settings.RETRY_ACTIVATION_EMAIL_MAX_ATTEMPTS

        send_activation_email.delay(str(self.msg), from_address=from_address)

        # Asserts sending email retry logging.
        for attempt in range(email_max_attempts):
            mock_log.info.assert_any_call(
                'Retrying sending email to user {dest_addr}, attempt # {attempt} of {max_attempts}'.format(
                    dest_addr=self.student.email,
                    attempt=attempt,
                    max_attempts=email_max_attempts
                ))
        assert mock_log.info.call_count == 6

        # Asserts that the error was logged on crossing max retry attempts.
        mock_log.error.assert_called_with(
            'Unable to send activation email to user from "%s" to "%s"',
            from_address,
            self.student.email,
            exc_info=True
        )
        assert mock_log.error.call_count == 1
示例#2
0
def compose_and_send_activation_email(user, profile, user_registration=None, redirect_url=None):
    """
    Construct all the required params and send the activation email
    through celery task

    Arguments:
        user: current logged-in user
        profile: profile object of the current logged-in user
        user_registration: registration of the current logged-in user
        redirect_url: The URL to redirect to after successful activation
    """
    route_enabled = settings.FEATURES.get('REROUTE_ACTIVATION_EMAIL')

    msg = compose_activation_email(user, user_registration, route_enabled, profile.name, redirect_url)

    send_activation_email.delay(str(msg))
示例#3
0
def compose_and_send_activation_email(user, profile, user_registration=None):
    """
    Construct all the required params and send the activation email
    through celery task

    Arguments:
        user: current logged-in user
        profile: profile object of the current logged-in user
        user_registration: registration of the current logged-in user
    """
    route_enabled = settings.FEATURES.get('REROUTE_ACTIVATION_EMAIL')

    root_url = configuration_helpers.get_value('LMS_ROOT_URL', settings.LMS_ROOT_URL)
    msg = compose_activation_email(root_url, user, user_registration, route_enabled, profile.name)

    send_activation_email.delay(str(msg))
    def test_UnrecoverableSendError(self, mock_log):
        """
        Tests that a major failure of the send is logged
        """
        from_address = '*****@*****.**'

        send_activation_email.delay(str(self.msg), from_address=from_address)

        # Asserts that the error was logged
        mock_log.exception.assert_called_with(
            'Unable to send activation email to user from "%s" to "%s"',
            from_address,
            self.student.email,
        )

        # Assert that nothing else was logged
        assert mock_log.info.call_count == 0
        assert mock_log.error.call_count == 0
        assert mock_log.exception.call_count == 1