'Check that the StudentModule state contains the expected values.
The student module is found for the test course, given the `username` and problem `descriptor`.
Values checked include the number of attempts, the score, and the max score for a problem.'

def check_state(self, user, descriptor, expected_score, expected_max_score, expected_attempts=1):

    module = self.get_student_module(user.username, descriptor)
    self.assertEqual(module.grade, expected_score)
    self.assertEqual(module.max_grade, expected_max_score)
    state = json.loads(module.state)
    attempts = state['attempts']
    self.assertEqual(attempts, expected_attempts)
    if (attempts > 0):
        self.assertIn('correct_map', state)
        self.assertIn('student_answers', state)
        self.assertGreater(len(state['correct_map']), 0)
        self.assertGreater(len(state['student_answers']), 0)
    expected_subsection_grade = expected_score
    course_grade = CourseGradeFactory().create(user, self.course)
    self.assertEquals(course_grade.graded_subsections_by_format['Homework'][self.problem_section.location].graded_total.earned, expected_subsection_grade)
