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


Python SlashSeparatedCourseKey.make_usage_key方法代码示例

本文整理汇总了Python中xmodule.modulestore.locations.SlashSeparatedCourseKey.make_usage_key方法的典型用法代码示例。如果您正苦于以下问题:Python SlashSeparatedCourseKey.make_usage_key方法的具体用法?Python SlashSeparatedCourseKey.make_usage_key怎么用?Python SlashSeparatedCourseKey.make_usage_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xmodule.modulestore.locations.SlashSeparatedCourseKey的用法示例。


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

示例1: test_rewrite_reference_list

# 需要导入模块: from xmodule.modulestore.locations import SlashSeparatedCourseKey [as 别名]
# 或者: from xmodule.modulestore.locations.SlashSeparatedCourseKey import make_usage_key [as 别名]
 def test_rewrite_reference_list(self):
     module_store = modulestore('direct')
     target_course_id = SlashSeparatedCourseKey('testX', 'conditional_copy', 'copy_run')
     import_from_xml(
         module_store,
         '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', 'copy_run')
     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:PaoloC68,项目名称:edx-platform,代码行数:30,代码来源:test_import.py

示例2: TestJumpTo

# 需要导入模块: from xmodule.modulestore.locations import SlashSeparatedCourseKey [as 别名]
# 或者: from xmodule.modulestore.locations.SlashSeparatedCourseKey import make_usage_key [as 别名]
class TestJumpTo(TestCase):
    """
    Check the jumpto link for a course.
    """

    def setUp(self):
        # Use toy course from XML
        self.course_key = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')

    def test_jumpto_invalid_location(self):
        location = self.course_key.make_usage_key(None, 'NoSuchPlace')
        # This is fragile, but unfortunately the problem is that within the LMS we
        # can't use the reverse calls from the CMS
        jumpto_url = '{0}/{1}/jump_to/{2}'.format('/courses', self.course_key.to_deprecated_string(), location.to_deprecated_string())
        response = self.client.get(jumpto_url)
        self.assertEqual(response.status_code, 404)

    def test_jumpto_from_chapter(self):
        location = self.course_key.make_usage_key('chapter', 'Overview')
        jumpto_url = '{0}/{1}/jump_to/{2}'.format('/courses', self.course_key.to_deprecated_string(), location.to_deprecated_string())
        expected = 'courses/edX/toy/2012_Fall/courseware/Overview/'
        response = self.client.get(jumpto_url)
        self.assertRedirects(response, expected, status_code=302, target_status_code=302)

    def test_jumpto_id(self):
        jumpto_url = '{0}/{1}/jump_to_id/{2}'.format('/courses', self.course_key.to_deprecated_string(), 'Overview')
        expected = 'courses/edX/toy/2012_Fall/courseware/Overview/'
        response = self.client.get(jumpto_url)
        self.assertRedirects(response, expected, status_code=302, target_status_code=302)

    def test_jumpto_id_invalid_location(self):
        location = Location('edX', 'toy', 'NoSuchPlace', None, None, None)
        jumpto_url = '{0}/{1}/jump_to_id/{2}'.format('/courses', self.course_key.to_deprecated_string(), location.to_deprecated_string())
        response = self.client.get(jumpto_url)
        self.assertEqual(response.status_code, 404)
开发者ID:PaoloC68,项目名称:edx-platform,代码行数:37,代码来源:test_views.py

示例3: TestInstructorEnrollmentStudentModule

