feat: make LEARNING_MICROFRONTEND_URL site aware.

This commit is contained in:
Felipe Bermúdez-Mendoza
2025-11-05 21:49:23 +01:00
parent 7f8ba45f36
commit 7c42a600da
10 changed files with 202 additions and 17 deletions

View File

@@ -74,8 +74,10 @@ def send_ace_message(goal, session_id):
course_home_url = get_learning_mfe_home_url(course_key=goal.course_key, url_fragment='home')
goals_unsubscribe_url = f'{settings.LEARNING_MICROFRONTEND_URL}/goal-unsubscribe/{goal.unsubscribe_token}'
goals_unsubscribe_url = (
f'{configuration_helpers.get_value("LEARNING_MICROFRONTEND_URL", settings.LEARNING_MICROFRONTEND_URL)}'
f'/goal-unsubscribe/{goal.unsubscribe_token}'
)
language = get_user_preference(user, LANGUAGE_KEY)
# Code to allow displaying different banner images for different languages

View File

@@ -235,6 +235,42 @@ class TestGoalReminderEmailCommand(TestCase):
send_ace_message(goal, str(uuid.uuid4()))
assert mock_ace.called is value
def test_goals_unsubscribe_url_uses_site_config(self):
"""Test goals unsubscribe URL uses site-configured MFE base."""
goal = self.make_valid_goal()
with mock.patch('lms.djangoapps.course_goals.management.commands.goal_reminder_email.ace.send') as mock_ace, \
mock.patch(
'lms.djangoapps.course_goals.management.commands.goal_reminder_email.configuration_helpers.get_value',
return_value='https://learning.siteconf',
) as mock_get_value:
assert send_ace_message(goal, str(uuid.uuid4())) is True
assert mock_ace.call_count == 1
msg = mock_ace.call_args[0][0]
assert msg.context[
'goals_unsubscribe_url'
] == f'https://learning.siteconf/goal-unsubscribe/{goal.unsubscribe_token}'
mock_get_value.assert_any_call('LEARNING_MICROFRONTEND_URL', settings.LEARNING_MICROFRONTEND_URL)
def test_goals_unsubscribe_url_falls_back_to_settings(self):
"""Test goals unsubscribe URL falls back to settings when site config is absent."""
default_url = 'https://learning.default'
goal = self.make_valid_goal()
with override_settings(LEARNING_MICROFRONTEND_URL=default_url):
with mock.patch(
'lms.djangoapps.course_goals.management.commands.goal_reminder_email.ace.send',
) as mock_ace, \
mock.patch(
'lms.djangoapps.course_goals.management.commands.goal_reminder_email.configuration_helpers.get_value',
side_effect=lambda k, d: d,
) as mock_get_value:
assert send_ace_message(goal, str(uuid.uuid4())) is True
assert mock_ace.call_count == 1
msg = mock_ace.call_args[0][0]
assert msg.context['goals_unsubscribe_url'] == f'{default_url}/goal-unsubscribe/{goal.unsubscribe_token}'
mock_get_value.assert_any_call('LEARNING_MICROFRONTEND_URL', default_url)
class TestGoalReminderEmailSES(TestCase):
"""