fix: course progress url returned based on course_home_mfe_progress_tab_is_active
This commit is contained in:
@@ -15,6 +15,7 @@ from openedx_filters.learning.filters import CourseEnrollmentAPIRenderStarted, C
|
||||
from common.djangoapps.course_modes.models import CourseMode
|
||||
from openedx.features.course_experience import course_home_url
|
||||
from xmodule.data import CertificatesDisplayBehaviors
|
||||
from lms.djangoapps.learner_home.utils import course_progress_url
|
||||
|
||||
|
||||
class LiteralField(serializers.Field):
|
||||
@@ -116,7 +117,7 @@ class CourseRunSerializer(serializers.Serializer):
|
||||
return course_home_url(instance.course_id)
|
||||
|
||||
def get_progressUrl(self, instance):
|
||||
return reverse("progress", kwargs={"course_id": instance.course_id})
|
||||
return course_progress_url(instance.course_id)
|
||||
|
||||
def get_unenrollUrl(self, instance):
|
||||
return reverse("course_run_refund_status", args=[instance.course_id])
|
||||
|
||||
@@ -51,7 +51,7 @@ from lms.djangoapps.learner_home.serializers import (
|
||||
SuggestedCourseSerializer,
|
||||
UnfulfilledEntitlementSerializer,
|
||||
)
|
||||
|
||||
from lms.djangoapps.learner_home.utils import course_progress_url
|
||||
from lms.djangoapps.learner_home.test_utils import (
|
||||
datetime_to_django_format,
|
||||
random_bool,
|
||||
@@ -224,6 +224,30 @@ class TestCourseRunSerializer(LearnerDashboardBaseTest):
|
||||
# Then the resumeUrl is None, which is allowed
|
||||
self.assertIsNone(output_data["resumeUrl"])
|
||||
|
||||
def is_progress_url_matching_course_home_mfe_progress_tab_is_active(self):
|
||||
"""
|
||||
Compares the progress URL generated by CourseRunSerializer to the expected progress URL.
|
||||
|
||||
:return: True if the generated progress URL matches the expected, False otherwise.
|
||||
"""
|
||||
input_data = self.create_test_enrollment()
|
||||
input_context = self.create_test_context(input_data.course.id)
|
||||
output_data = CourseRunSerializer(input_data, context=input_context).data
|
||||
return output_data['progressUrl'] == course_progress_url(input_data.course.id)
|
||||
|
||||
@mock.patch('lms.djangoapps.learner_home.utils.course_home_mfe_progress_tab_is_active')
|
||||
def test_progress_url(self, mock_course_home_mfe_progress_tab_is_active):
|
||||
"""
|
||||
Tests the progress URL generated by the CourseRunSerializer. When course_home_mfe_progress_tab_is_active
|
||||
is true, the generated progress URL must point to the progress page of the course home (learning) MFE.
|
||||
Otherwise, it must point to the legacy progress page.
|
||||
"""
|
||||
mock_course_home_mfe_progress_tab_is_active.return_value = True
|
||||
self.assertTrue(self.is_progress_url_matching_course_home_mfe_progress_tab_is_active())
|
||||
|
||||
mock_course_home_mfe_progress_tab_is_active.return_value = False
|
||||
self.assertTrue(self.is_progress_url_matching_course_home_mfe_progress_tab_is_active())
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TestCoursewareAccessSerializer(LearnerDashboardBaseTest):
|
||||
|
||||
@@ -4,6 +4,7 @@ Additional utilities for Learner Home
|
||||
|
||||
import logging
|
||||
|
||||
from django.urls import reverse
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.exceptions import MultipleObjectsReturned
|
||||
from rest_framework.exceptions import PermissionDenied, NotFound
|
||||
@@ -11,6 +12,8 @@ from rest_framework.exceptions import PermissionDenied, NotFound
|
||||
from common.djangoapps.student.models import (
|
||||
get_user_by_username_or_email,
|
||||
)
|
||||
from lms.djangoapps.course_home_api.toggles import course_home_mfe_progress_tab_is_active
|
||||
from openedx.features.course_experience.url_helpers import get_learning_mfe_home_url
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
User = get_user_model()
|
||||
@@ -54,3 +57,16 @@ def get_masquerade_user(request):
|
||||
)
|
||||
log.info(success_msg)
|
||||
return masquerade_user
|
||||
|
||||
|
||||
def course_progress_url(course_key) -> str:
|
||||
"""
|
||||
Returns the course progress page's URL for the current user.
|
||||
|
||||
:param course_key: The course key for which the home url is being requested.
|
||||
|
||||
:return: The course progress page URL.
|
||||
"""
|
||||
if course_home_mfe_progress_tab_is_active(course_key):
|
||||
return get_learning_mfe_home_url(course_key, url_fragment='progress')
|
||||
return reverse('progress', kwargs={'course_id': course_key})
|
||||
|
||||
Reference in New Issue
Block a user