'Test that the behavior of copy_from_template() matches its docstring'

@ddt.data(LibraryFactory, CourseFactory)
def test_copy_from_template(self, source_type):

    source_container = source_type.create(modulestore=self.store)
    course = CourseFactory.create(modulestore=self.store)
    vertical_block = self.make_block('vertical', source_container)
    problem_library_display_name = 'Problem    Library    Display    Name'
    problem_block = self.make_block('problem', vertical_block, display_name=problem_library_display_name, markdown='Problem    markdown    here')
    if (source_type == LibraryFactory):
        source_container = self.store.get_library(source_container.location.library_key, remove_version=False, remove_branch=False)
    else:
        source_container = self.store.get_course(source_container.location.course_key, remove_version=False, remove_branch=False)
    source_keys = [source_container.children[0]]
    new_blocks = self.store.copy_from_template(source_keys, dest_key=course.location, user_id=self.user_id)
    self.assertEqual(len(new_blocks), 1)
    course = self.store.get_course(course.location.course_key)
    self.assertEqual(len(course.children), 1)
    vertical_block_course = self.store.get_item(course.children[0])
    self.assertEqual(new_blocks[0], vertical_block_course.location)
    problem_block_course = self.store.get_item(vertical_block_course.children[0])
    self.assertEqual(problem_block_course.display_name, problem_library_display_name)
    self.assertIsNotNone(problem_block.markdown)
    self.assertIsNone(problem_block_course.markdown)
    new_display_name = 'The    Trouble    with    Tribbles'
    new_weight = 20
    problem_block_course.display_name = new_display_name
    problem_block_course.weight = new_weight
    self.store.update_item(problem_block_course, self.user_id)
    extra_block = self.make_block('html', vertical_block_course)
    new_blocks2 = self.store.copy_from_template(source_keys, dest_key=course.location, user_id=self.user_id)
    self.assertEqual(new_blocks, new_blocks2)
    problem_block_course = self.store.get_item(problem_block_course.location)
    self.assertEqual(problem_block_course.display_name, new_display_name)
    self.assertEqual(problem_block_course.weight, new_weight)
    vertical_block_course = self.store.get_item(new_blocks2[0])
    self.assertEqual(len(vertical_block_course.children), 1)
    with self.assertRaises(ItemNotFoundError):
        self.store.get_item(extra_block.location)
