• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python xml_importer.import_from_xml函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中xmodule.modulestore.xml_importer.import_from_xml函数的典型用法代码示例。如果您正苦于以下问题:Python import_from_xml函数的具体用法?Python import_from_xml怎么用?Python import_from_xml使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了import_from_xml函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_toy_textbooks_loads

    def test_toy_textbooks_loads(self):
        module_store = modulestore()
        import_from_xml(module_store, TEST_DATA_DIR, ["toy"])

        course = module_store.get_item(Location(["i4x", "edX", "toy", "course", "2012_Fall", None]))

        self.assertGreater(len(course.textbooks), 0)
开发者ID:rajeshpillai,项目名称:edx-platform,代码行数:7,代码来源:tests.py


示例2: test_remove_hide_progress_tab

    def test_remove_hide_progress_tab(self):
        module_store = modulestore('direct')
        import_from_xml(module_store, 'common/test/data/', ['full'])

        source_location = CourseDescriptor.id_to_location('edX/full/6.002_Spring_2012')
        course = module_store.get_item(source_location)
        self.assertFalse(course.hide_progress_tab)
开发者ID:nettoyeur,项目名称:edx-platform,代码行数:7,代码来源:test_contentstore.py


示例3: check_components_on_page

    def check_components_on_page(self, component_types, expected_types):
        """
        Ensure that the right types end up on the page.

        component_types is the list of advanced components.

        expected_types is the list of elements that should appear on the page.

        expected_types and component_types should be similar, but not
        exactly the same -- for example, 'videoalpha' in
        component_types should cause 'Video Alpha' to be present.
        """
        store = modulestore('direct')
        import_from_xml(store, 'common/test/data/', ['simple'])

        course = store.get_item(Location(['i4x', 'edX', 'simple',
                                          'course', '2012_Fall', None]), depth=None)

        course.advanced_modules = component_types

        store.update_metadata(course.location, own_metadata(course))

        # just pick one vertical
        descriptor = store.get_items(Location('i4x', 'edX', 'simple', 'vertical', None, None))[0]

        resp = self.client.get(reverse('edit_unit', kwargs={'location': descriptor.location.url()}))
        self.assertEqual(resp.status_code, 200)

        for expected in expected_types:
            self.assertIn(expected, resp.content)
开发者ID:nettoyeur,项目名称:edx-platform,代码行数:30,代码来源:test_contentstore.py


示例4: test_get_items

    def test_get_items(self):
        '''
        This verifies a bug we had where the None setting in get_items() meant 'wildcard'
        Unfortunately, None = published for the revision field, so get_items() would return
        both draft and non-draft copies.
        '''
        store = modulestore('direct')
        draft_store = modulestore('draft')
        import_from_xml(store, 'common/test/data/', ['simple'])

        html_module = draft_store.get_item(['i4x', 'edX', 'simple', 'html', 'test_html', None])

        draft_store.clone_item(html_module.location, html_module.location)

        # now query get_items() to get this location with revision=None, this should just
        # return back a single item (not 2)

        items = store.get_items(['i4x', 'edX', 'simple', 'html', 'test_html', None])
        self.assertEqual(len(items), 1)
        self.assertFalse(getattr(items[0], 'is_draft', False))

        # now refetch from the draft store. Note that even though we pass
        # None in the revision field, the draft store will replace that with 'draft'
        items = draft_store.get_items(['i4x', 'edX', 'simple', 'html', 'test_html', None])
        self.assertEqual(len(items), 1)
        self.assertTrue(getattr(items[0], 'is_draft', False))
开发者ID:nettoyeur,项目名称:edx-platform,代码行数:26,代码来源:test_contentstore.py


示例5: test_import_textbook_as_content_element

    def test_import_textbook_as_content_element(self):
        module_store = modulestore('direct')
        import_from_xml(module_store, 'common/test/data/', ['full'])

        course = module_store.get_item(Location(['i4x', 'edX', 'full', 'course', '6.002_Spring_2012', None]))

        self.assertGreater(len(course.textbooks), 0)
