Skip to content
Snippets Groups Projects
Commit 658b066c authored by Albert St. Aubin's avatar Albert St. Aubin
Browse files

Correcting bug where a user enrolled in a run that has left the upgrade

window

[LEARNER-6360]

Correcting bug where a user enrolled in a run that has left the upgrade
window could not leave their session.  Now if a user has an enrolled
session it will always be present
parent 45a0b549
Branches
Tags
No related merge requests found
......@@ -481,10 +481,10 @@ class TestSessionEntitlement(CatalogIntegrationMixin, TestCase):
"""
Test retrieval of visible session entitlements.
"""
catalog_course_runs = CourseRunFactory.create()
catalog_course = CourseFactory(course_runs=[catalog_course_runs])
catalog_course_run = CourseRunFactory.create()
catalog_course = CourseFactory(course_runs=[catalog_course_run])
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)
CourseModeFactory.create(mode_slug=CourseMode.VERIFIED, min_price=100, course_id=course_overview.id)
course_enrollment = CourseEnrollmentFactory(
......@@ -495,18 +495,23 @@ class TestSessionEntitlement(CatalogIntegrationMixin, TestCase):
)
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 = CourseFactory(course_runs=[catalog_course_runs])
catalog_course_run = CourseRunFactory.create()
catalog_course = CourseFactory(course_runs=[catalog_course_run])
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)
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(
user=self.user, course_id=unicode(course_overview.id), mode=CourseMode.VERIFIED
)
......@@ -514,6 +519,50 @@ class TestSessionEntitlement(CatalogIntegrationMixin, TestCase):
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)
self.assertEqual(session_entitlements, [])
......
......@@ -460,13 +460,15 @@ def get_fulfillable_course_runs_for_entitlement(entitlement, course_runs):
course_id=course_id
)
is_enrolled_in_mode = is_active and (user_enrollment_mode == entitlement.mode)
if (course_run.get('status') == COURSE_PUBLISHED and
is_course_run_entitlement_fulfillable(course_id, entitlement, search_time)):
if (is_enrolled_in_mode and
entitlement.enrollment_course_run and
course_id == entitlement.enrollment_course_run.course_id):
enrollable_sessions.append(course_run)
elif not is_enrolled_in_mode:
if (is_enrolled_in_mode and
entitlement.enrollment_course_run and
course_id == entitlement.enrollment_course_run.course_id):
# User is enrolled in the course so we should include it in the list of enrollable sessions always
# this will ensure it is available for the UI
enrollable_sessions.append(course_run)
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.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