# 需要导入模块: from xmodule.modulestore.locations import SlashSeparatedCourseKey [as 别名]
# 或者: from xmodule.modulestore.locations.SlashSeparatedCourseKey import make_usage_key [as 别名]
class TestInstructorEnrollmentStudentModule(TestCase):
    """ Test student module manipulations. """
    def setUp(self):
        self.course_key = SlashSeparatedCourseKey('fake', 'course', 'id')

    def test_reset_student_attempts(self):
        user = UserFactory()
        msk = self.course_key.make_usage_key('dummy', 'module')
        original_state = json.dumps({'attempts': 32, 'otherstuff': 'alsorobots'})
        StudentModule.objects.create(student=user, course_id=self.course_key, module_state_key=msk, state=original_state)
        # lambda to reload the module state from the database
        module = lambda: StudentModule.objects.get(student=user, course_id=self.course_key, module_state_key=msk)
        self.assertEqual(json.loads(module().state)['attempts'], 32)
        reset_student_attempts(self.course_key, user, msk)
        self.assertEqual(json.loads(module().state)['attempts'], 0)

    def test_delete_student_attempts(self):
        user = UserFactory()
        msk = self.course_key.make_usage_key('dummy', 'module')
        original_state = json.dumps({'attempts': 32, 'otherstuff': 'alsorobots'})
        StudentModule.objects.create(student=user, course_id=self.course_key, module_state_key=msk, state=original_state)
        self.assertEqual(StudentModule.objects.filter(student=user, course_id=self.course_key, module_state_key=msk).count(), 1)
        reset_student_attempts(self.course_key, user, msk, delete_module=True)
        self.assertEqual(StudentModule.objects.filter(student=user, course_id=self.course_key, module_state_key=msk).count(), 0)

    def test_delete_submission_scores(self):
        user = UserFactory()
        problem_location = self.course_key.make_usage_key('dummy', 'module')

        # Create a student module for the user
        StudentModule.objects.create(
            student=user,
            course_id=self.course_key,
            module_state_key=problem_location,
            state=json.dumps({})
        )

        # Create a submission and score for the student using the submissions API
        student_item = {
            'student_id': anonymous_id_for_user(user, self.course_key),
            'course_id': self.course_key.to_deprecated_string(),
            'item_id': problem_location.to_deprecated_string(),
            'item_type': 'openassessment'
        }
        submission = sub_api.create_submission(student_item, 'test answer')
        sub_api.set_score(submission['uuid'], 1, 2)

        # Delete student state using the instructor dash
        reset_student_attempts(
            self.course_key, user, problem_location,
            delete_module=True
        )

        # Verify that the student's scores have been reset in the submissions API
        score = sub_api.get_score(student_item)
        self.assertIs(score, None)
开发者ID:aemilcar,项目名称:edx-platform,代码行数:58,代码来源:test_enrollment.py

示例4: lms_link_test

# 需要导入模块: from xmodule.modulestore.locations import SlashSeparatedCourseKey [as 别名]
# 或者: from xmodule.modulestore.locations.SlashSeparatedCourseKey import make_usage_key [as 别名]
    def lms_link_test(self):
        """ Tests get_lms_link_for_item. """
        course_key = SlashSeparatedCourseKey("mitX", "101", "test")
        location = course_key.make_usage_key("vertical", "contacting_us")
        link = utils.get_lms_link_for_item(location, False)
        self.assertEquals(link, "//localhost:8000/courses/mitX/101/test/jump_to/i4x://mitX/101/vertical/contacting_us")

        # test preview
        link = utils.get_lms_link_for_item(location, True)
        self.assertEquals(link, "//preview/courses/mitX/101/test/jump_to/i4x://mitX/101/vertical/contacting_us")

        # now test with the course' location
        location = course_key.make_usage_key("course", "test")
        link = utils.get_lms_link_for_item(location)
        self.assertEquals(link, "//localhost:8000/courses/mitX/101/test/jump_to/i4x://mitX/101/course/test")
开发者ID:hmcmooc,项目名称:muddx-platform,代码行数:17,代码来源:test_utils.py

示例5: SetupTestErrorModules

# 需要导入模块: from xmodule.modulestore.locations import SlashSeparatedCourseKey [as 别名]
# 或者: from xmodule.modulestore.locations.SlashSeparatedCourseKey import make_usage_key [as 别名]
class SetupTestErrorModules():
    def setUp(self):
        self.system = get_test_system()
        self.course_id = SlashSeparatedCourseKey('org', 'course', 'run')
        self.location = self.course_id.make_usage_key('foo', 'bar')
        self.valid_xml = u"<problem>ABC \N{SNOWMAN}</problem>"
        self.error_msg = "Error"
开发者ID:PaoloC68,项目名称:edx-platform,代码行数:9,代码来源:test_error_module.py

示例6: test_delete_course_map

# 需要导入模块: from xmodule.modulestore.locations import SlashSeparatedCourseKey [as 别名]
# 或者: from xmodule.modulestore.locations.SlashSeparatedCourseKey import make_usage_key [as 别名]
    def test_delete_course_map(self):
        """
        Test that course location is properly remove from loc_mapper and cache when course is deleted
        """
        org = u'foo_org'
        course = u'bar_course'
        run = u'baz_run'
        course_location = SlashSeparatedCourseKey(org, course, run)
        loc_mapper().create_map_entry(course_location)
        # pylint: disable=protected-access
        entry = loc_mapper().location_map.find_one({
            '_id': loc_mapper()._construct_course_son(course_location)
        })
        self.assertIsNotNone(entry, 'Entry not found in loc_mapper')
        self.assertEqual(entry['offering'], u'{1}.{2}'.format(org, course, run))

        # now delete course location from loc_mapper and cache and test that course location no longer
        # exists in loca_mapper and cache
        loc_mapper().delete_course_mapping(course_location)
        # pylint: disable=protected-access
        entry = loc_mapper().location_map.find_one({
            '_id': loc_mapper()._construct_course_son(course_location)
        })
        self.assertIsNone(entry, 'Entry found in loc_mapper')
        # pylint: disable=protected-access
        cached_value = loc_mapper()._get_location_from_cache(course_location.make_usage_key('course', run))
        self.assertIsNone(cached_value, 'course_locator found in cache')
        # pylint: disable=protected-access
        cached_value = loc_mapper()._get_course_location_from_cache(course_location)
        self.assertIsNone(cached_value, 'Entry found in cache')
开发者ID:PaoloC68,项目名称:edx-platform,代码行数:32,代码来源:test_location_mapper.py

示例7: test_rewrite_reference

# 需要导入模块: from xmodule.modulestore.locations import SlashSeparatedCourseKey [as 别名]
# 或者: from xmodule.modulestore.locations.SlashSeparatedCourseKey import make_usage_key [as 别名]
 def test_rewrite_reference(self):
     module_store = modulestore('direct')
     target_course_id = SlashSeparatedCourseKey('testX', 'peergrading_copy', 'copy_run')
     import_from_xml(
         module_store,
         'common/test/data/',
         ['open_ended'],
         target_course_id=target_course_id
     )
     peergrading_module = module_store.get_item(
         target_course_id.make_usage_key('peergrading', 'PeerGradingLinked')
     )
     self.assertIsNotNone(peergrading_module)
     self.assertEqual(
         target_course_id.make_usage_key('combinedopenended', 'SampleQuestion'),
         peergrading_module.link_to_location
     )
开发者ID:PaoloC68,项目名称:edx-platform,代码行数:19,代码来源:test_import.py

示例8: setUp

# 需要导入模块: from xmodule.modulestore.locations import SlashSeparatedCourseKey [as 别名]
# 或者: from xmodule.modulestore.locations.SlashSeparatedCourseKey import make_usage_key [as 别名]
 def setUp(self):
     course_key = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')
     self.course = course_key.make_usage_key('course', course_key.run)
     self.anonymous_user = AnonymousUserFactory()
     self.student = UserFactory()
     self.global_staff = UserFactory(is_staff=True)
     self.course_staff = StaffFactory(course_key=self.course.course_key)
     self.course_instructor = InstructorFactory(course_key=self.course.course_key)
开发者ID:aemilcar,项目名称:edx-platform,代码行数:10,代码来源:test_access.py

示例9: i_click_on_error_dialog

# 需要导入模块: from xmodule.modulestore.locations import SlashSeparatedCourseKey [as 别名]
# 或者: from xmodule.modulestore.locations.SlashSeparatedCourseKey import make_usage_key [as 别名]
def i_click_on_error_dialog(step):
    world.click_link_by_text('Correct failed component')
    assert_true(world.css_html("span.inline-error").startswith("Problem i4x://MITx/999/problem"))
    course_key = SlashSeparatedCourseKey("MITx", "999", "Robot_Super_Course")
    # we don't know the actual ID of the vertical. So just check that we did go to a
    # vertical page in the course (there should only be one).
    vertical_usage_key = course_key.make_usage_key("vertical", "")
    vertical_url = reverse_usage_url('unit_handler', vertical_usage_key)
    assert_equal(1, world.browser.url.count(vertical_url))
开发者ID:PaoloC68,项目名称:edx-platform,代码行数:11,代码来源:course-export.py

示例10: setUp

# 需要导入模块: from xmodule.modulestore.locations import SlashSeparatedCourseKey [as 别名]
# 或者: from xmodule.modulestore.locations.SlashSeparatedCourseKey import make_usage_key [as 别名]
 def setUp(self):
     system = get_test_descriptor_system()
     course_key = SlashSeparatedCourseKey('org', 'course', 'run')
     usage_key = course_key.make_usage_key('video', 'name')
     self.descriptor = system.construct_xblock_from_class(
         VideoDescriptor,
         scope_ids=ScopeIds(None, None, usage_key, usage_key),
         field_data=DictFieldData({}),
     )
     self.descriptor.runtime.handler_url = MagicMock()
开发者ID:PaoloC68,项目名称:edx-platform,代码行数:12,代码来源:test_video_mongo.py

示例11: setup_xml_course

# 需要导入模块: from xmodule.modulestore.locations import SlashSeparatedCourseKey [as 别名]
# 或者: from xmodule.modulestore.locations.SlashSeparatedCourseKey import make_usage_key [as 别名]
    def setup_xml_course(self):
        """
        Define the XML backed course to use.
        Toy courses are already loaded in XML and mixed modulestores.
        """
        course_key = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')
        location = course_key.make_usage_key('chapter', 'Overview')
        descriptor = modulestore().get_item(location)

        self.module = self._get_module(course_key, descriptor, location)
开发者ID:PaoloC68,项目名称:edx-platform,代码行数:12,代码来源:test_module_render.py

示例12: test_invalid_chars_location

# 需要导入模块: from xmodule.modulestore.locations import SlashSeparatedCourseKey [as 别名]
# 或者: from xmodule.modulestore.locations.SlashSeparatedCourseKey import make_usage_key [as 别名]
 def test_invalid_chars_location(self):
     """
     Test that the location constructor fails if given invalid chars
     """
     course_key = SlashSeparatedCourseKey(u'org.dept-1%2', u'course.sub-2%3', u'run.faster-4%5')
     valid_base = course_key.make_usage_key('tomato-again%9', 'block-head:sub-4%9')
     for key in SlashSeparatedCourseKey.KEY_FIELDS:
         with self.assertRaises(InvalidKeyError):
             # this ends up calling the constructor where the legality check should occur
             valid_base.replace(**{key: u'funny thing'})
开发者ID:PaoloC68,项目名称:edx-platform,代码行数:12,代码来源:test_location.py

示例13: test_rewrite_reference_value_dict

# 需要导入模块: from xmodule.modulestore.locations import SlashSeparatedCourseKey [as 别名]
# 或者: from xmodule.modulestore.locations.SlashSeparatedCourseKey import make_usage_key [as 别名]
 def test_rewrite_reference_value_dict(self):
     module_store = modulestore('direct')
     target_course_id = SlashSeparatedCourseKey('testX', 'split_test_copy', 'copy_run')
     import_from_xml(
         module_store,
         'common/test/data/',
         ['split_test_module'],
         target_course_id=target_course_id
     )
     split_test_module = module_store.get_item(
         target_course_id.make_usage_key('split_test', 'split1')
     )
     self.assertIsNotNone(split_test_module)
     self.assertEqual(
         {
             "0": target_course_id.make_usage_key('vertical', 'sample_0'),
             "2": target_course_id.make_usage_key('vertical', 'sample_2'),
         },
         split_test_module.group_id_to_child,
     )
开发者ID:PaoloC68,项目名称:edx-platform,代码行数:22,代码来源:test_import.py

示例14: create_course

# 需要导入模块: from xmodule.modulestore.locations import SlashSeparatedCourseKey [as 别名]
# 或者: from xmodule.modulestore.locations.SlashSeparatedCourseKey import make_usage_key [as 别名]
    def create_course(self, org, offering, user_id=None, fields=None, **kwargs):
        """
        Creates and returns the course.

        Args:
            org (str): the organization that owns the course
            offering (str): the name of the course offering
            user_id: id of the user creating the course
            fields (dict): Fields to set on the course at initialization
            kwargs: Any optional arguments understood by a subset of modulestores to customize instantiation

        Returns: a CourseDescriptor

        Raises:
            InvalidLocationError: If a course with the same org and offering already exists
        """

        course, _, run = offering.partition('/')
        course_id = SlashSeparatedCourseKey(org, course, run)

        # Check if a course with this org/course has been defined before (case-insensitive)
        course_search_location = SON([
            ('_id.tag', 'i4x'),
            ('_id.org', re.compile(u'^{}$'.format(course_id.org), re.IGNORECASE)),
            ('_id.course', re.compile(u'^{}$'.format(course_id.course), re.IGNORECASE)),
            ('_id.category', 'course'),
        ])
        courses = self.collection.find(course_search_location, fields=('_id'))
        if courses.count() > 0:
            raise InvalidLocationError(
                "There are already courses with the given org and course id: {}".format([
                    course['_id'] for course in courses
                ]))

        location = course_id.make_usage_key('course', course_id.run)
        course = self.create_and_save_xmodule(location, fields=fields, **kwargs)

        # clone a default 'about' overview module as well
        about_location = location.replace(
            category='about',
            name='overview'
        )
        overview_template = AboutDescriptor.get_template('overview.yaml')
        self.create_and_save_xmodule(
            about_location,
            system=course.system,
            definition_data=overview_template.get('data')
        )

        return course
开发者ID:PaoloC68,项目名称:edx-platform,代码行数:52,代码来源:base.py

示例15: check_path_to_location

# 需要导入模块: from xmodule.modulestore.locations import SlashSeparatedCourseKey [as 别名]
# 或者: from xmodule.modulestore.locations.SlashSeparatedCourseKey import make_usage_key [as 别名]
def check_path_to_location(modulestore):
    """
    Make sure that path_to_location works: should be passed a modulestore
    with the toy and simple courses loaded.
    """
    course_id = SlashSeparatedCourseKey("edX", "toy", "2012_Fall")

    should_work = (
        (course_id.make_usage_key('video', 'Welcome'),
         (course_id, "Overview", "Welcome", None)),
        (course_id.make_usage_key('chapter', 'Overview'),
         (course_id, "Overview", None, None)),
    )

    for location, expected in should_work:
        assert_equals(path_to_location(modulestore, location), expected)

    not_found = (
        course_id.make_usage_key('video', 'WelcomeX'),
        course_id.make_usage_key('course', 'NotHome'),
    )
    for location in not_found:
        with assert_raises(ItemNotFoundError):
            path_to_location(modulestore, location)
开发者ID:PaoloC68,项目名称:edx-platform,代码行数:26,代码来源:test_modulestore.py


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