'Tests retrieving a subsection grade before and after losing access
to a block in the subsection.'

def test_subsection_access_changed(self):

    self.submit_question_answer('p1', {'2_1': 'choice_choice_2'})
    self.submit_question_answer('p2', {'2_1': 'choice_choice_2'})
    course_structure = get_course_blocks(self.request.user, self.course.location)
    subsection_grade_factory = SubsectionGradeFactory(self.request.user, self.course, course_structure)
    grade = subsection_grade_factory.create(self.sequence, read_only=True)
    self.assertEqual(grade.graded_total.earned, 4.0)
    self.assertEqual(grade.graded_total.possible, 4.0)
    with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred):
        problem_2 = self.store.get_item(self.problem_2.location)
        problem_2.visible_to_staff_only = True
        self.store.update_item(problem_2, self.instructor.id)
        self.store.publish(self.course.location, self.instructor.id)
    course_structure = get_course_blocks(self.student, self.course.location)
    self.assertNotIn(problem_2.location, course_structure)
    subsection_grade_factory = SubsectionGradeFactory(self.student, self.course, course_structure)
    grade = subsection_grade_factory.create(self.sequence, read_only=True)
    self.assertEqual(grade.graded_total.earned, 4.0)
    self.assertEqual(grade.graded_total.possible, 4.0)
