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

Python factories.LibraryFactory类代码示例

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

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



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

示例1: test_libraries_on_course_index

    def test_libraries_on_course_index(self):
        """
        Test getting the list of libraries from the course listing page
        """
        def _assert_library_link_present(response, library):
            """
            Asserts there's a valid library link on libraries tab.
            """
            parsed_html = lxml.html.fromstring(response.content)
            library_link_elements = parsed_html.find_class('library-link')
            self.assertEqual(len(library_link_elements), 1)
            link = library_link_elements[0]
            self.assertEqual(
                link.get("href"),
                reverse_library_url('library_handler', library.location.library_key),
            )
            # now test that url
            outline_response = self.client.get(link.get("href"), {}, HTTP_ACCEPT='text/html')
            self.assertEqual(outline_response.status_code, 200)

        # Add a library:
        lib1 = LibraryFactory.create()

        index_url = '/home/'
        index_response = self.client.get(index_url, {}, HTTP_ACCEPT='text/html')
        _assert_library_link_present(index_response, lib1)

        # Make sure libraries are visible to non-staff users too
        self.client.logout()
        non_staff_user, non_staff_userpassword = self.create_non_staff_user()
        lib2 = LibraryFactory.create(user_id=non_staff_user.id)
        LibraryUserRole(lib2.location.library_key).add_users(non_staff_user)
        self.client.login(username=non_staff_user.username, password=non_staff_userpassword)
        index_response = self.client.get(index_url, {}, HTTP_ACCEPT='text/html')
        _assert_library_link_present(index_response, lib2)
开发者ID:Stanford-Online,项目名称:edx-platform,代码行数:35,代码来源:test_course_index.py


示例2: test_libraries_on_index

    def test_libraries_on_index(self):
        """
        Test that the library tab is present.
        """
        def _assert_library_tab_present(response):
            """
            Asserts there's a library tab.
            """
            parsed_html = lxml.html.fromstring(response.content)
            library_tab = parsed_html.find_class('react-library-listing')
            self.assertEqual(len(library_tab), 1)

        # Add a library:
        lib1 = LibraryFactory.create()

        index_url = '/home/'
        index_response = self.client.get(index_url, {}, HTTP_ACCEPT='text/html')
        _assert_library_tab_present(index_response)

        # Make sure libraries are visible to non-staff users too
        self.client.logout()
        non_staff_user, non_staff_userpassword = self.create_non_staff_user()
        lib2 = LibraryFactory.create(user_id=non_staff_user.id)
        LibraryUserRole(lib2.location.library_key).add_users(non_staff_user)
        self.client.login(username=non_staff_user.username, password=non_staff_userpassword)
        index_response = self.client.get(index_url, {}, HTTP_ACCEPT='text/html')
        _assert_library_tab_present(index_response)
开发者ID:dehamzah,项目名称:edx-platform,代码行数:27,代码来源:test_course_index.py


示例3: test_duplicate_library

 def test_duplicate_library(self):
     """
     Make sure we cannot create duplicate libraries
     """
     org, lib_code = ("DuplicateX", "DUP")
     LibraryFactory.create(org=org, library=lib_code, modulestore=self.store)
     with self.assertRaises(DuplicateCourseError):
         LibraryFactory.create(org=org, library=lib_code, modulestore=self.store)
开发者ID:xego,项目名称:edx-platform,代码行数:8,代码来源:test_libraries.py


示例4: test_create_library

    def test_create_library(self):
        """
        Test that we can create a library, and see how many mongo calls it uses to do so.

        Expected mongo calls, in order:
        find_one({'org': '...', 'run': 'library', 'course': '...'})
        insert(definition: {'block_type': 'library', 'fields': {}})

        insert_structure(bulk)
        insert_course_index(bulk)
        get_course_index(bulk)
        """
        with check_mongo_calls(2, 3):
            LibraryFactory.create(modulestore=self.store)
开发者ID:xego,项目名称:edx-platform,代码行数:14,代码来源:test_libraries.py


示例5: test_library_import_branch_settings

    def test_library_import_branch_settings(self, branch_setting):
        """
        Try importing a known good library archive under either branch setting.
        The branch setting should have no effect on library import.
        """
        with self.store.branch_setting(branch_setting):
            library = LibraryFactory.create(modulestore=self.store)
            lib_key = library.location.library_key
            extract_dir = path(tempfile.mkdtemp(dir=settings.DATA_DIR))
            # the extract_dir needs to be passed as a relative dir to
            # import_library_from_xml
            extract_dir_relative = path.relpath(extract_dir, settings.DATA_DIR)

            try:
                with tarfile.open(path(TEST_DATA_DIR) / 'imports' / 'library.HhJfPD.tar.gz') as tar:
                    safetar_extractall(tar, extract_dir)
                import_library_from_xml(
                    self.store,
                    self.user.id,
                    settings.GITHUB_REPO_ROOT,
                    [extract_dir_relative / 'library'],
                    load_error_modules=False,
                    static_content_store=contentstore(),
                    target_id=lib_key
                )
            finally:
                shutil.rmtree(extract_dir)
开发者ID:cpennington,项目名称:edx-platform,代码行数:27,代码来源:test_import_export.py


示例6: test_no_access

    def test_no_access(self):
        user, password = self.create_non_staff_user()
        self.client.login(username=user, password=password)

        lib = LibraryFactory.create()
        response = self.client.get(make_url_for_lib(lib.location.library_key))
        self.assertEqual(response.status_code, 403)
开发者ID:shevious,项目名称:edx-platform,代码行数:7,代码来源:test_library.py


示例7: test_manage_library_users

    def test_manage_library_users(self):
        """
        Simple test that the Library "User Access" view works.
        Also tests that we can use the REST API to assign a user to a library.
        """
        library = LibraryFactory.create()
        extra_user, _ = self.create_non_staff_user()
        manage_users_url = reverse_library_url('manage_library_users', unicode(library.location.library_key))

        response = self.client.get(manage_users_url)
        self.assertEqual(response.status_code, 200)
        # extra_user has not been assigned to the library so should not show up in the list:
        self.assertNotIn(extra_user.username, response.content)

        # Now add extra_user to the library:
        user_details_url = reverse_course_url(
            'course_team_handler',
            library.location.library_key, kwargs={'email': extra_user.email}
        )
        edit_response = self.client.ajax_post(user_details_url, {"role": LibraryUserRole.ROLE})
        self.assertIn(edit_response.status_code, (200, 204))

        # Now extra_user should apear in the list:
        response = self.client.get(manage_users_url)
        self.assertEqual(response.status_code, 200)
        self.assertIn(extra_user.username, response.content)
开发者ID:shevious,项目名称:edx-platform,代码行数:26,代码来源:test_library.py


示例8: test_library_export

 def test_library_export(self):
     """
     Verify that useable library data can be exported.
     """
     youtube_id = "qS4NO9MNC6w"
     library = LibraryFactory.create(modulestore=self.store)
     video_block = ItemFactory.create(
         category="video",
         parent_location=library.location,
         user_id=self.user.id,
         publish_item=False,
         youtube_id_1_0=youtube_id
     )
     name = library.url_name
     lib_key = library.location.library_key
     root_dir = path(tempfile.mkdtemp())
     try:
         export_library_to_xml(self.store, contentstore(), lib_key, root_dir, name)
         lib_xml = lxml.etree.XML(open(root_dir / name / LIBRARY_ROOT).read())
         self.assertEqual(lib_xml.get('org'), lib_key.org)
         self.assertEqual(lib_xml.get('library'), lib_key.library)
         block = lib_xml.find('video')
         self.assertIsNotNone(block)
         self.assertEqual(block.get('url_name'), video_block.url_name)
         video_xml = lxml.etree.XML(open(root_dir / name / 'video' / video_block.url_name + '.xml').read())
         self.assertEqual(video_xml.tag, 'video')
         self.assertEqual(video_xml.get('youtube_id_1_0'), youtube_id)
     finally:
         shutil.rmtree(root_dir / name)
开发者ID:cpennington,项目名称:edx-platform,代码行数:29,代码来源:test_import_export.py


示例9: test_copy_from_template_publish

    def test_copy_from_template_publish(self):
        """
        Test that copy_from_template's "defaults" data is not lost
        when blocks are published.
        """
        # Create a library with a problem:
        source_library = LibraryFactory.create(modulestore=self.store)
        display_name_expected = "CUSTOM Library Display Name"
        self.make_block("problem", source_library, display_name=display_name_expected)
        # Reload source_library since we need its branch and version to use copy_from_template:
        source_library = self.store.get_library(
            source_library.location.library_key, remove_version=False, remove_branch=False
        )
        # And a course with a vertical:
        course = CourseFactory.create(modulestore=self.store)
        self.make_block("vertical", course)

        problem_key_in_course = self.store.copy_from_template(
            source_library.children, dest_key=course.location, user_id=self.user_id
        )[0]

        # We do the following twice because different methods get used inside
        # split modulestore on first vs. subsequent publish
        for __ in range(2):
            # Publish:
            self.store.publish(problem_key_in_course, self.user_id)
            # Test that the defaults values are there.
            problem_published = self.store.get_item(
                problem_key_in_course.for_branch(ModuleStoreEnum.BranchName.published)
            )
            self.assertEqual(problem_published.display_name, display_name_expected)
开发者ID:cmscom,项目名称:edx-platform,代码行数:31,代码来源:test_split_copy_from_template.py


示例10: test_library_author_view

    def test_library_author_view(self):
        """
        Test that LibraryRoot.author_view can run and includes content from its
        children.
        We have to patch the runtime (module system) in order to be able to
        render blocks in our test environment.
        """
        library = LibraryFactory.create(modulestore=self.store)
        # Add one HTML block to the library:
        ItemFactory.create(
            category="html",
            parent_location=library.location,
            user_id=self.user_id,
            publish_item=False,
            modulestore=self.store,
        )
        library = self.store.get_library(library.location.library_key)

        context = {"reorderable_items": set()}
        # Patch the HTML block to always render "Hello world"
        message = u"Hello world"
        hello_render = lambda _, context: Fragment(message)
        with patch("xmodule.html_module.HtmlDescriptor.author_view", hello_render, create=True):
            with patch("xmodule.x_module.descriptor_global_get_asides", lambda block: []):
                result = library.render(AUTHOR_VIEW, context)
        self.assertIn(message, result.content)
开发者ID:xego,项目名称:edx-platform,代码行数:26,代码来源:test_libraries.py


示例11: test_library_author_view_with_paging

    def test_library_author_view_with_paging(self):
        """
        Test that LibraryRoot.author_view can apply paging
        We have to patch the runtime (module system) in order to be able to
        render blocks in our test environment.
        """
        library = LibraryFactory.create(modulestore=self.store)
        # Add five HTML blocks to the library:
        blocks = [
            ItemFactory.create(
                category="html",
                parent_location=library.location,
                user_id=self.user_id,
                publish_item=False,
                modulestore=self.store,
                data="HtmlBlock" + str(i)
            )
            for i in range(5)
        ]
        library = self.store.get_library(library.location.library_key)

        def render_and_check_contents(page, page_size):
            """ Renders block and asserts on returned content """
            context = {'reorderable_items': set(), 'paging': {'page_number': page, 'page_size': page_size}}
            expected_blocks = blocks[page_size * page:page_size * (page + 1)]
            result = library.render(AUTHOR_VIEW, context)

            for expected_block in expected_blocks:
                self.assertIn(expected_block.data, result.content)

        render_and_check_contents(0, 3)
        render_and_check_contents(1, 3)
        render_and_check_contents(0, 2)
        render_and_check_contents(1, 2)
开发者ID:AlexxNica,项目名称:edx-platform,代码行数:34,代码来源:test_library_root.py


示例12: test_library_author_view

    def test_library_author_view(self):
        """
        Test that LibraryRoot.author_view can run and includes content from its
        children.
        We have to patch the runtime (module system) in order to be able to
        render blocks in our test environment.
        """
        message = u"Hello world"
        library = LibraryFactory.create(modulestore=self.store)
        # Add one HTML block to the library:
        ItemFactory.create(
            category="html",
            parent_location=library.location,
            user_id=self.user_id,
            publish_item=False,
            modulestore=self.store,
            data=message
        )
        library = self.store.get_library(library.location.library_key)

        context = {'reorderable_items': set(), }
        # Patch the HTML block to always render "Hello world"

        result = library.render(AUTHOR_VIEW, context)
        self.assertIn(message, result.content)
开发者ID:AlexxNica,项目名称:edx-platform,代码行数:25,代码来源:test_library_root.py


示例13: test_bad_http_verb_with_lib_key

 def test_bad_http_verb_with_lib_key(self):
     """
     We should get an error if we do weird requests to /library/
     """
     lib = LibraryFactory.create()
     for verb in ("post", "delete", "put"):
         response = getattr(self.client, verb)(make_url_for_lib(lib.location.library_key))
         self.assertEqual(response.status_code, 405)
开发者ID:shevious,项目名称:edx-platform,代码行数:8,代码来源:test_library.py


示例14: test_str_repr

 def test_str_repr(self, name):
     """
     Test __unicode__() and __str__() methods of libraries
     """
     library = LibraryFactory.create(metadata={"display_name": name}, modulestore=self.store)
     self.assertIn(name, unicode(library))
     if not isinstance(name, unicode):
         self.assertIn(name, str(library))
开发者ID:xego,项目名称:edx-platform,代码行数:8,代码来源:test_libraries.py


示例15: test_list_available_libraries

 def test_list_available_libraries(self):
     """
     Test listing of libraries.
     """
     _ = LibraryFactory.create(modulestore=self.store)
     all_libraries = self.tools.list_available_libraries()
     self.assertTrue(all_libraries)
     self.assertEqual(len(all_libraries), 1)
开发者ID:cmscom,项目名称:edx-platform,代码行数:8,代码来源:test_library_tools.py


示例16: setUp

    def setUp(self):
        """ Setup method - create courses """
        super(TestReindexCourse, self).setUp()
        self.store = modulestore()
        self.first_lib = LibraryFactory.create(
            org="test", library="lib1", display_name="run1", default_store=ModuleStoreEnum.Type.split
        )
        self.second_lib = LibraryFactory.create(
            org="test", library="lib2", display_name="run2", default_store=ModuleStoreEnum.Type.split
        )

        self.first_course = CourseFactory.create(
            org="test", course="course1", display_name="run1"
        )
        self.second_course = CourseFactory.create(
            org="test", course="course2", display_name="run1"
        )
开发者ID:AlexxNica,项目名称:edx-platform,代码行数:17,代码来源:test_reindex_courses.py


