Skip to content
Snippets Groups Projects
Commit b99aeda6 authored by uzairr's avatar uzairr
Browse files

Add additional check for grade display on course banner.

PROD-1142
parent 0cb0867c
No related branches found
Tags release-2019-11-04-10.15
No related merge requests found
......@@ -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(
......
......@@ -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
......@@ -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':
......
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