'Make sure that copy_from_template works with things like \'chapter\' that
are always auto-published.'

def test_copy_from_template_auto_publish(self):

    source_course = CourseFactory.create(modulestore=self.store)
    course = CourseFactory.create(modulestore=self.store)
    about = self.make_block('about', source_course)
    chapter = self.make_block('chapter', source_course)
    sequential = self.make_block('sequential', chapter)
    vertical = self.make_block('vertical', sequential)
    self.make_block('problem', vertical)
    html = self.make_block('html', source_course)
    source_course = self.store.get_course(source_course.location.course_key, remove_version=False, remove_branch=False)
    source_keys = [block.location for block in [about, chapter, html]]
    block_keys = self.store.copy_from_template(source_keys, dest_key=course.location, user_id=self.user_id)
    self.assertEqual(len(block_keys), len(source_keys))
    new_blocks = {}
    block_keys = set(block_keys)
    while block_keys:
        key = block_keys.pop()
        block = self.store.get_item(key)
        new_blocks[block.category] = block
        block_keys.update(set(getattr(block, 'children', [])))
    def published_version_exists(block):
        '    Does    a    published    version    of    block    exist?    '
        try:
            self.store.get_item(block.location.for_branch(ModuleStoreEnum.BranchName.published))
            return True
        except ItemNotFoundError:
            return False
    self.assertFalse(self.store.has_changes(new_blocks['about']))
    self.assertTrue(published_version_exists(new_blocks['chapter']))
    self.assertTrue(published_version_exists(new_blocks['sequential']))
    self.assertTrue(self.store.has_changes(new_blocks['html']))
    self.assertTrue(self.store.has_changes(new_blocks['problem']))
    self.assertTrue(self.store.has_changes(new_blocks['chapter']))
    self.assertFalse(published_version_exists(new_blocks['vertical']))
