diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index d6b7bc1e51..2bf010404e 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -789,6 +789,30 @@ class ViewsTestCase(ModuleStoreTestCase): self.assertNotIn(str(course.id), response.content) + @patch.object(CourseOverview, 'load_from_module_store', return_value=None) + def test_financial_assistance_form_missing_course_overview(self, _mock_course_overview): + """ + Verify that learners can not get financial aid for the courses with no + course overview. + """ + # Create course + course = CourseFactory.create().id + + # Create Course Modes + CourseModeFactory.create(mode_slug=CourseMode.AUDIT, course_id=course) + CourseModeFactory.create(mode_slug=CourseMode.VERIFIED, course_id=course) + + # Enroll user in the course + enrollment = CourseEnrollmentFactory(course_id=course, user=self.user, mode=CourseMode.AUDIT) + + self.assertEqual(enrollment.course_overview, None) + + url = reverse('financial_assistance_form') + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + + self.assertNotIn(str(course), response.content) + def test_financial_assistance_form(self): """Verify that learner can get the financial aid for the course in which he/she is enrolled in audit mode whereas the course provide verified mode. diff --git a/lms/djangoapps/courseware/views/views.py b/lms/djangoapps/courseware/views/views.py index 009499e661..5d7c6c8876 100644 --- a/lms/djangoapps/courseware/views/views.py +++ b/lms/djangoapps/courseware/views/views.py @@ -1599,6 +1599,7 @@ def get_financial_aid_courses(user): for enrollment in CourseEnrollment.enrollments_for_user(user).order_by('-created'): if enrollment.mode != CourseMode.VERIFIED and \ + enrollment.course_overview and \ enrollment.course_overview.eligible_for_financial_aid and \ CourseMode.objects.filter( Q(_expiration_datetime__isnull=True) | Q(_expiration_datetime__gt=datetime.now(UTC())),