开发者ID:nettoyeur,项目名称:edx-platform,代码行数:7,代码来源:test_contentstore.py


示例6: test_rewrite_reference_list

 def test_rewrite_reference_list(self):
     module_store = modulestore('direct')
     target_location = Location(['i4x', 'testX', 'conditional_copy', 'course', 'copy_run'])
     import_from_xml(
         module_store,
         'common/test/data/',
         ['conditional'],
         target_location_namespace=target_location
     )
     conditional_module = module_store.get_item(
         Location(['i4x', 'testX', 'conditional_copy', 'conditional', 'condone'])
     )
     self.assertIsNotNone(conditional_module)
     self.assertListEqual(
         [
             u'i4x://testX/conditional_copy/problem/choiceprob',
             u'i4x://edX/different_course/html/for_testing_import_rewrites'
         ],
         conditional_module.sources_list
     )
     self.assertListEqual(
         [
             u'i4x://testX/conditional_copy/html/congrats',
             u'i4x://testX/conditional_copy/html/secret_page'
         ],
         conditional_module.show_tag_list
     )
开发者ID:Caesar73,项目名称:edx-platform,代码行数:27,代码来源:test_import.py


示例7: setUp

    def setUp(self):
        super(TestMongoCoursesLoad, self).setUp()
        self.setup_user()

        # Import the toy course into a Mongo-backed modulestore
        self.store = modulestore()
        import_from_xml(self.store, TEST_DATA_DIR, ['toy'])
开发者ID:6thfdwp,项目名称:edx-platform,代码行数:7,代码来源:tests.py


示例8: initdb

 def initdb():
     # connect to the db
     store = MongoModuleStore(HOST, DB, COLLECTION, FS_ROOT, RENDER_TEMPLATE, default_class=DEFAULT_CLASS)
     # Explicitly list the courses to load (don't want the big one)
     courses = ['toy', 'simple']
     import_from_xml(store, DATA_DIR, courses)
     return store
开发者ID:LukeLu1263,项目名称:edx-platform,代码行数:7,代码来源:test_mongo.py


示例9: setUp

 def setUp(self):
     CourseTestCase.setUp(self)
     # add in the full class too
     import_from_xml(get_modulestore(
         self.course_location), 'common/test/data/', ['full'])
     self.fullcourse_location = Location(
         ['i4x', 'edX', 'full', 'course', '6.002_Spring_2012', None])
开发者ID:hughdbrown,项目名称:edx-platform,代码行数:7,代码来源:test_course_settings.py


