Fix: from_address not pull from site configuration (#27946)
* Fix: from_address not pulled from site configuration
This commit is contained in:
@@ -8,10 +8,11 @@ from django.conf import settings
|
||||
from django.test import TestCase
|
||||
|
||||
from edx_ace.errors import ChannelError, RecoverableChannelDeliveryError
|
||||
from lms.djangoapps.courseware.tests.factories import UserFactory
|
||||
from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory, SiteFactory
|
||||
from common.djangoapps.student.models import Registration
|
||||
from common.djangoapps.student.tasks import send_activation_email
|
||||
from common.djangoapps.student.tests.factories import UserFactory
|
||||
from common.djangoapps.student.views.management import compose_activation_email
|
||||
from common.djangoapps.student.views.management import compose_activation_email, compose_and_send_activation_email
|
||||
|
||||
|
||||
class SendActivationEmailTestCase(TestCase):
|
||||
@@ -94,3 +95,26 @@ class SendActivationEmailTestCase(TestCase):
|
||||
assert mock_log.info.call_count == 0
|
||||
assert mock_log.error.call_count == 0
|
||||
assert mock_log.exception.call_count == 1
|
||||
|
||||
@mock.patch('common.djangoapps.student.tasks.log')
|
||||
@mock.patch('common.djangoapps.student.tasks.ace.send', mock.Mock(side_effect=ChannelError))
|
||||
@mock.patch('common.djangoapps.student.views.management.theming_helpers.get_current_site')
|
||||
@mock.patch('openedx.core.djangoapps.site_configuration.helpers.get_current_site_configuration')
|
||||
def test_from_address_in_send_email(self, mock_site_configuration, mock_get_current_site, mock_log):
|
||||
"""
|
||||
Tests that the "from_address" is pulled from the site configuration.
|
||||
"""
|
||||
site = SiteFactory.create()
|
||||
mock_get_current_site.return_value = site
|
||||
expected_from_email_address = 'test-no-reply@example.com'
|
||||
site_config = SiteConfigurationFactory.create(site=site, site_values={
|
||||
'ACTIVATION_EMAIL_FROM_ADDRESS': expected_from_email_address
|
||||
})
|
||||
mock_site_configuration.return_value = site_config
|
||||
|
||||
compose_and_send_activation_email(self.student, self.student.profile, self.student.registration)
|
||||
mock_log.exception.assert_called_with(
|
||||
'Unable to send activation email to user from "%s" to "%s"',
|
||||
expected_from_email_address,
|
||||
self.student.email,
|
||||
)
|
||||
|
||||
@@ -229,8 +229,11 @@ def compose_and_send_activation_email(user, profile, user_registration=None, red
|
||||
route_enabled = settings.FEATURES.get('REROUTE_ACTIVATION_EMAIL')
|
||||
|
||||
msg = compose_activation_email(user, user_registration, route_enabled, profile.name, redirect_url)
|
||||
from_address = configuration_helpers.get_value('ACTIVATION_EMAIL_FROM_ADDRESS') or (
|
||||
configuration_helpers.get_value('email_from_address', settings.DEFAULT_FROM_EMAIL)
|
||||
)
|
||||
|
||||
send_activation_email.delay(str(msg))
|
||||
send_activation_email.delay(str(msg), from_address)
|
||||
|
||||
|
||||
@login_required
|
||||
|
||||
Reference in New Issue
Block a user