本文整理汇总了Python中xmodule.modulestore.locator.CourseLocator类的典型用法代码示例。如果您正苦于以下问题:Python CourseLocator类的具体用法?Python CourseLocator怎么用?Python CourseLocator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CourseLocator类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_course_constructor_course_id_no_revision
def test_course_constructor_course_id_no_revision(self):
testurn = 'edu.mit.eecs.6002x'
testobj = CourseLocator(course_id=testurn)
self.check_course_locn_fields(testobj, 'course_id', course_id=testurn)
self.assertEqual(testobj.course_id, testurn)
self.assertEqual(str(testobj), testurn)
self.assertEqual(testobj.url(), 'edx://' + testurn)
开发者ID:NakarinTalikan,项目名称:edx-platform,代码行数:7,代码来源:test_locators.py
示例2: test_course_constructor_package_id_no_branch
def test_course_constructor_package_id_no_branch(self):
org = 'mit.eecs'
offering = '6002x'
testurn = '{}+{}'.format(org, offering)
testobj = CourseLocator(org=org, offering=offering)
self.check_course_locn_fields(testobj, org=org, offering=offering)
self.assertEqual(testobj._to_string(), testurn)
开发者ID:aemilcar,项目名称:edx-platform,代码行数:7,代码来源:test_locators.py
示例3: test_course_constructor_package_id_no_branch
def test_course_constructor_package_id_no_branch(self):
testurn = 'mit.eecs.6002x'
testobj = CourseLocator(package_id=testurn)
self.check_course_locn_fields(testobj, 'package_id', package_id=testurn)
self.assertEqual(testobj.package_id, testurn)
self.assertEqual(str(testobj), testurn)
self.assertEqual(testobj.url(), 'edx://' + testurn)
开发者ID:Caesar73,项目名称:edx-platform,代码行数:7,代码来源:test_locators.py
示例4: test_course_constructor_course_id_no_branch
def test_course_constructor_course_id_no_branch(self):
testurn = "mit.eecs.6002x"
testobj = CourseLocator(course_id=testurn)
self.check_course_locn_fields(testobj, "course_id", course_id=testurn)
self.assertEqual(testobj.course_id, testurn)
self.assertEqual(str(testobj), testurn)
self.assertEqual(testobj.url(), "edx://" + testurn)
开发者ID:rjsheperd,项目名称:edx-platform,代码行数:7,代码来源:test_locators.py
示例5: test_course_constructor_course_id_separate_branch
def test_course_constructor_course_id_separate_branch(self):
test_id = "mit.eecs.6002x"
test_branch = "published"
expected_urn = "mit.eecs.6002x" + BRANCH_PREFIX + "published"
testobj = CourseLocator(course_id=test_id, branch=test_branch)
self.check_course_locn_fields(testobj, "course_id with separate branch", course_id=test_id, branch=test_branch)
self.assertEqual(testobj.course_id, test_id)
self.assertEqual(testobj.branch, test_branch)
self.assertEqual(str(testobj), expected_urn)
self.assertEqual(testobj.url(), "edx://" + expected_urn)
开发者ID:rjsheperd,项目名称:edx-platform,代码行数:10,代码来源:test_locators.py
示例6: test_course_constructor_course_id_separate_revision
def test_course_constructor_course_id_separate_revision(self):
test_id = 'edu.mit.eecs.6002x'
test_revision = 'published'
expected_urn = 'edu.mit.eecs.6002x;published'
testobj = CourseLocator(course_id=test_id, revision=test_revision)
self.check_course_locn_fields(testobj, 'course_id with separate revision',
course_id=test_id,
revision=test_revision,
)
self.assertEqual(testobj.course_id, test_id)
self.assertEqual(testobj.revision, test_revision)
self.assertEqual(str(testobj), expected_urn)
self.assertEqual(testobj.url(), 'edx://' + expected_urn)
开发者ID:NakarinTalikan,项目名称:edx-platform,代码行数:13,代码来源:test_locators.py
示例7: test_course_constructor_course_id_with_branch
def test_course_constructor_course_id_with_branch(self):
testurn = 'mit.eecs.6002x/' + BRANCH_PREFIX + 'published'
expected_id = 'mit.eecs.6002x'
expected_branch = 'published'
testobj = CourseLocator(course_id=testurn)
self.check_course_locn_fields(testobj, 'course_id with branch',
course_id=expected_id,
branch=expected_branch,
)
self.assertEqual(testobj.course_id, expected_id)
self.assertEqual(testobj.branch, expected_branch)
self.assertEqual(str(testobj), testurn)
self.assertEqual(testobj.url(), 'edx://' + testurn)
开发者ID:DavidGrahamFL,项目名称:edx-platform,代码行数:13,代码来源:test_locators.py
示例8: test_course_constructor_package_id_separate_branch
def test_course_constructor_package_id_separate_branch(self):
test_id = 'mit.eecs.6002x'
test_branch = 'published'
expected_urn = 'mit.eecs.6002x/' + BRANCH_PREFIX + 'published'
testobj = CourseLocator(package_id=test_id, branch=test_branch)
self.check_course_locn_fields(testobj, 'package_id with separate branch',
package_id=test_id,
branch=test_branch,
)
self.assertEqual(testobj.package_id, test_id)
self.assertEqual(testobj.branch, test_branch)
self.assertEqual(str(testobj), expected_urn)
self.assertEqual(testobj.url(), 'edx://' + expected_urn)
开发者ID:Caesar73,项目名称:edx-platform,代码行数:13,代码来源:test_locators.py
示例9: test_course_constructor_package_id_separate_branch
def test_course_constructor_package_id_separate_branch(self):
org = 'mit.eecs'
offering = '6002x'
test_branch = 'published'
expected_urn = '{}+{}+{}+{}'.format(org, offering, CourseLocator.BRANCH_PREFIX, test_branch)
testobj = CourseLocator(org=org, offering=offering, branch=test_branch)
self.check_course_locn_fields(
testobj,
org=org,
offering=offering,
branch=test_branch,
)
self.assertEqual(testobj.branch, test_branch)
self.assertEqual(testobj._to_string(), expected_urn)
开发者ID:aemilcar,项目名称:edx-platform,代码行数:14,代码来源:test_locators.py
示例10: test_get_parents
def test_get_parents(self):
'''
get_parent_locations(locator, [usage_id], [branch]): [BlockUsageLocator]
'''
locator = CourseLocator(course_id="GreekHero", branch='draft')
parents = modulestore().get_parent_locations(locator, usage_id='chapter1')
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')
parents = modulestore().get_parent_locations(locator, usage_id='nosuchblock')
self.assertEqual(len(parents), 0)
开发者ID:burngeek8,项目名称:edx-platform,代码行数:15,代码来源:test_split_modulestore.py
示例11: test_course_constructor_course_id_repeated_branch
def test_course_constructor_course_id_repeated_branch(self):
"""
The same branch appears in the course_id and the branch field.
"""
test_id = "mit.eecs.6002x" + BRANCH_PREFIX + "published"
test_branch = "published"
expected_id = "mit.eecs.6002x"
expected_urn = test_id
testobj = CourseLocator(course_id=test_id, branch=test_branch)
self.check_course_locn_fields(
testobj, "course_id with repeated branch", course_id=expected_id, branch=test_branch
)
self.assertEqual(testobj.course_id, expected_id)
self.assertEqual(testobj.branch, test_branch)
self.assertEqual(str(testobj), expected_urn)
self.assertEqual(testobj.url(), "edx://" + expected_urn)
开发者ID:rjsheperd,项目名称:edx-platform,代码行数:16,代码来源:test_locators.py
示例12: test_course_constructor_version_guid
def test_course_constructor_version_guid(self):
# generate a random location
test_id_1 = ObjectId()
test_id_1_loc = str(test_id_1)
testobj_1 = CourseLocator(version_guid=test_id_1)
self.check_course_locn_fields(testobj_1, version_guid=test_id_1)
self.assertEqual(str(testobj_1.version_guid), test_id_1_loc)
self.assertEqual(testobj_1._to_string(), u'+'.join((testobj_1.VERSION_PREFIX, test_id_1_loc)))
# Test using a given string
test_id_2_loc = '519665f6223ebd6980884f2b'
test_id_2 = ObjectId(test_id_2_loc)
testobj_2 = CourseLocator(version_guid=test_id_2)
self.check_course_locn_fields(testobj_2, version_guid=test_id_2)
self.assertEqual(str(testobj_2.version_guid), test_id_2_loc)
self.assertEqual(testobj_2._to_string(), u'+'.join((testobj_2.VERSION_PREFIX, test_id_2_loc)))
开发者ID:aemilcar,项目名称:edx-platform,代码行数:16,代码来源:test_locators.py
示例13: test_course_constructor_course_id_repeated_revision
def test_course_constructor_course_id_repeated_revision(self):
"""
The same revision appears in the course_id and the revision field.
"""
test_id = 'edu.mit.eecs.6002x;published'
test_revision = 'published'
expected_id = 'edu.mit.eecs.6002x'
expected_urn = 'edu.mit.eecs.6002x;published'
testobj = CourseLocator(course_id=test_id, revision=test_revision)
self.check_course_locn_fields(testobj, 'course_id with repeated revision',
course_id=expected_id,
revision=test_revision,
)
self.assertEqual(testobj.course_id, expected_id)
self.assertEqual(testobj.revision, test_revision)
self.assertEqual(str(testobj), expected_urn)
self.assertEqual(testobj.url(), 'edx://' + expected_urn)
开发者ID:NakarinTalikan,项目名称:edx-platform,代码行数:17,代码来源:test_locators.py
示例14: test_course_constructor_package_id_repeated_branch
def test_course_constructor_package_id_repeated_branch(self):
"""
The same branch appears in the package_id and the branch field.
"""
test_id = 'mit.eecs.6002x/' + BRANCH_PREFIX + 'published'
test_branch = 'published'
expected_id = 'mit.eecs.6002x'
expected_urn = test_id
testobj = CourseLocator(package_id=test_id, branch=test_branch)
self.check_course_locn_fields(testobj, 'package_id with repeated branch',
package_id=expected_id,
branch=test_branch,
)
self.assertEqual(testobj.package_id, expected_id)
self.assertEqual(testobj.branch, test_branch)
self.assertEqual(str(testobj), expected_urn)
self.assertEqual(testobj.url(), 'edx://' + expected_urn)
开发者ID:Caesar73,项目名称:edx-platform,代码行数:17,代码来源:test_locators.py
示例15: test_course_constructor_version_guid
def test_course_constructor_version_guid(self):
# generate a random location
test_id_1 = ObjectId()
test_id_1_loc = str(test_id_1)
testobj_1 = CourseLocator(version_guid=test_id_1)
self.check_course_locn_fields(testobj_1, 'version_guid', version_guid=test_id_1)
self.assertEqual(str(testobj_1.version_guid), test_id_1_loc)
self.assertEqual(str(testobj_1), VERSION_PREFIX + test_id_1_loc)
self.assertEqual(testobj_1.url(), 'edx://' + VERSION_PREFIX + test_id_1_loc)
# Test using a given string
test_id_2_loc = '519665f6223ebd6980884f2b'
test_id_2 = ObjectId(test_id_2_loc)
testobj_2 = CourseLocator(version_guid=test_id_2)
self.check_course_locn_fields(testobj_2, 'version_guid', version_guid=test_id_2)
self.assertEqual(str(testobj_2.version_guid), test_id_2_loc)
self.assertEqual(str(testobj_2), VERSION_PREFIX + test_id_2_loc)
self.assertEqual(testobj_2.url(), 'edx://' + VERSION_PREFIX + test_id_2_loc)
开发者ID:Caesar73,项目名称:edx-platform,代码行数:18,代码来源:test_locators.py
示例16: test_url_reverse
def test_url_reverse(self):
"""
Test the url_reverse method
"""
locator = CourseLocator(package_id="a.fancy_course-id", branch="branch_1.2-3")
self.assertEqual(
'/expression/{}/format'.format(unicode(locator)),
locator.url_reverse('expression', 'format')
)
self.assertEqual(
'/expression/{}/format'.format(unicode(locator)),
locator.url_reverse('/expression', '/format')
)
self.assertEqual(
'/expression/{}'.format(unicode(locator)),
locator.url_reverse('expression/', None)
)
self.assertEqual(
'/expression/{}'.format(unicode(locator)),
locator.url_reverse('/expression/', '')
)
开发者ID:Caesar73,项目名称:edx-platform,代码行数:21,代码来源:test_locators.py
示例17: test_html
def test_html(self):
'''
Ensure CourseLocator generates expected urls.
'''
raise SkipTest()
testobj = CourseLocator(version_guid='versionid')
self.assertEqual(testobj.html_id(), 'cvx/versionid', 'versionid')
self.assertEqual(testobj, CourseLocator(testobj.html_id()),
'versionid conversion through html_id')
testobj = CourseLocator(course_id='courseid')
self.assertEqual(testobj.html_id(), 'crx/courseid', 'courseid')
self.assertEqual(testobj, CourseLocator(testobj.html_id()),
'courseid conversion through html_id')
testobj = CourseLocator(course_id='courseid', revision='rev')
self.assertEqual(testobj.html_id(), 'crx/courseid%40rev', 'rev')
self.assertEqual(testobj, CourseLocator(testobj.html_id()),
'rev conversion through html_id')
开发者ID:NakarinTalikan,项目名称:edx-platform,代码行数:19,代码来源:test_locators.py
示例18: translate_location
def translate_location(self, location, published=True,
add_entry_if_missing=True, passed_block_id=None):
"""
Translate the given module location to a Locator.
The rationale for auto adding entries was that there should be a reasonable default translation
if the code just trips into this w/o creating translations.
Will raise ItemNotFoundError if there's no mapping and add_entry_if_missing is False.
:param location: a Location pointing to a module
:param published: a boolean to indicate whether the caller wants the draft or published branch.
:param add_entry_if_missing: a boolean as to whether to raise ItemNotFoundError or to create an entry if
the course
or block is not found in the map.
:param passed_block_id: what block_id to assign and save if none is found
(only if add_entry_if_missing)
NOTE: unlike old mongo, draft branches contain the whole course; so, it applies to all category
of locations including course.
"""
course_son = self._interpret_location_course_id(location.course_key)
cached_value = self._get_locator_from_cache(location, published)
if cached_value:
return cached_value
entry = self.location_map.find_one(course_son)
if entry is None:
if add_entry_if_missing:
# create a new map
self.create_map_entry(location.course_key)
entry = self.location_map.find_one(course_son)
else:
raise ItemNotFoundError(location)
else:
entry = self._migrate_if_necessary([entry])[0]
block_id = entry['block_map'].get(self.encode_key_for_mongo(location.name))
category = location.category
if block_id is None:
if add_entry_if_missing:
block_id = self._add_to_block_map(
location, course_son, entry['block_map'], passed_block_id
)
else:
raise ItemNotFoundError(location)
else:
# jump_to_id uses a None category.
if category is None:
if len(block_id) == 1:
# unique match (most common case)
category = block_id.keys()[0]
block_id = block_id.values()[0]
else:
raise InvalidLocationError()
elif category in block_id:
block_id = block_id[category]
elif add_entry_if_missing:
block_id = self._add_to_block_map(location, course_son, entry['block_map'])
else:
raise ItemNotFoundError(location)
prod_course_locator = CourseLocator(
org=entry['org'],
offering=entry['offering'],
branch=entry['prod_branch']
)
published_usage = BlockUsageLocator(
prod_course_locator,
block_type=category,
block_id=block_id
)
draft_usage = BlockUsageLocator(
prod_course_locator.for_branch(entry['draft_branch']),
block_type=category,
block_id=block_id
)
if published:
result = published_usage
else:
result = draft_usage
self._cache_location_map_entry(location, published_usage, draft_usage)
return result
开发者ID:bmcdonald2,项目名称:edx-platform,代码行数:85,代码来源:loc_mapper_store.py
示例19: test_translate_locator
def test_translate_locator(self):
"""
tests translate_locator_to_location(BlockUsageLocator)
"""
# lookup for non-existent course
org = 'foo_org'
course = 'bar_course'
run = 'baz_run'
new_style_org = '{}.geek_dept'.format(org)
new_style_offering = '{}.{}'.format(course, run)
prob_course_key = CourseLocator(
org=new_style_org, offering=new_style_offering,
branch='published',
)
prob_locator = BlockUsageLocator(
prob_course_key,
block_type='problem',
block_id='problem2',
)
prob_location = loc_mapper().translate_locator_to_location(prob_locator)
self.assertIsNone(prob_location, 'found entry in empty map table')
loc_mapper().create_map_entry(
SlashSeparatedCourseKey(org, course, run),
new_style_org, new_style_offering,
block_map={
'abc123': {'problem': 'problem2'},
'48f23a10395384929234': {'chapter': 'chapter48f'},
'baz_run': {'course': 'root'},
}
)
# only one course matches
prob_location = loc_mapper().translate_locator_to_location(prob_locator)
# default branch
self.assertEqual(prob_location, Location(org, course, run, 'problem', 'abc123', None))
# test get_course keyword
prob_location = loc_mapper().translate_locator_to_location(prob_locator, get_course=True)
self.assertEqual(prob_location, SlashSeparatedCourseKey(org, course, run))
# explicit branch
prob_locator = prob_locator.for_branch('draft')
prob_location = loc_mapper().translate_locator_to_location(prob_locator)
# Even though the problem was set as draft, we always return revision=None to work
# with old mongo/draft modulestores.
self.assertEqual(prob_location, Location(org, course, run, 'problem', 'abc123', None))
prob_locator = BlockUsageLocator(
prob_course_key.for_branch('production'),
block_type='problem', block_id='problem2'
)
prob_location = loc_mapper().translate_locator_to_location(prob_locator)
self.assertEqual(prob_location, Location(org, course, run, 'problem', 'abc123', None))
# same for chapter except chapter cannot be draft in old system
chap_locator = BlockUsageLocator(
prob_course_key.for_branch('production'),
block_type='chapter', block_id='chapter48f',
)
chap_location = loc_mapper().translate_locator_to_location(chap_locator)
self.assertEqual(chap_location, Location(org, course, run, 'chapter', '48f23a10395384929234'))
# explicit branch
chap_locator = chap_locator.for_branch('draft')
chap_location = loc_mapper().translate_locator_to_location(chap_locator)
self.assertEqual(chap_location, Location(org, course, run, 'chapter', '48f23a10395384929234'))
chap_locator = BlockUsageLocator(
prob_course_key.for_branch('production'), block_type='chapter', block_id='chapter48f'
)
chap_location = loc_mapper().translate_locator_to_location(chap_locator)
self.assertEqual(chap_location, Location(org, course, run, 'chapter', '48f23a10395384929234'))
# look for non-existent problem
prob_locator2 = BlockUsageLocator(
prob_course_key.for_branch('draft'),
block_type='problem', block_id='problem3'
)
prob_location = loc_mapper().translate_locator_to_location(prob_locator2)
self.assertIsNone(prob_location, 'Found non-existent problem')
# add a distractor course
delta_run = 'delta_run'
new_style_offering = '{}.{}'.format(course, delta_run)
loc_mapper().create_map_entry(
SlashSeparatedCourseKey(org, course, delta_run),
new_style_org, new_style_offering,
block_map={'abc123': {'problem': 'problem3'}}
)
prob_location = loc_mapper().translate_locator_to_location(prob_locator)
self.assertEqual(prob_location, Location(org, course, run, 'problem', 'abc123', None))
开发者ID:PaoloC68,项目名称:edx-platform,代码行数:85,代码来源:test_location_mapper.py
注:本文中的xmodule.modulestore.locator.CourseLocator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论