Commit cc6f8be8 by Alex Dusenbery Committed by Alex Dusenbery

EDUCATOR-1029 | More defensive version of ZeroSubsectionGrade.problem_scores

parent 19a5aa7d
...@@ -81,9 +81,11 @@ class ZeroSubsectionGrade(SubsectionGradeBase): ...@@ -81,9 +81,11 @@ class ZeroSubsectionGrade(SubsectionGradeBase):
): ):
block = self.course_data.structure[block_key] block = self.course_data.structure[block_key]
if getattr(block, 'has_score', False): if getattr(block, 'has_score', False):
locations[block_key] = get_score( problem_score = get_score(
submissions_scores={}, csm_scores={}, persisted_block=None, block=block, submissions_scores={}, csm_scores={}, persisted_block=None, block=block,
) )
if problem_score is not None:
locations[block_key] = problem_score
return locations return locations
......
...@@ -367,15 +367,18 @@ class TestSubsectionGradeFactory(ProblemSubmissionTestMixin, GradeTestBase): ...@@ -367,15 +367,18 @@ class TestSubsectionGradeFactory(ProblemSubmissionTestMixin, GradeTestBase):
self.assertEqual(mock_read_saved_grade.called, feature_flag and course_setting) self.assertEqual(mock_read_saved_grade.called, feature_flag and course_setting)
@ddt.ddt
class ZeroGradeTest(GradeTestBase): class ZeroGradeTest(GradeTestBase):
""" """
Tests ZeroCourseGrade (and, implicitly, ZeroSubsectionGrade) Tests ZeroCourseGrade (and, implicitly, ZeroSubsectionGrade)
functionality. functionality.
""" """
def test_zero(self): @ddt.data(True, False)
def test_zero(self, assume_zero_enabled):
""" """
Creates a ZeroCourseGrade and ensures it's empty. Creates a ZeroCourseGrade and ensures it's empty.
""" """
with waffle().override(ASSUME_ZERO_GRADE_IF_ABSENT, active=assume_zero_enabled):
course_data = CourseData(self.request.user, structure=self.course_structure) course_data = CourseData(self.request.user, structure=self.course_structure)
chapter_grades = ZeroCourseGrade(self.request.user, course_data).chapter_grades chapter_grades = ZeroCourseGrade(self.request.user, course_data).chapter_grades
for chapter in chapter_grades: for chapter in chapter_grades:
...@@ -385,6 +388,20 @@ class ZeroGradeTest(GradeTestBase): ...@@ -385,6 +388,20 @@ class ZeroGradeTest(GradeTestBase):
self.assertEqual(score.first_attempted, None) self.assertEqual(score.first_attempted, None)
self.assertEqual(section.all_total.earned, 0) self.assertEqual(section.all_total.earned, 0)
@ddt.data(True, False)
def test_zero_null_scores(self, assume_zero_enabled):
"""
Creates a zero course grade and ensures that null scores aren't included in the section problem scores.
"""
with waffle().override(ASSUME_ZERO_GRADE_IF_ABSENT, active=assume_zero_enabled):
with patch('lms.djangoapps.grades.new.subsection_grade.get_score', return_value=None):
course_data = CourseData(self.request.user, structure=self.course_structure)
chapter_grades = ZeroCourseGrade(self.request.user, course_data).chapter_grades
for chapter in chapter_grades:
self.assertNotEqual({}, chapter_grades[chapter]['sections'])
for section in chapter_grades[chapter]['sections']:
self.assertEqual({}, section.problem_scores)
class SubsectionGradeTest(GradeTestBase): class SubsectionGradeTest(GradeTestBase):
""" """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment