diff --git a/common/djangoapps/student/tests/test_views.py b/common/djangoapps/student/tests/test_views.py index f9da759552cb750cce5da9c4579b8de352012c09..1e9ecc2360fc4b39852b587de53b85d3a4e46c61 100644 --- a/common/djangoapps/student/tests/test_views.py +++ b/common/djangoapps/student/tests/test_views.py @@ -222,32 +222,38 @@ class StudentDashboardTests(SharedModuleStoreTestCase, MilestonesTestCaseMixin, response = self.client.get(self.path) self.assertRedirects(response, reverse('account_settings')) - def test_grade_doesnt_appears_before_course_end_date(self): + def test_grade_appears_before_course_end_date(self): """ Verify that learners are not able to see their final grade before the end of course in the learner dashboard """ - self.course = CourseFactory.create(end=self.TOMORROW, emit_signals=True) + self.course_key = CourseKey.from_string('course-v1:edX+DemoX+Demo_Course') + self.course = CourseOverviewFactory.create(id=self.course_key, end_date=self.TOMORROW, + certificate_available_date=self.THREE_YEARS_AGO, + lowest_passing_grade=0.3) self.course_enrollment = CourseEnrollmentFactory(course_id=self.course.id, user=self.user) GeneratedCertificateFactory(status='notpassing', course_id=self.course.id, user=self.user, grade=0.45) response = self.client.get(reverse('dashboard')) # The final grade does not appear before the course has ended - self.assertNotContains(response, 'Your final grade:') - self.assertNotContains(response, '<span class="grade-value">45%</span>') + self.assertContains(response, 'Your final grade:') + self.assertContains(response, '<span class="grade-value">45%</span>') - def test_grade_appears_after_course_has_ended(self): + def test_grade_not_appears_before_cert_available_date(self): """ Verify that learners are able to see their final grade of the course in the learner dashboard after the course had ended """ - self.course = CourseFactory.create(end=self.THREE_YEARS_AGO, emit_signals=True) + self.course_key = CourseKey.from_string('course-v1:edX+DemoX+Demo_Course') + self.course = CourseOverviewFactory.create(id=self.course_key, end_date=self.THREE_YEARS_AGO, + certificate_available_date=self.TOMORROW, + lowest_passing_grade=0.3) self.course_enrollment = CourseEnrollmentFactory(course_id=self.course.id, user=self.user) GeneratedCertificateFactory(status='notpassing', course_id=self.course.id, user=self.user, grade=0.45) response = self.client.get(reverse('dashboard')) - self.assertContains(response, 'Your final grade:') - self.assertContains(response, '<span class="grade-value">45%</span>') + self.assertNotContains(response, 'Your final grade:') + self.assertNotContains(response, '<span class="grade-value">45%</span>') @patch.multiple('django.conf.settings', **MOCK_SETTINGS) @ddt.data( diff --git a/common/djangoapps/util/course.py b/common/djangoapps/util/course.py index a7a491c675b871507391900201c296f50b3c87e5..4ff94b7dd365d3dd14e664b5be33a28b1987b2ff 100644 --- a/common/djangoapps/util/course.py +++ b/common/djangoapps/util/course.py @@ -76,7 +76,15 @@ def has_certificates_enabled(course): return course.cert_html_view_enabled -def should_display_grade(end_date): - if end_date and end_date < now().replace(hour=0, minute=0, second=0, microsecond=0): - return True - return False +def should_display_grade(course_overview): + """ + Returns True or False depending upon either certificate available date + or course-end-date + """ + course_end_date = course_overview.end_date + cert_available_date = course_overview.certificate_available_date + current_date = now().replace(hour=0, minute=0, second=0, microsecond=0) + if cert_available_date: + return cert_available_date < current_date + + return course_end_date and course_end_date < current_date diff --git a/lms/templates/dashboard/_dashboard_certificate_information.html b/lms/templates/dashboard/_dashboard_certificate_information.html index 1d8d29cc8814b44345df2bb73da44863f4acb345..62f4b81bb8689b7aeb9c21b2ceee883ade1cadce 100644 --- a/lms/templates/dashboard/_dashboard_certificate_information.html +++ b/lms/templates/dashboard/_dashboard_certificate_information.html @@ -46,9 +46,14 @@ else: % else: <div class="message message-status ${status_css_class} is-shown"> <p class="message-copy"> - % if should_display_grade(course_overview.end): + % if should_display_grade(course_overview): ${_("Your final grade:")} <span class="grade-value">${"{0:.0f}%".format(float(cert_status['grade'])*100)}</span>. + % elif course_overview.certificate_available_date: + <% + cert_available_date = course_overview.certificate_available_date.strftime('%Y-%m-%d') + %> + ${_("Grades will be finalized on {cert_available_date}".format(cert_available_date=cert_available_date))} % endif % if cert_status['status'] == 'notpassing': % if enrollment.mode != 'audit':