From 963ec44826648ecbdf22981314ed4bcb2516b90c Mon Sep 17 00:00:00 2001 From: Jolyon Bloomfield Date: Thu, 28 Mar 2019 23:07:00 -0700 Subject: [PATCH] Hiding overall grades for a sequential when problem scores are hidden --- lms/djangoapps/courseware/tests/test_views.py | 34 +++++++++++++------ lms/templates/courseware/progress.html | 4 +-- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index 623ee0ec65..a020a5af79 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -1995,34 +1995,48 @@ class ProgressPageShowCorrectnessTests(ProgressPageBaseTests): Ensures that grades and scores are shown or not shown on the progress page as required. """ - expected_score = "
{score}/{max_score}
".format(score=score, max_score=max_score) + expected_score = u"
{score}/{max_score}
".format(score=score, max_score=max_score) percent = score / float(max_score) + # Test individual problem scores if show_grades: # If grades are shown, we should be able to see the current problem scores. - self.assertIn(expected_score, response.content) + self.assertIn(expected_score, response.content.decode("utf-8")) if graded: - expected_summary_text = "Problem Scores:" + expected_summary_text = u"Problem Scores:" else: - expected_summary_text = "Practice Scores:" + expected_summary_text = u"Practice Scores:" else: # If grades are hidden, we should not be able to see the current problem scores. - self.assertNotIn(expected_score, response.content) + self.assertNotIn(expected_score, response.content.decode("utf-8")) if graded: - expected_summary_text = "Problem scores are hidden" + expected_summary_text = u"Problem scores are hidden" else: - expected_summary_text = "Practice scores are hidden" + expected_summary_text = u"Practice scores are hidden" if show_correctness == ShowCorrectness.PAST_DUE and due_date: - expected_summary_text += ' until the due date.' + expected_summary_text += u' until the due date.' else: - expected_summary_text += '.' + expected_summary_text += u'.' # Ensure that expected text is present - self.assertIn(expected_summary_text, response.content) + self.assertIn(expected_summary_text, response.content.decode("utf-8")) + + # Test overall sequential score + if graded and max_score > 0: + percentageString = "{0:.0%}".format(percent) if max_score > 0 else "" + template = u' ({0:.3n}/{1:.3n}) {2}' + expected_grade_summary = template.format(float(score), + float(max_score), + percentageString) + + if show_grades: + self.assertIn(expected_grade_summary, response.content.decode("utf-8")) + else: + self.assertNotIn(expected_grade_summary, response.content.decode("utf-8")) @ddt.data( ('', None, False), diff --git a/lms/templates/courseware/progress.html b/lms/templates/courseware/progress.html index fc06cf75a2..289fdcfd07 100644 --- a/lms/templates/courseware/progress.html +++ b/lms/templates/courseware/progress.html @@ -177,13 +177,13 @@ username = get_enterprise_learner_generic_name(request) or student.username

${ section.display_name} - %if total > 0 or earned > 0: + %if (total > 0 or earned > 0) and section.show_grades(staff_access): ${_("{earned} of {total} possible points").format(earned='{:.3n}'.format(float(earned)), total='{:.3n}'.format(float(total)))} %endif - %if total > 0 or earned > 0: + %if (total > 0 or earned > 0) and section.show_grades(staff_access): ${"({0:.3n}/{1:.3n}) {2}".format( float(earned), float(total), percentageString )} %endif