示例17: setUpClass

    def setUpClass(cls):

        super(LibraryTestCase, cls).setUpClass()

        cls.library = LibraryFactory.create(modulestore=cls.store)
        creator = UserFactory()

        cls.library_blocks = [
            ItemFactory.create(
                category="html",
                parent=cls.library,
                parent_location=cls.library.location,
                publish_item=False,
                user_id=creator.id,
                modulestore=cls.store,
            ) for _ in range(3)
        ]
        cls.libtools = LibraryToolsService(cls.store)
        cls.store.update_item(cls.library, creator.id)

        with cls.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, None):
            cls.course = CourseFactory.create(modulestore=cls.store)
            cls.course_key = cls.course.id

            with cls.store.bulk_operations(cls.course_key, emit_signals=False):
                cls.chapter = ItemFactory.create(
                    parent=cls.course,
                    parent_location=cls.course.location,
                    category="chapter",
                    modulestore=cls.store,
                    publish_item=False,
                )
                cls.sequential = ItemFactory.create(
                    parent=cls.chapter,
                    parent_location=cls.chapter.location,
                    category='sequential',
                    modulestore=cls.store,
                    publish_item=False,
                )
                cls.vertical = ItemFactory.create(
                    parent=cls.sequential,
                    parent_location=cls.sequential.location,
                    category='vertical',
                    modulestore=cls.store,
                    publish_item=False,
                )

                cls.lc_block = ItemFactory.create(
                    category="library_content",
                    parent=cls.vertical,
                    parent_location=cls.vertical.location,
                    max_count=2,
                    source_library_id=unicode(cls.library.location.library_key),
                    modulestore=cls.store,
                )
                # copy children from library to content block (LibaryContentDescriptor.tools.update_children?)
                cls.store.update_item(cls.course, creator.id)
                cls.store.update_item(cls.lc_block, creator.id)
开发者ID:edx-solutions,项目名称:edx-platform,代码行数:58,代码来源:test_creation.py


示例18: test_content_library_export_import

    def test_content_library_export_import(self):
        library1 = LibraryFactory.create(modulestore=self.store)
        source_library1_key = library1.location.library_key
        library2 = LibraryFactory.create(modulestore=self.store)
        source_library2_key = library2.location.library_key

        import_library_from_xml(
            self.store,
            'test_user',
            TEST_DATA_DIR,
            ['library_empty_problem'],
            static_content_store=contentstore(),
            target_id=source_library1_key,
            load_error_modules=False,
            raise_on_failure=True,
            create_if_not_present=True,
        )

        export_library_to_xml(
            self.store,
            contentstore(),
            source_library1_key,
            self.export_dir,
            'exported_source_library',
        )

        source_library = self.store.get_library(source_library1_key)
        self.assertEqual(source_library.url_name, 'library')

        # Import the exported library into a different content library.
        import_library_from_xml(
            self.store,
            'test_user',
            self.export_dir,
            ['exported_source_library'],
            static_content_store=contentstore(),
            target_id=source_library2_key,
            load_error_modules=False,
            raise_on_failure=True,
            create_if_not_present=True,
        )

        # Compare the two content libraries for equality.
        self.assertCoursesEqual(source_library1_key, source_library2_key)
开发者ID:cpennington,项目名称:edx-platform,代码行数:44,代码来源:test_import_export.py


示例19: test_get_lib_version

 def test_get_lib_version(self):
     """
     Test that we can get version data about a library from get_library()
     """
     # Create a library
     lib_key = LibraryFactory.create(modulestore=self.store).location.library_key
     # Re-load the library from the modulestore, explicitly including version information:
     lib = self.store.get_library(lib_key, remove_version=False, remove_branch=False)
     version = lib.location.library_key.version_guid
     self.assertIsInstance(version, ObjectId)
开发者ID:xego,项目名称:edx-platform,代码行数:10,代码来源:test_libraries.py


示例20: test_xblock_in_lib_have_published_version_returns_false

 def test_xblock_in_lib_have_published_version_returns_false(self):
     library = LibraryFactory.create(modulestore=self.store)
     block = ItemFactory.create(
         category="html",
         parent_location=library.location,
         user_id=self.user_id,
         publish_item=False,
         modulestore=self.store,
     )
     self.assertFalse(self.store.has_published_version(block))
开发者ID:Cgruppo,项目名称:edx-platform,代码行数:10,代码来源:test_libraries.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python factories.SampleCourseFactory类代码示例发布时间:2022-05-26
下一篇:
Python factories.ItemFactory类代码示例发布时间: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