Skip to content
Snippets Groups Projects
Unverified Commit e1c6801d authored by Diane Kaplan's avatar Diane Kaplan Committed by GitHub
Browse files

Hide financial assistance link for two cases

parent 47d15ff1
No related merge requests found
......@@ -114,11 +114,18 @@ class FinancialAssistanceTool(CourseTool):
if not request.user or not CourseEnrollment.is_enrolled(request.user, course_key):
return False
# hide if there's a course_upgrade_enrollment in the past
enrollment = CourseEnrollment.get_enrollment(request.user, course_key)
# hide if we're no longer in an upsell mode (already upgraded)
if enrollment.mode not in CourseMode.UPSELL_TO_VERIFIED_MODES:
return False
# hide if there's no course_upgrade_deadline, or one with a value in the past
if enrollment.course_upgrade_deadline:
if now > enrollment.course_upgrade_deadline:
return False
else:
return False
return bool(course_overview.eligible_for_financial_aid)
......
......@@ -137,14 +137,31 @@ class FinancialAssistanceToolTest(SharedModuleStoreTestCase):
self.request = RequestFactory().request()
crum.set_current_request(self.request)
self.addCleanup(crum.set_current_request, None)
# baseline course enrollment, future upgrade deadline
self.enrollment = CourseEnrollmentFactory(
course_id=self.course.id,
mode=CourseMode.AUDIT,
course=self.course_overview,
)
self.request.user = self.enrollment.user
self.enrollment.course_upgrade_deadline = self.now - datetime.timedelta(days=1)
self.enrollment.save()
# enrollment where learner has upgraded
self.enrollment_upgraded = CourseEnrollmentFactory(
course_id=self.course.id,
mode=CourseMode.VERIFIED,
course=self.course_overview,
)
# course enrollment for mock: upgrade deadline in the past
self.enrollment_deadline_past = self.enrollment
self.enrollment_deadline_past.course_upgrade_deadline = self.now - datetime.timedelta(days=1)
self.enrollment_deadline_past.save()
# course enrollment for mock: no upgrade deadline
self.enrollment_deadline_missing = self.enrollment
self.enrollment_deadline_missing.course_upgrade_deadline = None
self.enrollment_deadline_missing.save()
def test_tool_visible_logged_in(self):
self.course_financial_mode.save()
......@@ -155,7 +172,7 @@ class FinancialAssistanceToolTest(SharedModuleStoreTestCase):
self.course_overview.save()
self.assertFalse(FinancialAssistanceTool().is_enabled(self.request, self.course_overview.id))
def test_tool_not_visible_when_user_not_unrolled(self):
def test_tool_not_visible_when_user_not_enrolled(self):
self.course_financial_mode.save()
self.request.user = None
self.assertFalse(FinancialAssistanceTool().is_enabled(self.request, self.course.id))
......@@ -163,10 +180,23 @@ class FinancialAssistanceToolTest(SharedModuleStoreTestCase):
# mock the response from get_enrollment to use enrollment with course_upgrade_deadline in the past
@patch('lms.djangoapps.courseware.course_tools.CourseEnrollment.get_enrollment')
def test_not_visible_when_upgrade_deadline_has_passed(self, get_enrollment_mock):
get_enrollment_mock.return_value = self.enrollment
get_enrollment_mock.return_value = self.enrollment_deadline_past
self.assertFalse(FinancialAssistanceTool().is_enabled(self.request, self.course.id))
# mock the response from get_enrollment to use enrollment with no course_upgrade_deadline
@patch('lms.djangoapps.courseware.course_tools.CourseEnrollment.get_enrollment')
def test_not_visible_when_no_upgrade_deadline(self, get_enrollment_mock):
get_enrollment_mock.return_value = self.enrollment_deadline_missing
self.assertFalse(FinancialAssistanceTool().is_enabled(self.request, self.course.id))
def test_tool_not_visible_when_end_date_passed(self):
self.course_overview.end_date = self.now - datetime.timedelta(days=30)
self.course_overview.save()
self.assertFalse(FinancialAssistanceTool().is_enabled(self.request, self.course_overview.id))
# mock the response from get_enrollment to use enrollment where learner upgraded
@patch('lms.djangoapps.courseware.course_tools.CourseEnrollment.get_enrollment')
def test_tool_not_visible_when_already_upgraded(self, get_enrollment_mock):
self.course_financial_mode.save()
get_enrollment_mock.return_value = self.enrollment_upgraded
self.assertFalse(FinancialAssistanceTool().is_enabled(self.request, self.course.id))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment