'Verify that saved student state is loaded for xblocks rendered in the index view.'

@XBlock.register_temp_plugin(ViewCheckerBlock, 'view_checker')
@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
def test_student_state(self, default_store):

    user = UserFactory()
    with modulestore().default_store(default_store):
        course = CourseFactory.create()
        chapter = ItemFactory.create(parent=course, category='chapter')
        section = ItemFactory.create(parent=chapter, category='view_checker', display_name='Sequence    Checker')
        vertical = ItemFactory.create(parent=section, category='view_checker', display_name='Vertical    Checker')
        block = ItemFactory.create(parent=vertical, category='view_checker', display_name='Block    Checker')
    for item in (section, vertical, block):
        StudentModuleFactory.create(student=user, course_id=course.id, module_state_key=item.scope_ids.usage_id, state=json.dumps({'state': unicode(item.scope_ids.usage_id)}))
    CourseEnrollmentFactory(user=user, course_id=course.id)
    self.assertTrue(self.client.login(username=user.username, password='test'))
    response = self.client.get(reverse('courseware_section', kwargs={'course_id': unicode(course.id), 'chapter': chapter.url_name, 'section': section.url_name}))
    self.assertEquals(response.content.count('ViewCheckerPassed'), 3)
