Skip to content
Snippets Groups Projects
Unverified Commit 99eca7b2 authored by Albert (AJ) St. Aubin's avatar Albert (AJ) St. Aubin Committed by GitHub
Browse files

Merge pull request #18929 from edx/aj/LEARNER-6360

Correcting bug where a user enrolled in a run that has left the upgrade
parents 0c2396a3 658b066c
Branches
Tags release-2021-09-02-16.48
No related merge requests found
...@@ -481,10 +481,10 @@ class TestSessionEntitlement(CatalogIntegrationMixin, TestCase): ...@@ -481,10 +481,10 @@ class TestSessionEntitlement(CatalogIntegrationMixin, TestCase):
""" """
Test retrieval of visible session entitlements. Test retrieval of visible session entitlements.
""" """
catalog_course_runs = CourseRunFactory.create() catalog_course_run = CourseRunFactory.create()
catalog_course = CourseFactory(course_runs=[catalog_course_runs]) catalog_course = CourseFactory(course_runs=[catalog_course_run])
mock_get_edx_api_data.return_value = catalog_course mock_get_edx_api_data.return_value = catalog_course
course_key = CourseKey.from_string(catalog_course_runs.get('key')) course_key = CourseKey.from_string(catalog_course_run.get('key'))
course_overview = CourseOverviewFactory.create(id=course_key, start=self.tomorrow) course_overview = CourseOverviewFactory.create(id=course_key, start=self.tomorrow)
CourseModeFactory.create(mode_slug=CourseMode.VERIFIED, min_price=100, course_id=course_overview.id) CourseModeFactory.create(mode_slug=CourseMode.VERIFIED, min_price=100, course_id=course_overview.id)
course_enrollment = CourseEnrollmentFactory( course_enrollment = CourseEnrollmentFactory(
...@@ -495,18 +495,23 @@ class TestSessionEntitlement(CatalogIntegrationMixin, TestCase): ...@@ -495,18 +495,23 @@ class TestSessionEntitlement(CatalogIntegrationMixin, TestCase):
) )
session_entitlements = get_visible_sessions_for_entitlement(entitlement) session_entitlements = get_visible_sessions_for_entitlement(entitlement)
self.assertEqual(session_entitlements, [catalog_course_runs]) self.assertEqual(session_entitlements, [catalog_course_run])
def test_unpublished_sessions_for_entitlement(self, mock_get_edx_api_data): def test_get_visible_sessions_for_entitlement_expired_mode(self, mock_get_edx_api_data):
""" """
Test unpublished course runs are not part of visible session entitlements. Test retrieval of visible session entitlements.
""" """
catalog_course_runs = CourseRunFactory.create(status=COURSE_UNPUBLISHED) catalog_course_run = CourseRunFactory.create()
catalog_course = CourseFactory(course_runs=[catalog_course_runs]) catalog_course = CourseFactory(course_runs=[catalog_course_run])
mock_get_edx_api_data.return_value = catalog_course mock_get_edx_api_data.return_value = catalog_course
course_key = CourseKey.from_string(catalog_course_runs.get('key')) course_key = CourseKey.from_string(catalog_course_run.get('key'))
course_overview = CourseOverviewFactory.create(id=course_key, start=self.tomorrow) course_overview = CourseOverviewFactory.create(id=course_key, start=self.tomorrow)
CourseModeFactory.create(mode_slug=CourseMode.VERIFIED, min_price=100, course_id=course_overview.id) CourseModeFactory.create(
mode_slug=CourseMode.VERIFIED,
min_price=100,
course_id=course_overview.id,
expiration_datetime=now() - timedelta(days=1)
)
course_enrollment = CourseEnrollmentFactory( course_enrollment = CourseEnrollmentFactory(
user=self.user, course_id=unicode(course_overview.id), mode=CourseMode.VERIFIED user=self.user, course_id=unicode(course_overview.id), mode=CourseMode.VERIFIED
) )
...@@ -514,6 +519,50 @@ class TestSessionEntitlement(CatalogIntegrationMixin, TestCase): ...@@ -514,6 +519,50 @@ class TestSessionEntitlement(CatalogIntegrationMixin, TestCase):
user=self.user, enrollment_course_run=course_enrollment, mode=CourseMode.VERIFIED user=self.user, enrollment_course_run=course_enrollment, mode=CourseMode.VERIFIED
) )
session_entitlements = get_visible_sessions_for_entitlement(entitlement)
self.assertEqual(session_entitlements, [catalog_course_run])
def test_unpublished_sessions_for_entitlement_when_enrolled(self, mock_get_edx_api_data):
"""
Test unpublished course runs are part of visible session entitlements when the user
is enrolled.
"""
catalog_course_run = CourseRunFactory.create(status=COURSE_UNPUBLISHED)
catalog_course = CourseFactory(course_runs=[catalog_course_run])
mock_get_edx_api_data.return_value = catalog_course
course_key = CourseKey.from_string(catalog_course_run.get('key'))
course_overview = CourseOverviewFactory.create(id=course_key, start=self.tomorrow)
CourseModeFactory.create(
mode_slug=CourseMode.VERIFIED,
min_price=100,
course_id=course_overview.id,
expiration_datetime=now() - timedelta(days=1)
)
course_enrollment = CourseEnrollmentFactory(
user=self.user, course_id=unicode(course_overview.id), mode=CourseMode.VERIFIED
)
entitlement = CourseEntitlementFactory(
user=self.user, enrollment_course_run=course_enrollment, mode=CourseMode.VERIFIED
)
session_entitlements = get_visible_sessions_for_entitlement(entitlement)
self.assertEqual(session_entitlements, [catalog_course_run])
def test_unpublished_sessions_for_entitlement(self, mock_get_edx_api_data):
"""
Test unpublished course runs are not part of visible session entitlements when the user
is not enrolled.
"""
catalog_course_run = CourseRunFactory.create(status=COURSE_UNPUBLISHED)
catalog_course = CourseFactory(course_runs=[catalog_course_run])
mock_get_edx_api_data.return_value = catalog_course
course_key = CourseKey.from_string(catalog_course_run.get('key'))
course_overview = CourseOverviewFactory.create(id=course_key, start=self.tomorrow)
CourseModeFactory.create(mode_slug=CourseMode.VERIFIED, min_price=100, course_id=course_overview.id)
entitlement = CourseEntitlementFactory(
user=self.user, mode=CourseMode.VERIFIED
)
session_entitlements = get_visible_sessions_for_entitlement(entitlement) session_entitlements = get_visible_sessions_for_entitlement(entitlement)
self.assertEqual(session_entitlements, []) self.assertEqual(session_entitlements, [])
......
...@@ -460,13 +460,15 @@ def get_fulfillable_course_runs_for_entitlement(entitlement, course_runs): ...@@ -460,13 +460,15 @@ def get_fulfillable_course_runs_for_entitlement(entitlement, course_runs):
course_id=course_id course_id=course_id
) )
is_enrolled_in_mode = is_active and (user_enrollment_mode == entitlement.mode) is_enrolled_in_mode = is_active and (user_enrollment_mode == entitlement.mode)
if (course_run.get('status') == COURSE_PUBLISHED and if (is_enrolled_in_mode and
is_course_run_entitlement_fulfillable(course_id, entitlement, search_time)): entitlement.enrollment_course_run and
if (is_enrolled_in_mode and course_id == entitlement.enrollment_course_run.course_id):
entitlement.enrollment_course_run and # User is enrolled in the course so we should include it in the list of enrollable sessions always
course_id == entitlement.enrollment_course_run.course_id): # this will ensure it is available for the UI
enrollable_sessions.append(course_run) enrollable_sessions.append(course_run)
elif not is_enrolled_in_mode: elif (course_run.get('status') == COURSE_PUBLISHED and not
is_enrolled_in_mode and
is_course_run_entitlement_fulfillable(course_id, entitlement, search_time)):
enrollable_sessions.append(course_run) enrollable_sessions.append(course_run)
enrollable_sessions.sort(key=lambda session: session.get('start')) enrollable_sessions.sort(key=lambda session: session.get('start'))
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment