当前位置: 首页>>代码示例>>Python>>正文


Python locator.BlockUsageLocator类代码示例

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


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

示例1: test_get_item

    def test_get_item(self):
        '''
        get_item(blocklocator)
        '''
        # positive tests of various forms
        locator = BlockUsageLocator(version_guid=self.GUID_D1, usage_id='head12345')
        block = modulestore().get_item(locator)
        self.assertIsInstance(block, CourseDescriptor)

        locator = BlockUsageLocator(course_id='GreekHero', usage_id='head12345', branch='draft')
        block = modulestore().get_item(locator)
        self.assertEqual(block.location.course_id, "GreekHero")
        # look at this one in detail
        self.assertEqual(len(block.tabs), 6, "wrong number of tabs")
        self.assertEqual(block.display_name, "The Ancient Greek Hero")
        self.assertEqual(block.advertised_start, "Fall 2013")
        self.assertEqual(len(block.children), 3)
        self.assertEqual(block.definition_locator.definition_id, "head12345_12")
        # check dates and graders--forces loading of descriptor
        self.assertEqual(block.edited_by, "[email protected]")
        self.assertDictEqual(
            block.grade_cutoffs, {"Pass": 0.45},
        )

        # try to look up other branches
        self.assertRaises(ItemNotFoundError,
                          modulestore().get_item,
                          BlockUsageLocator(course_id=locator.as_course_locator(),
                                            usage_id=locator.usage_id,
                                            branch='published'))
        locator.branch = 'draft'
        self.assertIsInstance(
            modulestore().get_item(locator),
            CourseDescriptor
        )
开发者ID:burngeek8,项目名称:edx-platform,代码行数:35,代码来源:test_split_modulestore.py

示例2: test_old_location_helpers

    def test_old_location_helpers(self):
        """
        Test the functions intended to help with the conversion from old locations to locators
        """
        location_tuple = ('i4x', 'mit', 'eecs.6002x', 'course', 't3_2013')
        location = Location(location_tuple)
        self.assertEqual(location, Locator.to_locator_or_location(location))
        self.assertEqual(location, Locator.to_locator_or_location(location_tuple))
        self.assertEqual(location, Locator.to_locator_or_location(list(location_tuple)))
        self.assertEqual(location, Locator.to_locator_or_location(location.dict()))

        locator = BlockUsageLocator(package_id='foo.bar', branch='alpha', block_id='deep')
        self.assertEqual(locator, Locator.to_locator_or_location(locator))
        self.assertEqual(locator.as_course_locator(), Locator.to_locator_or_location(locator.as_course_locator()))
        self.assertEqual(location, Locator.to_locator_or_location(location.url()))
        self.assertEqual(locator, Locator.to_locator_or_location(locator.url()))
        self.assertEqual(locator, Locator.to_locator_or_location(locator.__dict__))

        asset_location = Location(['c4x', 'mit', 'eecs.6002x', 'asset', 'selfie.jpeg'])
        self.assertEqual(asset_location, Locator.to_locator_or_location(asset_location))
        self.assertEqual(asset_location, Locator.to_locator_or_location(asset_location.url()))

        def_location_url = "defx://version/" + '{:024x}'.format(random.randrange(16 ** 24))
        self.assertEqual(DefinitionLocator(def_location_url), Locator.to_locator_or_location(def_location_url))

        with self.assertRaises(ValueError):
            Locator.to_locator_or_location(22)
        with self.assertRaises(ValueError):
            Locator.to_locator_or_location("hello.world.not.a.url")
        self.assertIsNone(Locator.parse_url("unknown://foo.bar/baz"))
开发者ID:Caesar73,项目名称:edx-platform,代码行数:30,代码来源:test_locators.py

示例3: test_update_children

    def test_update_children(self):
        """
        test updating an item's children ensuring the definition doesn't version but the course does if it should
        """
        locator = BlockUsageLocator(course_id="GreekHero", usage_id="chapter3", branch='draft')
        block = modulestore().get_item(locator)
        pre_def_id = block.definition_locator.definition_id
        pre_version_guid = block.location.version_guid

        # reorder children
        self.assertGreater(len(block.children), 0, "meaningless test")
        moved_child = block.children.pop()
        block.save()  # decache model changes
        updated_problem = modulestore().update_item(block, 'childchanger')
        # check that course version changed and course's previous is the other one
        self.assertEqual(updated_problem.definition_locator.definition_id, pre_def_id)
        self.assertNotEqual(updated_problem.location.version_guid, pre_version_guid)
        self.assertEqual(updated_problem.children, block.children)
        self.assertNotIn(moved_child, updated_problem.children)
        locator.usage_id = "chapter1"
        other_block = modulestore().get_item(locator)
        other_block.children.append(moved_child)
        other_block.save()  # decache model changes
        other_updated = modulestore().update_item(other_block, 'childchanger')
        self.assertIn(moved_child, other_updated.children)
开发者ID:AzizYosofi,项目名称:edx-platform,代码行数:25,代码来源:test_split_modulestore.py

示例4: test_post_course_update

    def test_post_course_update(self):
        """
        Test that a user can successfully post on course updates and handouts of a course
        whose location in not in loc_mapper
        """
        # create a course via the view handler
        course_location = Location(['i4x', 'Org_1', 'Course_1', 'course', 'Run_1'])
        course_locator = loc_mapper().translate_location(
            course_location.course_id, course_location, False, True
        )
        self.client.ajax_post(
            course_locator.url_reverse('course'),
            {
                'org': course_location.org,
                'number': course_location.course,
                'display_name': 'test course',
                'run': course_location.name,
            }
        )

        branch = u'draft'
        version = None
        block = u'updates'
        updates_locator = BlockUsageLocator(
            package_id=course_location.course_id.replace('/', '.'), branch=branch, version_guid=version, block_id=block
        )

        content = u"Sample update"
        payload = {'content': content, 'date': 'January 8, 2013'}
        course_update_url = updates_locator.url_reverse('course_info_update')
        resp = self.client.ajax_post(course_update_url, payload)

        # check that response status is 200 not 400
        self.assertEqual(resp.status_code, 200)

        payload = json.loads(resp.content)
        self.assertHTMLEqual(payload['content'], content)

        # now test that calling translate_location returns a locator whose block_id is 'updates'
        updates_location = course_location.replace(category='course_info', name=block)
        updates_locator = loc_mapper().translate_location(course_location.course_id, updates_location)
        self.assertTrue(isinstance(updates_locator, BlockUsageLocator))
        self.assertEqual(updates_locator.block_id, block)

        # check posting on handouts
        block = u'handouts'
        handouts_locator = BlockUsageLocator(
            package_id=updates_locator.package_id, branch=updates_locator.branch, version_guid=version, block_id=block
        )
        course_handouts_url = handouts_locator.url_reverse('xblock')
        content = u"Sample handout"
        payload = {"data": content}
        resp = self.client.ajax_post(course_handouts_url, payload)

        # check that response status is 200 not 500
        self.assertEqual(resp.status_code, 200)

        payload = json.loads(resp.content)
        self.assertHTMLEqual(payload['data'], content)
开发者ID:BeiLuoShiMen,项目名称:edx-platform,代码行数:59,代码来源:test_course_updates.py

示例5: test_block_constructor

 def test_block_constructor(self):
     testurn = 'mit.eecs.6002x;published#HW3'
     expected_id = 'mit.eecs.6002x'
     expected_branch = 'published'
     expected_block_ref = 'HW3'
     testobj = BlockUsageLocator(course_id=testurn)
     self.check_block_locn_fields(testobj, 'test_block constructor',
                                  course_id=expected_id,
                                  branch=expected_branch,
                                  block=expected_block_ref)
     self.assertEqual(str(testobj), testurn)
     self.assertEqual(testobj.url(), 'edx://' + testurn)
开发者ID:burngeek8,项目名称:edx-platform,代码行数:12,代码来源:test_locators.py

示例6: grading_handler

def grading_handler(request, tag=None, course_id=None, branch=None, version_guid=None, block=None, grader_index=None):
    """
    Course Grading policy configuration
    GET
        html: get the page
        json no grader_index: get the CourseGrading model (graceperiod, cutoffs, and graders)
        json w/ grader_index: get the specific grader
    PUT
        json no grader_index: update the Course through the CourseGrading model
        json w/ grader_index: create or update the specific grader (create if index out of range)
    """
    locator = BlockUsageLocator(course_id=course_id, branch=branch, version_guid=version_guid, usage_id=block)
    if not has_access(request.user, locator):
        raise PermissionDenied()

    if 'text/html' in request.META.get('HTTP_ACCEPT', '') and request.method == 'GET':
        course_old_location = loc_mapper().translate_locator_to_location(locator)
        course_module = modulestore().get_item(course_old_location)
        course_details = CourseGradingModel.fetch(locator)

        return render_to_response('settings_graders.html', {
            'context_course': course_module,
            'course_locator': locator,
            'course_details': json.dumps(course_details, cls=CourseSettingsEncoder),
            'grading_url': locator.url_reverse('/settings/grading/'),
        })
    elif 'application/json' in request.META.get('HTTP_ACCEPT', ''):
        if request.method == 'GET':
            if grader_index is None:
                return JsonResponse(
                    CourseGradingModel.fetch(locator),
                    # encoder serializes dates, old locations, and instances
                    encoder=CourseSettingsEncoder
                )
            else:
                return JsonResponse(CourseGradingModel.fetch_grader(locator, grader_index))
        elif request.method in ('POST', 'PUT'):  # post or put, doesn't matter.
            # None implies update the whole model (cutoffs, graceperiod, and graders) not a specific grader
            if grader_index is None:
                return JsonResponse(
                    CourseGradingModel.update_from_json(locator, request.json),
                    encoder=CourseSettingsEncoder
                )
            else:
                return JsonResponse(
                    CourseGradingModel.update_grader_from_json(locator, request.json)
                )
        elif request.method == "DELETE" and grader_index is not None:
            CourseGradingModel.delete_grader(locator, grader_index)
            return JsonResponse()
开发者ID:e-ucm,项目名称:edx-platform,代码行数:50,代码来源:course.py

示例7: test_block_constructor

 def test_block_constructor(self):
     testurn = "mit.eecs.6002x" + BRANCH_PREFIX + "published" + BLOCK_PREFIX + "HW3"
     expected_id = "mit.eecs.6002x"
     expected_branch = "published"
     expected_block_ref = "HW3"
     testobj = BlockUsageLocator(course_id=testurn)
     self.check_block_locn_fields(
         testobj, "test_block constructor", course_id=expected_id, branch=expected_branch, block=expected_block_ref
     )
     self.assertEqual(str(testobj), testurn)
     self.assertEqual(testobj.url(), "edx://" + testurn)
     agnostic = testobj.version_agnostic()
     self.assertIsNone(agnostic.version_guid)
     self.check_block_locn_fields(
         agnostic, "test_block constructor", course_id=expected_id, branch=expected_branch, block=expected_block_ref
     )
开发者ID:rjsheperd,项目名称:edx-platform,代码行数:16,代码来源:test_locators.py

示例8: test_get_parents

 def test_get_parents(self):
     '''
     get_parent_locations(locator, [usage_id], [branch]): [BlockUsageLocator]
     '''
     locator = BlockUsageLocator(course_id="GreekHero", branch='draft', usage_id='chapter1')
     parents = modulestore().get_parent_locations(locator)
     self.assertEqual(len(parents), 1)
     self.assertEqual(parents[0].usage_id, 'head12345')
     self.assertEqual(parents[0].course_id, "GreekHero")
     locator.usage_id = 'chapter2'
     parents = modulestore().get_parent_locations(locator)
     self.assertEqual(len(parents), 1)
     self.assertEqual(parents[0].usage_id, 'head12345')
     locator.usage_id = 'nosuchblock'
     parents = modulestore().get_parent_locations(locator)
     self.assertEqual(len(parents), 0)
开发者ID:AzizYosofi,项目名称:edx-platform,代码行数:16,代码来源:test_split_modulestore.py

示例9: test_relative

 def test_relative(self):
     """
     Test making a relative usage locator.
     """
     package_id = 'mit.eecs-1'
     branch = 'foo'
     baseobj = CourseLocator(package_id=package_id, branch=branch)
     block_id = 'problem:with-colon~2'
     testobj = BlockUsageLocator.make_relative(baseobj, block_id)
     self.check_block_locn_fields(
         testobj, 'Cannot make relative to course', package_id=package_id, branch=branch, block=block_id
     )
     block_id = 'completely_different'
     testobj = BlockUsageLocator.make_relative(testobj, block_id)
     self.check_block_locn_fields(
         testobj, 'Cannot make relative to block usage', package_id=package_id, branch=branch, block=block_id
     )
开发者ID:Caesar73,项目名称:edx-platform,代码行数:17,代码来源:test_locators.py

示例10: test_block_constructor

 def test_block_constructor(self):
     testurn = 'mit.eecs.6002x/' + BRANCH_PREFIX + 'published/' + BLOCK_PREFIX + 'HW3'
     expected_id = 'mit.eecs.6002x'
     expected_branch = 'published'
     expected_block_ref = 'HW3'
     testobj = BlockUsageLocator(package_id=testurn)
     self.check_block_locn_fields(testobj, 'test_block constructor',
                                  package_id=expected_id,
                                  branch=expected_branch,
                                  block=expected_block_ref)
     self.assertEqual(str(testobj), testurn)
     self.assertEqual(testobj.url(), 'edx://' + testurn)
     agnostic = testobj.version_agnostic()
     self.assertIsNone(agnostic.version_guid)
     self.check_block_locn_fields(agnostic, 'test_block constructor',
                                  package_id=expected_id,
                                  branch=expected_branch,
                                  block=expected_block_ref)
开发者ID:Caesar73,项目名称:edx-platform,代码行数:18,代码来源:test_locators.py

示例11: test_relative

 def test_relative(self):
     """
     Test making a relative usage locator.
     """
     org = 'mit.eecs'
     offering = '1'
     branch = 'foo'
     baseobj = CourseLocator(org=org, offering=offering, branch=branch)
     block_id = 'problem:with-colon~2'
     testobj = BlockUsageLocator.make_relative(baseobj, 'problem', block_id)
     self.check_block_locn_fields(
         testobj, org=org, offering=offering, branch=branch, block=block_id
     )
     block_id = 'completely_different'
     testobj = BlockUsageLocator.make_relative(testobj, 'problem', block_id)
     self.check_block_locn_fields(
         testobj, org=org, offering=offering, branch=branch, block=block_id
     )
开发者ID:aemilcar,项目名称:edx-platform,代码行数:18,代码来源:test_locators.py

示例12: test_block_generations

    def test_block_generations(self):
        """
        Test get_block_generations
        """
        test_course = persistent_factories.PersistentCourseFactory.create(
            offering='history.hist101', org='edu.harvard',
            display_name='history test course',
            user_id='testbot'
        )
        chapter = persistent_factories.ItemFactory.create(display_name='chapter 1',
            parent_location=test_course.location, user_id='testbot')
        sub = persistent_factories.ItemFactory.create(display_name='subsection 1',
            parent_location=chapter.location, user_id='testbot', category='vertical')
        first_problem = persistent_factories.ItemFactory.create(
            display_name='problem 1', parent_location=sub.location, user_id='testbot', category='problem',
            data="<problem></problem>"
        )
        first_problem.max_attempts = 3
        first_problem.save()  # decache the above into the kvs
        updated_problem = modulestore('split').update_item(first_problem, '**replace_user**')
        self.assertIsNotNone(updated_problem.previous_version)
        self.assertEqual(updated_problem.previous_version, first_problem.update_version)
        self.assertNotEqual(updated_problem.update_version, first_problem.update_version)
        updated_loc = modulestore('split').delete_item(updated_problem.location, 'testbot', delete_children=True)

        second_problem = persistent_factories.ItemFactory.create(
            display_name='problem 2',
            parent_location=BlockUsageLocator.make_relative(
                updated_loc, block_type='problem', block_id=sub.location.block_id
            ),
            user_id='testbot', category='problem',
            data="<problem></problem>"
        )

        # course root only updated 2x
        version_history = modulestore('split').get_block_generations(test_course.location)
        self.assertEqual(version_history.locator.version_guid, test_course.location.version_guid)
        self.assertEqual(len(version_history.children), 1)
        self.assertEqual(version_history.children[0].children, [])
        self.assertEqual(version_history.children[0].locator.version_guid, chapter.location.version_guid)

        # sub changed on add, add problem, delete problem, add problem in strict linear seq
        version_history = modulestore('split').get_block_generations(sub.location)
        self.assertEqual(len(version_history.children), 1)
        self.assertEqual(len(version_history.children[0].children), 1)
        self.assertEqual(len(version_history.children[0].children[0].children), 1)
        self.assertEqual(len(version_history.children[0].children[0].children[0].children), 0)

        # first and second problem may show as same usage_id; so, need to ensure their histories are right
        version_history = modulestore('split').get_block_generations(updated_problem.location)
        self.assertEqual(version_history.locator.version_guid, first_problem.location.version_guid)
        self.assertEqual(len(version_history.children), 1)  # updated max_attempts
        self.assertEqual(len(version_history.children[0].children), 0)

        version_history = modulestore('split').get_block_generations(second_problem.location)
        self.assertNotEqual(version_history.locator.version_guid, first_problem.location.version_guid)
开发者ID:PaoloC68,项目名称:edx-platform,代码行数:56,代码来源:test_crud.py

示例13: test_block_constructor_url_version_prefix

 def test_block_constructor_url_version_prefix(self):
     test_id_loc = "519665f6223ebd6980884f2b"
     testobj = BlockUsageLocator(url="edx://mit.eecs.6002x" + VERSION_PREFIX + test_id_loc + BLOCK_PREFIX + "lab2")
     self.check_block_locn_fields(
         testobj,
         "error parsing URL with version and block",
         course_id="mit.eecs.6002x",
         block="lab2",
         version_guid=ObjectId(test_id_loc),
     )
     agnostic = testobj.version_agnostic()
     self.check_block_locn_fields(
         agnostic,
         "error parsing URL with version and block",
         block="lab2",
         course_id=None,
         version_guid=ObjectId(test_id_loc),
     )
     self.assertIsNone(agnostic.course_id)
开发者ID:rjsheperd,项目名称:edx-platform,代码行数:19,代码来源:test_locators.py

示例14: test_block_constructor_url_version_prefix

 def test_block_constructor_url_version_prefix(self):
     test_id_loc = '519665f6223ebd6980884f2b'
     testobj = BlockUsageLocator(
         url='edx://mit.eecs.6002x/{}{}/{}lab2'.format(VERSION_PREFIX, test_id_loc, BLOCK_PREFIX)
     )
     self.check_block_locn_fields(
         testobj, 'error parsing URL with version and block',
         package_id='mit.eecs.6002x',
         block='lab2',
         version_guid=ObjectId(test_id_loc)
     )
     agnostic = testobj.version_agnostic()
     self.check_block_locn_fields(
         agnostic, 'error parsing URL with version and block',
         block='lab2',
         package_id=None,
         version_guid=ObjectId(test_id_loc)
     )
     self.assertIsNone(agnostic.package_id)
开发者ID:Caesar73,项目名称:edx-platform,代码行数:19,代码来源:test_locators.py

示例15: test_ensure_fully_specd

    def test_ensure_fully_specd(self):
        '''
        Test constructor and property accessors.
        '''
        raise SkipTest()
        self.assertRaises(InsufficientSpecificationError,
                          BlockUsageLocator.ensure_fully_specified, BlockUsageLocator())

        # url inits
        testurn = 'edx://org/course/category/name'
        self.assertRaises(InvalidLocationError,
                          BlockUsageLocator.ensure_fully_specified, testurn)
        testurn = 'unknown/versionid/blockid'
        self.assertRaises(InvalidLocationError,
                          BlockUsageLocator.ensure_fully_specified, testurn)

        testurn = 'cvx/versionid'
        self.assertRaises(InsufficientSpecificationError,
                          BlockUsageLocator.ensure_fully_specified, testurn)

        testurn = 'cvx/versionid/'
        self.assertRaises(InsufficientSpecificationError,
                          BlockUsageLocator.ensure_fully_specified, testurn)

        testurn = 'cvx/versionid/blockid'
        self.assertIsInstance(BlockUsageLocator.ensure_fully_specified(testurn),
                              BlockUsageLocator, testurn)

        testurn = 'cvx/versionid/blockid/extraneousstuff?including=args'
        self.assertIsInstance(BlockUsageLocator.ensure_fully_specified(testurn),
                              BlockUsageLocator, testurn)

        testurn = 'cvx://versionid/blockid'
        self.assertIsInstance(BlockUsageLocator.ensure_fully_specified(testurn),
                              BlockUsageLocator, testurn)

        testurn = 'crx/courseid/blockid'
        self.assertIsInstance(BlockUsageLocator.ensure_fully_specified(testurn),
                              BlockUsageLocator, testurn)

        testurn = 'crx/[email protected]/blockid'
        self.assertIsInstance(BlockUsageLocator.ensure_fully_specified(testurn),
                              BlockUsageLocator, testurn)
开发者ID:NakarinTalikan,项目名称:edx-platform,代码行数:43,代码来源:test_locators.py


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