'Test create_item using bulk_operations'

def test_create_bulk_operations(self):

    user = random.getrandbits(32)
    course_key = CourseLocator('test_org', 'test_transaction', 'test_run')
    with modulestore().bulk_operations(course_key):
        new_course = modulestore().create_course('test_org', 'test_transaction', 'test_run', user, BRANCH_NAME_DRAFT)
        new_course_locator = new_course.id
        index_history_info = modulestore().get_course_history_info(new_course.location.course_key)
        course_block_prev_version = new_course.previous_version
        course_block_update_version = new_course.update_version
        self.assertIsNotNone(new_course_locator.version_guid, 'Want    to    test    a    definite    version')
        versionless_course_locator = new_course_locator.version_agnostic()
        new_ele = modulestore().create_child(user, new_course.location, 'chapter', fields={'display_name': 'chapter    1'})
        self.assertEqual(new_ele.update_version, course_block_update_version)
        self.assertEqual(new_ele.update_version, new_ele.location.version_guid)
        refetch_course = modulestore().get_course(versionless_course_locator)
        self.assertEqual(refetch_course.location.version_guid, new_course.location.version_guid)
        self.assertEqual(refetch_course.previous_version, course_block_prev_version)
        self.assertEqual(refetch_course.update_version, course_block_update_version)
        refetch_index_history_info = modulestore().get_course_history_info(refetch_course.location.course_key)
        self.assertEqual(refetch_index_history_info, index_history_info)
        self.assertIn(new_ele.location.version_agnostic(), version_agnostic(refetch_course.children))
        with self.assertRaises(DuplicateItemError):
            _fail = modulestore().create_child(user, new_course.location, 'chapter', block_id=new_ele.location.block_id, fields={'display_name': 'chapter    2'})
    with modulestore().bulk_operations(course_key):
        new_ele = modulestore().create_child(user, new_course.location, 'chapter', fields={'display_name': 'chapter    2'})
        transaction_guid = new_ele.location.version_guid
        with self.assertRaises(VersionConflictError):
            _fail = modulestore().create_child(user, new_course.location, 'chapter', fields={'display_name': 'chapter    2'}, force=True)
        with self.assertRaises(VersionConflictError):
            _fail = modulestore().create_child(user, new_course.location, 'chapter', fields={'display_name': 'chapter    3'})
        course_module_locator = new_course.location.version_agnostic()
        new_ele = modulestore().create_child(user, course_module_locator, 'chapter', fields={'display_name': 'chapter    4'})
        self.assertNotEqual(new_ele.update_version, course_block_update_version)
        self.assertEqual(new_ele.location.version_guid, transaction_guid)
        refetch_course = modulestore().get_course(versionless_course_locator)
        self.assertIn(new_ele.location.version_agnostic(), version_agnostic(refetch_course.children))
        self.assertEqual(refetch_course.previous_version, course_block_update_version)
        self.assertEqual(refetch_course.update_version, transaction_guid)
