'Test when course has content library section.
First test user can\'t see any content library section,
and after that mock response from MySQL db.
Check user can see mocked sections in content library.'

def test_content_library(self):

    raw_block_structure = get_course_blocks(self.user, self.course.location, transformers=BlockStructureTransformers())
    self.assertEqual(len(list(raw_block_structure.get_block_keys())), len(self.blocks))
    clear_course_from_cache(self.course.id)
    trans_block_structure = get_course_blocks(self.user, self.course.location, self.transformers)
    trans_keys = set(trans_block_structure.get_block_keys())
    block_key_set = self.get_block_key_set(self.blocks, 'course', 'chapter1', 'lesson1', 'vertical1', 'library_content1')
    for key in block_key_set:
        self.assertIn(key, trans_keys)
    vertical2_selected = (self.get_block_key_set(self.blocks, 'vertical2').pop() in trans_keys)
    vertical3_selected = (self.get_block_key_set(self.blocks, 'vertical3').pop() in trans_keys)
    self.assertNotEquals(vertical2_selected, vertical3_selected)
    selected_vertical = ('vertical2' if vertical2_selected else 'vertical3')
    selected_child = ('html1' if vertical2_selected else 'html2')
    clear_course_from_cache(self.course.id)
    for i in range(5):
        trans_block_structure = get_course_blocks(self.user, self.course.location, self.transformers)
        self.assertEqual(set(trans_block_structure.get_block_keys()), self.get_block_key_set(self.blocks, 'course', 'chapter1', 'lesson1', 'vertical1', 'library_content1', selected_vertical, selected_child), "Expected    'selected'    equality    failed    in    iteration    {}.".format(i))