示例10: test_generate_find_timings

    def test_generate_find_timings(self, source_ms, num_assets):
        """
        Generate timings for different amounts of asset metadata and different modulestores.
        """
        if CodeBlockTimer is None:
            raise SkipTest("CodeBlockTimer undefined.")

        desc = "FindAssetTest:{}:{}".format(
            SHORT_NAME_MAP[source_ms],
            num_assets,
        )

        with CodeBlockTimer(desc):

            with CodeBlockTimer("fake_assets"):
                # First, make the fake asset metadata.
                make_asset_xml(num_assets, ASSET_XML_PATH)
                validate_xml(ASSET_XSD_PATH, ASSET_XML_PATH)

            # Construct the contentstore for storing the first import
            with MongoContentstoreBuilder().build() as source_content:
                # Construct the modulestore for storing the first import (using the previously created contentstore)
                with source_ms.build(source_content) as source_store:
                    source_course_key = source_store.make_course_key('a', 'course', 'course')
                    asset_key = source_course_key.make_asset_key(
                        AssetMetadata.GENERAL_ASSET_TYPE, 'silly_cat_picture.gif'
                    )

                    with CodeBlockTimer("initial_import"):
                        import_from_xml(
                            source_store,
                            'test_user',
                            TEST_DATA_ROOT,
                            course_dirs=TEST_COURSE,
                            static_content_store=source_content,
                            target_course_id=source_course_key,
                            create_course_if_not_present=True,
                            raise_on_failure=True,
                        )

                    with CodeBlockTimer("find_nonexistent_asset"):
                        # More correct would be using the AssetManager.find() - but since the test
                        # has created its own test modulestore, the AssetManager can't be used.
                        __ = source_store.find_asset_metadata(asset_key)

                    # Perform get_all_asset_metadata for each sort.
                    for sort in ALL_SORTS:
                        with CodeBlockTimer("get_asset_list:{}-{}".format(
                            sort[0],
                            'asc' if sort[1] == ModuleStoreEnum.SortOrder.ascending else 'desc'
                        )):
                            # Grab two ranges of 50 assets using different sorts.
                            # Why 50? That's how many are displayed on the current Studio "Files & Uploads" page.
                            start_middle = num_assets / 2
                            __ = source_store.get_all_asset_metadata(
                                source_course_key, 'asset', start=0, sort=sort, maxresults=50
                            )
                            __ = source_store.get_all_asset_metadata(
                                source_course_key, 'asset', start=start_middle, sort=sort, maxresults=50
                            )
开发者ID:olexiim,项目名称:edx-platform,代码行数:60,代码来源:test_asset_import_export.py


示例11: test_rewrite_reference_list

 def test_rewrite_reference_list(self):
     # This test fails with split modulestore (the HTML component is not in "different_course_id" namespace).
     # More investigation needs to be done.
     module_store = modulestore()._get_modulestore_by_type(ModuleStoreEnum.Type.mongo)
     target_course_id = module_store.make_course_key('testX', 'conditional_copy', 'copy_run')
     import_from_xml(
         module_store,
         self.user.id,
         TEST_DATA_DIR,
         ['conditional'],
         target_course_id=target_course_id
     )
     conditional_module = module_store.get_item(
         target_course_id.make_usage_key('conditional', 'condone')
     )
     self.assertIsNotNone(conditional_module)
     different_course_id = module_store.make_course_key('edX', 'different_course', None)
     self.assertListEqual(
         [
             target_course_id.make_usage_key('problem', 'choiceprob'),
             different_course_id.make_usage_key('html', 'for_testing_import_rewrites')
         ],
         conditional_module.sources_list
     )
     self.assertListEqual(
         [
             target_course_id.make_usage_key('html', 'congrats'),
             target_course_id.make_usage_key('html', 'secret_page')
         ],
         conditional_module.show_tag_list
     )
开发者ID:akbargumbira,项目名称:Labster.EdX,代码行数:31,代码来源:test_import.py


示例12: initdb

    def initdb(cls):
        # connect to the db
        doc_store_config = {"host": HOST, "port": PORT, "db": DB, "collection": COLLECTION}
        cls.add_asset_collection(doc_store_config)

        # since MongoModuleStore and MongoContentStore are basically assumed to be together, create this class
        # as well
        content_store = MongoContentStore(HOST, DB, port=PORT)
        #
        # Also test draft store imports
        #
        draft_store = DraftModuleStore(
            content_store,
            doc_store_config,
            FS_ROOT,
            RENDER_TEMPLATE,
            default_class=DEFAULT_CLASS,
            branch_setting_func=lambda: ModuleStoreEnum.Branch.draft_preferred,
            xblock_mixins=(EditInfoMixin,),
        )
        import_from_xml(draft_store, 999, DATA_DIR, cls.courses, static_content_store=content_store)

        # also test a course with no importing of static content
        import_from_xml(
            draft_store,
            999,
            DATA_DIR,
            ["test_import_course"],
            static_content_store=content_store,
            do_import_static=False,
            verbose=True,
        )

        return content_store, draft_store
开发者ID:morsoinferno,项目名称:ANALYSE,代码行数:34,代码来源:test_mongo.py


示例13: setUp

    def setUp(self):
        """
        Create user and login.
        """
        self.staff_pwd = super(ContentStoreToyCourseTest, self).setUp()
        self.staff_usr = self.user
        self.non_staff_usr, self.non_staff_pwd = self.create_non_staff_user()

        self.client = Client()
        self.contentstore = contentstore()

        self.course_key = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')

        import_from_xml(modulestore(), self.user.id, 'common/test/data/', ['toy'],
                static_content_store=self.contentstore, verbose=True)

        # A locked asset
        self.locked_asset = self.course_key.make_asset_key('asset', 'sample_static.txt')
        self.url_locked = self.locked_asset.to_deprecated_string()

        # An unlocked asset
        self.unlocked_asset = self.course_key.make_asset_key('asset', 'another_static.txt')
        self.url_unlocked = self.unlocked_asset.to_deprecated_string()

        self.contentstore.set_attr(self.locked_asset, 'locked', True)
开发者ID:AlexanderFuentes,项目名称:edx-platform,代码行数:25,代码来源:test.py


示例14: test_clone_course

    def test_clone_course(self):

        course_data = {
            "template": "i4x://edx/templates/course/Empty",
            "org": "MITx",
            "number": "999",
            "display_name": "Robot Super Course",
        }

        module_store = modulestore("direct")
        import_from_xml(module_store, "common/test/data/", ["full"])

        resp = self.client.post(reverse("create_new_course"), course_data)
        self.assertEqual(resp.status_code, 200)
        data = parse_json(resp)
        self.assertEqual(data["id"], "i4x://MITx/999/course/Robot_Super_Course")

        content_store = contentstore()

        source_location = CourseDescriptor.id_to_location("edX/full/6.002_Spring_2012")
        dest_location = CourseDescriptor.id_to_location("MITx/999/Robot_Super_Course")

        clone_course(module_store, content_store, source_location, dest_location)

        # now loop through all the units in the course and verify that the clone can render them, which
        # means the objects are at least present
        items = module_store.get_items(Location(["i4x", "edX", "full", "vertical", None]))
        self.assertGreater(len(items), 0)
        clone_items = module_store.get_items(Location(["i4x", "MITx", "999", "vertical", None]))
        self.assertGreater(len(clone_items), 0)
        for descriptor in items:
            new_loc = descriptor.location.replace(org="MITx", course="999")
            print "Checking {0} should now also be at {1}".format(descriptor.location.url(), new_loc.url())
            resp = self.client.get(reverse("edit_unit", kwargs={"location": new_loc.url()}))
            self.assertEqual(resp.status_code, 200)
开发者ID:bonavolontag,项目名称:edx-platform,代码行数:35,代码来源:test_contentstore.py


示例15: _assert_import

    def _assert_import(self, course_dir, expected_xblock_loc, expected_field_val, has_draft=False):
        """
        Import a course from XML, then verify that the XBlock was loaded
        with the correct field value.

        Args:
            course_dir (str): The name of the course directory (relative to the test data directory)
            expected_xblock_loc (str): The location of the XBlock in the course.
            expected_field_val (str): The expected value of the XBlock's test field.

        Kwargs:
            has_draft (bool): If true, check that a draft of the XBlock exists with
                the expected field value set.

        """
        import_from_xml(
            self.store, 'common/test/data', [course_dir],
            draft_store=self.draft_store
        )

        xblock = self.store.get_item(expected_xblock_loc)
        self.assertTrue(isinstance(xblock, StubXBlock))
        self.assertEqual(xblock.test_field, expected_field_val)

        if has_draft:
            draft_xblock = self.draft_store.get_item(expected_xblock_loc)
            self.assertTrue(isinstance(draft_xblock, StubXBlock))
            self.assertEqual(draft_xblock.test_field, expected_field_val)
开发者ID:DazzaGreenwood,项目名称:edx-platform,代码行数:28,代码来源:test_import_pure_xblock.py


示例16: initdb

    def initdb():
        # connect to the db
        doc_store_config = {
            'host': HOST,
            'db': DB,
            'collection': COLLECTION,
        }
        store = MongoModuleStore(
            doc_store_config, FS_ROOT, RENDER_TEMPLATE, default_class=DEFAULT_CLASS,
            xblock_mixins=(XModuleMixin,)
        )
        # since MongoModuleStore and MongoContentStore are basically assumed to be together, create this class
        # as well
        content_store = MongoContentStore(HOST, DB)
        #
        # Also test draft store imports
        #
        draft_store = DraftModuleStore(doc_store_config, FS_ROOT, RENDER_TEMPLATE, default_class=DEFAULT_CLASS)
        import_from_xml(store, DATA_DIR, TestMongoModuleStore.courses, draft_store=draft_store, static_content_store=content_store)

        # also test a course with no importing of static content
        import_from_xml(
            store,
            DATA_DIR,
            ['test_import_course'],
            static_content_store=content_store,
            do_import_static=False,
            verbose=True
        )

        return store, content_store, draft_store
开发者ID:bmcdonald2,项目名称:edx-platform,代码行数:31,代码来源:test_mongo.py


示例17: test_rewrite_reference_list

 def test_rewrite_reference_list(self):
     module_store = modulestore()
     target_course_id = SlashSeparatedCourseKey('testX', 'conditional_copy', 'copy_run')
     import_from_xml(
         module_store,
         self.user.id,
         'common/test/data/',
         ['conditional'],
         target_course_id=target_course_id
     )
     conditional_module = module_store.get_item(
         target_course_id.make_usage_key('conditional', 'condone')
     )
     self.assertIsNotNone(conditional_module)
     different_course_id = SlashSeparatedCourseKey('edX', 'different_course', None)
     self.assertListEqual(
         [
             target_course_id.make_usage_key('problem', 'choiceprob'),
             different_course_id.make_usage_key('html', 'for_testing_import_rewrites')
         ],
         conditional_module.sources_list
     )
     self.assertListEqual(
         [
             target_course_id.make_usage_key('html', 'congrats'),
             target_course_id.make_usage_key('html', 'secret_page')
         ],
         conditional_module.show_tag_list
     )
开发者ID:AshWilliams,项目名称:edx-platform,代码行数:29,代码来源:test_import.py


示例18: test_round_trip

    def test_round_trip(self, source_builder, dest_builder, source_content_builder, dest_content_builder, course_data_name):

        # Construct the contentstore for storing the first import
        with source_content_builder.build() as source_content:
            # Construct the modulestore for storing the first import (using the previously created contentstore)
            with source_builder.build(source_content) as source_store:
                # Construct the contentstore for storing the second import
                with dest_content_builder.build() as dest_content:
                    # Construct the modulestore for storing the second import (using the second contentstore)
                    with dest_builder.build(dest_content) as dest_store:
                        source_course_key = source_store.make_course_key('source', 'course', 'key')
                        dest_course_key = dest_store.make_course_key('dest', 'course', 'key')

                        import_from_xml(
                            source_store,
                            'test_user',
                            'common/test/data',
                            course_dirs=[course_data_name],
                            static_content_store=source_content,
                            target_course_id=source_course_key,
                            create_new_course_if_not_present=True,
                        )

                        export_to_xml(
                            source_store,
                            source_content,
                            source_course_key,
                            self.export_dir,
                            'exported_course',
                        )

                        import_from_xml(
                            dest_store,
                            'test_user',
                            self.export_dir,
                            static_content_store=dest_content,
                            target_course_id=dest_course_key,
                            create_new_course_if_not_present=True,
                        )

                        self.exclude_field(None, 'wiki_slug')
                        self.exclude_field(None, 'xml_attributes')
                        self.ignore_asset_key('_id')
                        self.ignore_asset_key('uploadDate')
                        self.ignore_asset_key('content_son')
                        self.ignore_asset_key('thumbnail_location')

                        self.assertCoursesEqual(
                            source_store,
                            source_course_key,
                            dest_store,
                            dest_course_key,
                        )

                        self.assertAssetsEqual(
                            source_content,
                            source_course_key,
                            dest_content,
                            dest_course_key,
                        )
开发者ID:BenjiLee,项目名称:edx-platform,代码行数:60,代码来源:test_cross_modulestore_import_export.py


示例19: test_locking

    def test_locking(self):
        """
        Tests a simple locking and unlocking of an asset in the toy course.
        """
        def verify_asset_locked_state(locked):
            """ Helper method to verify lock state in the contentstore """
            asset_location = StaticContent.get_location_from_path('/c4x/edX/toy/asset/sample_static.txt')
            content = contentstore().find(asset_location)
            self.assertEqual(content.locked, locked)

        def post_asset_update(lock):
            """ Helper method for posting asset update. """
            upload_date = datetime(2013, 6, 1, 10, 30, tzinfo=UTC)
            location = Location(['c4x', 'edX', 'toy', 'asset', 'sample_static.txt'])
            url = reverse('update_asset', kwargs={'org': 'edX', 'course': 'toy', 'name': '2012_Fall'})

            resp = self.client.post(url, json.dumps(assets._get_asset_json("sample_static.txt", upload_date, location, None, lock)), "application/json")
            self.assertEqual(resp.status_code, 201)
            return json.loads(resp.content)

        # Load the toy course.
        module_store = modulestore('direct')
        import_from_xml(module_store, 'common/test/data/', ['toy'], static_content_store=contentstore(), verbose=True)
        verify_asset_locked_state(False)

        # Lock the asset
        resp_asset = post_asset_update(True)
        self.assertTrue(resp_asset['locked'])
        verify_asset_locked_state(True)

        # Unlock the asset
        resp_asset = post_asset_update(False)
        self.assertFalse(resp_asset['locked'])
        verify_asset_locked_state(False)
开发者ID:Cabris,项目名称:edx-platform,代码行数:34,代码来源:test_assets.py


示例20: test_get_depth_with_drafts

    def test_get_depth_with_drafts(self):
        import_from_xml(modulestore('direct'), 'common/test/data/', ['simple'])

        course = modulestore('draft').get_item(
            Location(['i4x', 'edX', 'simple', 'course', '2012_Fall', None]),
            depth=None
        )

        # make sure no draft items have been returned
        num_drafts = self._get_draft_counts(course)
        self.assertEqual(num_drafts, 0)

        problem = modulestore('draft').get_item(
            Location(['i4x', 'edX', 'simple', 'problem', 'ps01-simple', None])
        )

        # put into draft
        modulestore('draft').clone_item(problem.location, problem.location)

        # make sure we can query that item and verify that it is a draft
        draft_problem = modulestore('draft').get_item(
            Location(['i4x', 'edX', 'simple', 'problem', 'ps01-simple', None])
        )
        self.assertTrue(getattr(draft_problem, 'is_draft', False))

        #now requery with depth
        course = modulestore('draft').get_item(
            Location(['i4x', 'edX', 'simple', 'course', '2012_Fall', None]),
            depth=None
        )

        # make sure just one draft item have been returned
        num_drafts = self._get_draft_counts(course)
        self.assertEqual(num_drafts, 1)
开发者ID:nettoyeur,项目名称:edx-platform,代码行数:34,代码来源:test_contentstore.py



注:本文中的xmodule.modulestore.xml_importer.import_from_xml函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python xml_importer.perform_xlint函数代码示例发布时间:2022-05-26
下一篇:
Python xml_importer.import_course_from_xml函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap