'Check that asides could be imported from XML and the modulestores handle asides crud'

@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
@XBlockAside.register_temp_plugin(AsideTestType, 'test_aside')
@patch('xmodule.modulestore.split_mongo.caching_descriptor_system.CachingDescriptorSystem.applicable_aside_types', (lambda self, block: ['test_aside']))
def test_aside_crud(self, default_store):

    if (default_store == ModuleStoreEnum.Type.mongo):
        raise SkipTest('asides    not    supported    in    old    mongo')
    with MongoContentstoreBuilder().build() as contentstore:
        self.store = MixedModuleStore(contentstore=contentstore, create_modulestore_instance=create_modulestore_instance, mappings={}, **self.OPTIONS)
        self.addCleanup(self.store.close_all_connections)
        with self.store.default_store(default_store):
            dest_course_key = self.store.make_course_key('edX', 'aside_test', '2012_Fall')
            courses = import_course_from_xml(self.store, self.user_id, DATA_DIR, ['aside'], load_error_modules=False, static_content_store=contentstore, target_id=dest_course_key, create_if_not_present=True)
            def check_block(block):
                "\n                                                                                Check    whether    block    has    the    expected    aside    w/    its    fields    and    then    recurse    to    the    block's    children\n                                                                                "
                asides = block.runtime.get_asides(block)
                self.assertEqual(len(asides), 1, 'Found    {}    asides    but    expected    only    test_aside'.format(asides))
                self.assertIsInstance(asides[0], AsideTestType)
                category = block.scope_ids.block_type
                self.assertEqual(asides[0].data_field, '{}    aside    data'.format(category))
                self.assertEqual(asides[0].content, '{}    Aside'.format(category.capitalize()))
                for child in block.get_children():
                    check_block(child)
            check_block(courses[0])
            new_chapter = self.store.create_child(self.user_id, courses[0].location, 'chapter', 'new_chapter')
            asides = new_chapter.runtime.get_asides(new_chapter)
            self.assertEqual(len(asides), 1, 'Found    {}    asides    but    expected    only    test_aside'.format(asides))
            chapter_aside = asides[0]
            self.assertIsInstance(chapter_aside, AsideTestType)
            self.assertFalse(chapter_aside.fields['data_field'].is_set_on(chapter_aside), "data_field    says    it's    assigned    to    {}".format(chapter_aside.data_field))
            self.assertFalse(chapter_aside.fields['content'].is_set_on(chapter_aside), "content    says    it's    assigned    to    {}".format(chapter_aside.content))
            chapter_aside.data_field = 'new    value'
            self.store.update_item(new_chapter, self.user_id, asides=[chapter_aside])
            new_chapter = self.store.get_item(new_chapter.location)
            chapter_aside = new_chapter.runtime.get_asides(new_chapter)[0]
            self.assertEqual('new    value', chapter_aside.data_field)
            chapter_aside.data_field = 'another    one    value'
            self.store.update_item(new_chapter, self.user_id, asides=[chapter_aside])
            new_chapter2 = self.store.get_item(new_chapter.location)
            chapter_aside2 = new_chapter2.runtime.get_asides(new_chapter2)[0]
            self.assertEqual('another    one    value', chapter_aside2.data_field)
