'Test that the MongoDB cache is used in API to return grades'

def test_spoc_gradebook_mongo_calls(self):

    course = ItemFactory.create(parent_location=self.course.location, category='course', display_name='Test    course')
    students = []
    for i in xrange(20):
        username = ('user_%d' % i)
        student = UserFactory.create(username=username)
        CourseEnrollmentFactory.create(user=student, course_id=self.course.id)
        students.append(student)
    chapter = ItemFactory.create(parent=course, category='chapter', display_name='Chapter', publish_item=True, start=datetime.datetime(2015, 3, 1, tzinfo=UTC))
    sequential = ItemFactory.create(parent=chapter, category='sequential', display_name='Lesson', publish_item=True, start=datetime.datetime(2015, 3, 1, tzinfo=UTC), metadata={'graded': True, 'format': 'Homework'})
    vertical = ItemFactory.create(parent=sequential, category='vertical', display_name='Subsection', publish_item=True, start=datetime.datetime(2015, 4, 1, tzinfo=UTC))
    for i in xrange(10):
        problem = ItemFactory.create(category='problem', parent=vertical, display_name=('A    Problem    Block    %d' % i), weight=1, publish_item=False, metadata={'rerandomize': 'always'})
        for j in students:
            grade = (i % 2)
            StudentModuleFactory.create(grade=grade, max_grade=1, student=j, course_id=self.course.id, module_state_key=problem.location)
    url = reverse('spoc_gradebook', kwargs={'course_id': self.course.id})
    with check_mongo_calls(9):
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
