chore: address comments by Feanil and fix pycodestyle.

This commit is contained in:
Felipe Bermúdez-Mendoza
2025-11-06 18:22:33 +01:00
parent 450f881308
commit 6b821a6a5f
2 changed files with 27 additions and 26 deletions

View File

@@ -238,12 +238,12 @@ class TestGoalReminderEmailCommand(TestCase):
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(
with mock.patch('lms.djangoapps.course_goals.management.commands.goal_reminder_email.ace.send') as mock_ace:
with 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 send_ace_message(goal, str(uuid.uuid4())) is True
assert mock_ace.call_count == 1
msg = mock_ace.call_args[0][0]
@@ -259,12 +259,15 @@ class TestGoalReminderEmailCommand(TestCase):
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
) as mock_ace:
with 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]

View File

@@ -22,19 +22,6 @@ from openedx.core.djangoapps.site_configuration import helpers as configuration_
User = get_user_model()
def _learning_mfe_base_url() -> str:
"""
Return the site-aware base URL for the Learning MFE.
Reads `LEARNING_MICROFRONTEND_URL` from Site Configuration when available;
otherwise falls back to `settings.LEARNING_MICROFRONTEND_URL`.
"""
return configuration_helpers.get_value(
'LEARNING_MICROFRONTEND_URL',
settings.LEARNING_MICROFRONTEND_URL,
)
def get_courseware_url(
usage_key: UsageKey,
request: Optional[HttpRequest] = None,
@@ -139,7 +126,11 @@ def make_learning_mfe_courseware_url(
strings. They're only ever used to concatenate a URL string.
`params` is an optional QueryDict object (e.g. request.GET)
"""
mfe_link = f'{_learning_mfe_base_url()}/course/{course_key}'
learning_microfrontend_url = configuration_helpers.get_value(
'LEARNING_MICROFRONTEND_URL',
settings.LEARNING_MICROFRONTEND_URL,
)
mfe_link = f'{learning_microfrontend_url}/course/{course_key}'
get_params = params.copy() if params else None
if preview:
@@ -149,7 +140,7 @@ def make_learning_mfe_courseware_url(
get_params = None
if (unit_key or sequence_key):
mfe_link = f'{_learning_mfe_base_url()}/preview/course/{course_key}'
mfe_link = f'{learning_microfrontend_url}/preview/course/{course_key}'
if sequence_key:
mfe_link += f'/{sequence_key}'
@@ -179,7 +170,11 @@ def get_learning_mfe_home_url(
`url_fragment` is an optional string.
`params` is an optional QueryDict object (e.g. request.GET)
"""
mfe_link = f'{_learning_mfe_base_url()}/course/{course_key}'
learning_microfrontend_url = configuration_helpers.get_value(
'LEARNING_MICROFRONTEND_URL',
settings.LEARNING_MICROFRONTEND_URL,
)
mfe_link = f'{learning_microfrontend_url}/course/{course_key}'
if url_fragment:
mfe_link += f'/{url_fragment}'
@@ -194,7 +189,10 @@ def is_request_from_learning_mfe(request: HttpRequest):
"""
Returns whether the given request was made by the frontend-app-learning MFE.
"""
url_str = _learning_mfe_base_url()
url_str = configuration_helpers.get_value(
'LEARNING_MICROFRONTEND_URL',
settings.LEARNING_MICROFRONTEND_URL,
)
if not url_str:
return False