feat: Add logic for happy and non-happy path upgrade msg in learner dashboard (#30368)
REV-2466
This commit is contained in:
@@ -55,6 +55,12 @@ ONE_WEEK_AGO = now() - timedelta(weeks=1)
|
||||
THREE_YEARS_FROM_NOW = now() + timedelta(days=(365 * 3))
|
||||
THREE_YEARS_AGO = now() - timedelta(days=(365 * 3))
|
||||
|
||||
# Name of the method to mock for Content Type Gating.
|
||||
GATING_METHOD_NAME = 'openedx.features.content_type_gating.models.ContentTypeGatingConfig.enabled_for_enrollment'
|
||||
|
||||
# Name of the method to mock for Course Duration Limits.
|
||||
CDL_METHOD_NAME = 'openedx.features.course_duration_limits.models.CourseDurationLimitConfig.enabled_for_enrollment'
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
|
||||
@@ -953,6 +959,46 @@ class StudentDashboardTests(SharedModuleStoreTestCase, MilestonesTestCaseMixin,
|
||||
else:
|
||||
self.assertNotContains(response, html_fragment)
|
||||
|
||||
@ddt.data(
|
||||
# gated_content_on, course_duration_limits_on, upgrade_message
|
||||
(True, True, 'Upgrade to get full access to the course material'),
|
||||
(True, False, 'Upgrade to earn'),
|
||||
(False, True, 'Upgrade to earn'),
|
||||
(False, False, 'Upgrade to earn'),
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_happy_path_upgrade_message(
|
||||
self,
|
||||
gated_content_on,
|
||||
course_duration_limits_on,
|
||||
upgrade_message
|
||||
):
|
||||
"""
|
||||
Upgrade message should be different for a course depending if it's happy or non-happy path.
|
||||
Happy path requirements:
|
||||
- Learner can upgrade (verified_mode)
|
||||
- FBE is on (has an audit_access_deadline and is able to see gated_content)
|
||||
"""
|
||||
with patch.object(EcommerceService, 'is_enabled', return_value=True):
|
||||
course = CourseFactory.create()
|
||||
CourseEnrollmentFactory.create(
|
||||
user=self.user,
|
||||
course_id=course.id
|
||||
)
|
||||
|
||||
CourseModeFactory.create(
|
||||
course_id=course.id,
|
||||
mode_slug='verified',
|
||||
mode_display_name='Verified',
|
||||
min_price=149,
|
||||
sku='abcdef',
|
||||
)
|
||||
|
||||
with patch(GATING_METHOD_NAME, return_value=gated_content_on):
|
||||
with patch(CDL_METHOD_NAME, return_value=course_duration_limits_on):
|
||||
response = self.client.get(reverse('dashboard'))
|
||||
self.assertContains(response, upgrade_message)
|
||||
|
||||
|
||||
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Tests only valid for the LMS')
|
||||
@unittest.skipUnless(settings.FEATURES.get("ENABLE_NOTICES"), 'Notices plugin is not enabled')
|
||||
|
||||
@@ -44,6 +44,8 @@ from openedx.core.djangoapps.site_configuration import helpers as configuration_
|
||||
from openedx.core.djangoapps.user_api.accounts.utils import is_secondary_email_feature_enabled
|
||||
from openedx.core.djangoapps.util.maintenance_banner import add_maintenance_banner
|
||||
from openedx.core.djangolib.markup import HTML, Text
|
||||
from openedx.features.content_type_gating.models import ContentTypeGatingConfig
|
||||
from openedx.features.course_duration_limits.access import get_user_course_duration, get_user_course_expiration_date
|
||||
from openedx.features.enterprise_support.api import (
|
||||
get_dashboard_consent_notification,
|
||||
get_enterprise_learner_portal_context,
|
||||
@@ -762,6 +764,18 @@ def student_dashboard(request): # lint-amnesty, pylint: disable=too-many-statem
|
||||
|
||||
show_account_activation_popup = request.COOKIES.get(settings.SHOW_ACTIVATE_CTA_POPUP_COOKIE_NAME, None)
|
||||
|
||||
fbe_status_list = []
|
||||
for enrollment in course_enrollments:
|
||||
course_key = CourseKey.from_string(str(enrollment.course_id))
|
||||
gated_content = ContentTypeGatingConfig.enabled_for_enrollment(
|
||||
user=request.user,
|
||||
course_key=course_key
|
||||
)
|
||||
duration = get_user_course_duration(enrollment.user, enrollment.course)
|
||||
deadline = duration and get_user_course_expiration_date(request.user, enrollment.course)
|
||||
fbe_is_on = bool(deadline and gated_content)
|
||||
fbe_status_list.append(fbe_is_on)
|
||||
|
||||
context = {
|
||||
'urls': urls,
|
||||
'programs_data': programs_data,
|
||||
@@ -808,6 +822,7 @@ def student_dashboard(request): # lint-amnesty, pylint: disable=too-many-statem
|
||||
'display_sidebar_account_activation_message': not(user.is_active or hide_dashboard_courses_until_activated),
|
||||
'display_dashboard_courses': (user.is_active or not hide_dashboard_courses_until_activated),
|
||||
'empty_dashboard_message': empty_dashboard_message,
|
||||
'fbe_status_list': fbe_status_list,
|
||||
'recovery_email_message': recovery_email_message,
|
||||
'recovery_email_activation_message': recovery_email_activation_message,
|
||||
'show_load_all_courses_link': show_load_all_courses_link(user, course_limit, course_enrollments),
|
||||
|
||||
Reference in New Issue
Block a user