Fix issues with PR #18928 ...

Fix celery task failure
Fix code quality test failures
Fix python test failures
Fix issue with PR #22042
Rebase and fix new test failures
This commit is contained in:
Mahyar Damavand
2019-10-15 18:30:13 +03:30
parent f93023bafe
commit 4ff5d129c8
5 changed files with 35 additions and 14 deletions

View File

@@ -8,18 +8,24 @@ import logging
from celery.exceptions import MaxRetriesExceededError
from celery.task import task # pylint: disable=no-name-in-module, import-error
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from edx_ace import ace
from edx_ace.errors import RecoverableChannelDeliveryError
from edx_ace.message import Message
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.lib.celery.task_utils import emulate_http_request
log = logging.getLogger('edx.celery.task')
@task(bind=True)
def send_activation_email(self, msg, from_address=None):
def send_activation_email(self, msg_string, from_address=None):
"""
Sending an activation email to the user.
"""
msg = Message.from_string(msg_string)
max_retries = settings.RETRY_ACTIVATION_EMAIL_MAX_ATTEMPTS
retries = self.request.retries
@@ -31,8 +37,12 @@ def send_activation_email(self, msg, from_address=None):
dest_addr = msg.recipient.email_address
site = Site.objects.get_current()
user = User.objects.get(username=msg.recipient.username)
try:
ace.send(msg)
with emulate_http_request(site=site, user=user):
ace.send(msg)
# Log that the Activation Email has been sent to user without an exception
log.info("Activation Email has been sent to User {user_email}".format(
user_email=dest_addr

View File

@@ -31,7 +31,6 @@ from student.views import (
confirm_email_change,
do_email_change_request,
generate_activation_email_context,
send_reactivation_email_for_user,
validate_new_email
)
from third_party_auth.views import inactive_user_view
@@ -104,7 +103,7 @@ class ActivationEmailTests(EmailTemplateTagMixin, CacheIsolationTestCase):
# sent from an OpenEdX installation.
OPENEDX_FRAGMENTS = [
(
u"You're almost there! Use the link below to activate your account to access engaging, "
u"Use the link below to activate your account to access engaging, "
u"high-quality {platform_name} courses. Note that you will not be able to log back into your "
u"account until you have activated it.".format(
platform_name=settings.PLATFORM_NAME

View File

@@ -50,7 +50,7 @@ class SendActivationEmailTestCase(TestCase):
from_address = 'task_testing@example.com'
email_max_attempts = settings.RETRY_ACTIVATION_EMAIL_MAX_ATTEMPTS
send_activation_email.delay(self.msg, from_address=from_address)
send_activation_email.delay(str(self.msg), from_address=from_address)
# Asserts sending email retry logging.
for attempt in range(email_max_attempts):
@@ -79,7 +79,7 @@ class SendActivationEmailTestCase(TestCase):
"""
from_address = 'task_testing@example.com'
send_activation_email.delay(self.msg, from_address=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(

View File

@@ -227,7 +227,7 @@ def compose_and_send_activation_email(user, profile, user_registration=None):
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(msg)
send_activation_email.delay(str(msg))
@login_required