'Test get_block_generations'

@patch('xmodule.tabs.CourseTab.from_json', side_effect=mock_tab_from_json)
def test_block_generations(self, _from_json):

    test_course = modulestore().create_course(org='edu.harvard', course='history', run='hist101', display_name='history    test    course', user_id='testbot', master_branch=ModuleStoreEnum.BranchName.draft)
    chapter = modulestore().create_child(None, test_course.location, block_type='chapter', block_id='chapter1', fields={'display_name': 'chapter    1'})
    sub = modulestore().create_child(None, chapter.location, block_type='vertical', block_id='subsection1', fields={'display_name': 'subsection    1'})
    first_problem = modulestore().create_child(None, sub.location, block_type='problem', block_id='problem1', fields={'display_name': 'problem    1', 'data': '<problem></problem>'})
    first_problem.max_attempts = 3
    first_problem.save()
    updated_problem = modulestore().update_item(first_problem, 'testbot')
    self.assertIsNotNone(updated_problem.previous_version)
    self.assertEqual(updated_problem.previous_version, first_problem.update_version)
    self.assertNotEqual(updated_problem.update_version, first_problem.update_version)
    modulestore().delete_item(updated_problem.location, 'testbot')
    second_problem = modulestore().create_child(None, sub.location.version_agnostic(), block_type='problem', block_id='problem2', fields={'display_name': 'problem    2', 'data': '<problem></problem>'})
    version_history = modulestore().get_block_generations(test_course.location)
    self.assertIsNotNone(version_history)
    self.assertEqual(version_history.locator.version_guid, test_course.location.version_guid)
    self.assertEqual(len(version_history.children), 1)
    self.assertEqual(version_history.children[0].children, [])
    self.assertEqual(version_history.children[0].locator.version_guid, chapter.location.version_guid)
    version_history = modulestore().get_block_generations(sub.location)
    self.assertEqual(len(version_history.children), 1)
    self.assertEqual(len(version_history.children[0].children), 1)
    self.assertEqual(len(version_history.children[0].children[0].children), 1)
    self.assertEqual(len(version_history.children[0].children[0].children[0].children), 0)
    version_history = modulestore().get_block_generations(updated_problem.location)
    self.assertEqual(version_history.locator.version_guid, first_problem.location.version_guid)
    self.assertEqual(len(version_history.children), 1)
    self.assertEqual(len(version_history.children[0].children), 0)
    version_history = modulestore().get_block_generations(second_problem.location)
    self.assertNotEqual(version_history.locator.version_guid, first_problem.location.version_guid)
