'Test the standard patterns: publish to new branch, revise and publish'

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

    source_course = CourseLocator(org='testx', course='GreekHero', run='run', branch=BRANCH_NAME_DRAFT)
    dest_course = CourseLocator(org='testx', course='GreekHero', run='run', branch=BRANCH_NAME_PUBLISHED)
    head = source_course.make_usage_key('course', 'head12345')
    chapter1 = source_course.make_usage_key('chapter', 'chapter1')
    chapter2 = source_course.make_usage_key('chapter', 'chapter2')
    chapter3 = source_course.make_usage_key('chapter', 'chapter3')
    modulestore().copy(self.user_id, source_course, dest_course, [head], [chapter2, chapter3])
    expected = [BlockKey.from_usage_key(head), BlockKey.from_usage_key(chapter1)]
    unexpected = [BlockKey.from_usage_key(chapter2), BlockKey.from_usage_key(chapter3), BlockKey('problem', 'problem1'), BlockKey('problem', 'problem3_2')]
    self._check_course(source_course, dest_course, expected, unexpected)
    new_module = modulestore().create_child(self.user_id, chapter1, 'sequential', fields={'display_name': 'new    sequential'})
    expected.remove(BlockKey.from_usage_key(chapter1))
    with self.assertRaises(ItemNotFoundError):
        modulestore().get_item(new_module.location.map_into_course(dest_course))
    modulestore().copy(self.user_id, source_course, dest_course, [new_module.location], None)
    expected.append(BlockKey.from_usage_key(new_module.location))
    pub_module = modulestore().get_item(new_module.location.map_into_course(dest_course))
    self.assertEqual(modulestore().get_parent_location(pub_module.location).block_id, chapter1.block_id)
    new_module = modulestore().create_item(self.user_id, source_course, 'course_info', block_id='handouts')
    modulestore().copy(self.user_id, source_course, dest_course, [new_module.location], None)
    expected.append(BlockKey.from_usage_key(new_module.location))
    pub_module = modulestore().get_item(new_module.location.map_into_course(dest_course))
    self._check_course(source_course, dest_course, expected, unexpected)
