本文整理汇总了Python中milestones.api.add_course_milestone函数的典型用法代码示例。如果您正苦于以下问题:Python add_course_milestone函数的具体用法?Python add_course_milestone怎么用?Python add_course_milestone使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_course_milestone函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_add_course_milestone
def test_add_course_milestone(self):
""" Unit Test: test_add_course_milestone """
with self.assertNumQueries(3):
api.add_course_milestone(
self.test_course_key,
self.relationship_types['REQUIRES'],
self.test_milestone
)
requirer_milestones = api.get_course_milestones(
self.test_course_key,
self.relationship_types['REQUIRES']
)
self.assertEqual(len(requirer_milestones), 1)
with self.assertNumQueries(3):
api.add_course_milestone(
self.test_prerequisite_course_key,
self.relationship_types['FULFILLS'],
self.test_milestone
)
fulfiller_milestones = api.get_course_milestones(
self.test_prerequisite_course_key,
self.relationship_types['FULFILLS'],
)
self.assertEqual(len(fulfiller_milestones), 1)
开发者ID:edx,项目名称:edx-milestones,代码行数:25,代码来源:test_api.py
示例2: test_add_milestone_inactive_milestone_with_relationships_propagate_false
def test_add_milestone_inactive_milestone_with_relationships_propagate_false(self):
""" Unit Test: test_add_milestone_inactive_milestone_with_relationships_propagate_false"""
milestone_data = {
'name': 'local_milestone',
'display_name': 'Local Milestone',
'namespace': six.text_type(self.test_course_key),
'description': 'Local Milestone Description'
}
milestone = api.add_milestone(milestone_data)
api.add_course_milestone(
self.test_course_key,
self.relationship_types['REQUIRES'],
milestone
)
api.add_course_content_milestone(
self.test_course_key,
self.test_content_key,
self.relationship_types['FULFILLS'],
milestone
)
api.add_user_milestone(self.serialized_test_user, milestone)
self.assertGreater(milestone['id'], 0)
api.remove_milestone(milestone['id'])
with self.assertNumQueries(3):
milestone = api.add_milestone(milestone_data, propagate=False)
开发者ID:edx,项目名称:edx-milestones,代码行数:26,代码来源:test_api.py
示例3: test_get_course_tabs_list_entrance_exam_enabled
def test_get_course_tabs_list_entrance_exam_enabled(self):
"""
Unit Test: test_get_course_tabs_list_entrance_exam_enabled
"""
entrance_exam = ItemFactory.create(
category="chapter", parent_location=self.course.location,
data="Exam Data", display_name="Entrance Exam"
)
entrance_exam.is_entrance_exam = True
milestone = {
'name': 'Test Milestone',
'namespace': '{}.entrance_exams'.format(unicode(self.course.id)),
'description': 'Testing Courseware Tabs'
}
self.course.entrance_exam_enabled = True
self.course.entrance_exam_id = unicode(entrance_exam.location)
milestone = milestones_api.add_milestone(milestone)
milestones_api.add_course_milestone(
unicode(self.course.id),
self.relationship_types['REQUIRES'],
milestone
)
milestones_api.add_course_content_milestone(
unicode(self.course.id),
unicode(entrance_exam.location),
self.relationship_types['FULFILLS'],
milestone
)
course_tab_list = get_course_tab_list(self.course, self.user)
self.assertEqual(len(course_tab_list), 2)
self.assertEqual(course_tab_list[0]['tab_id'], 'courseware')
self.assertEqual(course_tab_list[0]['name'], 'Entrance Exam')
self.assertEqual(course_tab_list[1]['tab_id'], 'instructor')
开发者ID:feedbackfruits,项目名称:edx-platform,代码行数:33,代码来源:test_tabs.py
示例4: test_remove_content_references
def test_remove_content_references(self):
""" Unit Test: test_remove_content_references """
# Add a course dependency on the test milestone
api.add_course_milestone(
self.test_course_key,
self.relationship_types['REQUIRES'],
self.test_milestone
)
self.assertEqual(len(api.get_course_milestones(self.test_course_key)), 1)
# Add a content fulfillment for the test milestone
api.add_course_content_milestone(
self.test_course_key,
self.test_content_key,
self.relationship_types['FULFILLS'],
self.test_milestone
)
milestones = api.get_course_content_milestones(self.test_course_key, self.test_content_key)
self.assertEqual(len(milestones), 1)
# Remove the content dependency
with self.assertNumQueries(2):
api.remove_content_references(self.test_content_key)
milestones = api.get_course_content_milestones(self.test_course_key, self.test_content_key)
self.assertEqual(len(milestones), 0)
开发者ID:edx,项目名称:edx-milestones,代码行数:25,代码来源:test_api.py
示例5: test_add_course_milestone_bogus_course_key
def test_add_course_milestone_bogus_course_key(self):
""" Unit Test: test_add_course_milestone_bogus_course_key """
with self.assertNumQueries(0):
with self.assertRaises(exceptions.InvalidCourseKeyException):
api.add_course_milestone('12345667av', 'whatever', self.test_milestone)
with self.assertNumQueries(0):
with self.assertRaises(exceptions.InvalidCourseKeyException):
api.add_course_milestone(None, 'whatever', self.test_milestone)
开发者ID:edx,项目名称:edx-milestones,代码行数:8,代码来源:test_api.py
示例6: test_fetch_milestone_courses_no_relationship_type
def test_fetch_milestone_courses_no_relationship_type(self):
""" Unit Test: test_fetch_milestone_courses_no_relationship_type"""
milestone1 = api.add_milestone({
'display_name': 'Test Milestone',
'name': 'test_milestone',
'namespace': unicode(self.test_course_key),
'description': 'Test Milestone Description',
})
api.add_course_milestone(self.test_course_key, 'fulfills', milestone1)
self.assertEqual(len(data.fetch_milestone_courses(milestone1)), 1)
开发者ID:GbalsaC,项目名称:bitnamiP,代码行数:10,代码来源:test_data.py
示例7: _create_entrance_exam
def _create_entrance_exam(request, course_key, entrance_exam_minimum_score_pct=None):
"""
Internal workflow operation to create an entrance exam
"""
# Provide a default value for the minimum score percent if nothing specified
if entrance_exam_minimum_score_pct is None:
entrance_exam_minimum_score_pct = float(settings.ENTRANCE_EXAM_MIN_SCORE_PCT)
# Confirm the course exists
course = modulestore().get_course(course_key)
if course is None:
return HttpResponse(status=400)
# Create the entrance exam item (currently it's just a chapter)
payload = {
"category": "chapter",
"display_name": "Entrance Exam",
"parent_locator": unicode(course.location),
"is_entrance_exam": True,
"in_entrance_exam": True,
}
factory = RequestFactory()
internal_request = factory.post("/", json.dumps(payload), content_type="application/json")
internal_request.user = request.user
created_item = json.loads(create_item(internal_request).content)
# Set the entrance exam metadata flags for this course
# Reload the course so we don't overwrite the new child reference
course = modulestore().get_course(course_key)
metadata = {
"entrance_exam_enabled": True,
"entrance_exam_minimum_score_pct": entrance_exam_minimum_score_pct / 100,
"entrance_exam_id": created_item["locator"],
}
CourseMetadata.update_from_dict(metadata, course, request.user)
# Add an entrance exam milestone if one does not already exist
milestone_namespace = generate_milestone_namespace(NAMESPACE_CHOICES["ENTRANCE_EXAM"], course_key)
milestones = milestones_api.get_milestones(milestone_namespace)
if len(milestones):
milestone = milestones[0]
else:
description = "Autogenerated during {} entrance exam creation.".format(unicode(course.id))
milestone = milestones_api.add_milestone(
{"name": "Completed Course Entrance Exam", "namespace": milestone_namespace, "description": description}
)
relationship_types = milestones_api.get_milestone_relationship_types()
milestones_api.add_course_milestone(unicode(course.id), relationship_types["REQUIRES"], milestone)
milestones_api.add_course_content_milestone(
unicode(course.id), created_item["locator"], relationship_types["FULFILLS"], milestone
)
return HttpResponse(status=201)
开发者ID:geekmooc,项目名称:edx-platform,代码行数:53,代码来源:entrance_exam.py
示例8: test_add_course_milestone_active_exists
def test_add_course_milestone_active_exists(self):
""" Unit Test: test_add_course_milestone """
api.add_course_milestone(
self.test_course_key,
self.relationship_types['REQUIRES'],
self.test_milestone
)
with self.assertNumQueries(2):
api.add_course_milestone(
self.test_course_key,
self.relationship_types['REQUIRES'],
self.test_milestone
)
开发者ID:edx,项目名称:edx-milestones,代码行数:13,代码来源:test_api.py
示例9: test_get_course_milestones_with_invalid_relationship_type
def test_get_course_milestones_with_invalid_relationship_type(self):
""" Unit Test: test_get_course_milestones_with_invalid_relationship_type """
api.add_course_milestone(
self.test_course_key,
self.relationship_types['REQUIRES'],
self.test_milestone
)
with self.assertNumQueries(1):
requirer_milestones = api.get_course_milestones(
self.test_course_key,
'INVALID RELATIONSHIP TYPE'
)
self.assertEqual(len(requirer_milestones), 0)
开发者ID:edx,项目名称:edx-milestones,代码行数:13,代码来源:test_api.py
示例10: test_get_course_milestones
def test_get_course_milestones(self):
""" Unit Test: test_get_course_milestones """
api.add_course_milestone(
self.test_course_key,
self.relationship_types['REQUIRES'],
self.test_milestone
)
with self.assertNumQueries(2):
requirer_milestones = api.get_course_milestones(
self.test_course_key,
self.relationship_types['REQUIRES']
)
self.assertEqual(len(requirer_milestones), 1)
开发者ID:edx,项目名称:edx-milestones,代码行数:13,代码来源:test_api.py
示例11: add_course_milestone
def add_course_milestone(course_id, relationship, milestone):
"""
Client API operation adapter/wrapper
"""
if not settings.FEATURES.get('MILESTONES_APP'):
return None
return milestones_api.add_course_milestone(course_id, relationship, milestone)
开发者ID:CraftAcademy,项目名称:edx-platform,代码行数:7,代码来源:milestones_helpers.py
示例12: add_prerequisite_course
def add_prerequisite_course(course_key, prerequisite_course_key):
"""
It would create a milestone, then it would set newly created
milestones as requirement for course referred by `course_key`
and it would set newly created milestone as fulfilment
milestone for course referred by `prerequisite_course_key`.
"""
if settings.FEATURES.get('MILESTONES_APP', False):
# create a milestone
milestone = add_milestone({
'name': _('Course {} requires {}'.format(unicode(course_key), unicode(prerequisite_course_key))),
'namespace': unicode(prerequisite_course_key),
'description': _('System defined milestone'),
})
# add requirement course milestone
add_course_milestone(course_key, 'requires', milestone)
# add fulfillment course milestone
add_course_milestone(prerequisite_course_key, 'fulfills', milestone)
开发者ID:mrgnr,项目名称:edx-platform,代码行数:19,代码来源:milestones_helpers.py
示例13: test_get_courses_milestones_with_invalid_relationship_type
def test_get_courses_milestones_with_invalid_relationship_type(self):
""" Unit Test: test_get_courses_milestones_with_invalid_relationship_type """
api.add_course_milestone(
self.test_course_key,
self.relationship_types['REQUIRES'],
self.test_milestone
)
api.add_course_milestone(
self.test_prerequisite_course_key,
self.relationship_types['REQUIRES'],
self.test_milestone
)
local_milestone = api.add_milestone({
'display_name': 'Local Milestone',
'name': 'local_milestone',
'namespace': six.text_type(self.test_course_key),
'description': 'Local Milestone Description'
})
api.add_course_milestone(
self.test_course_key,
self.relationship_types['FULFILLS'],
local_milestone
)
with self.assertNumQueries(1):
requirer_milestones = api.get_courses_milestones(
[self.test_course_key],
'INVALID RELATIONSHIP TYPE'
)
self.assertEqual(len(requirer_milestones), 0)
开发者ID:edx,项目名称:edx-milestones,代码行数:30,代码来源:test_api.py
示例14: test_get_courses_milestones
def test_get_courses_milestones(self):
""" Unit Test: test_get_courses_milestones """
api.add_course_milestone(
self.test_course_key,
self.relationship_types['REQUIRES'],
self.test_milestone
)
api.add_course_milestone(
self.test_prerequisite_course_key,
self.relationship_types['REQUIRES'],
self.test_milestone
)
local_milestone = api.add_milestone({
'display_name': 'Local Milestone',
'name': 'local_milestone',
'namespace': unicode(self.test_course_key),
'description': 'Local Milestone Description'
})
api.add_course_milestone(
self.test_course_key,
self.relationship_types['FULFILLS'],
local_milestone
)
with self.assertNumQueries(2):
requirer_milestones = api.get_courses_milestones(
[self.test_course_key, self.test_prerequisite_course_key],
self.relationship_types['REQUIRES']
)
self.assertEqual(len(requirer_milestones), 2)
with self.assertNumQueries(1):
requirer_milestones = api.get_courses_milestones(
[self.test_course_key],
)
self.assertEqual(len(requirer_milestones), 2)
开发者ID:GbalsaC,项目名称:bitnamiP,代码行数:35,代码来源:test_api.py
示例15: test_fetch_courses_milestones_invalid_milestone_relationship_type
def test_fetch_courses_milestones_invalid_milestone_relationship_type(self):
""" Unit Test: test_fetch_courses_milestones_invalid_milestone_relationship_type"""
milestone1 = api.add_milestone({
'display_name': 'Test Milestone',
'name': 'test_milestone',
'namespace': unicode(self.test_course_key),
'description': 'Test Milestone Description',
})
api.add_course_milestone(self.test_course_key, self.relationship_types['REQUIRES'], milestone1)
milestone2 = api.add_milestone({
'display_name': 'Test Milestone 2',
'name': 'test_milestone_2',
'namespace': unicode(self.test_course_key),
'description': 'Test Milestone Description 2',
})
api.add_course_milestone(self.test_course_key, self.relationship_types['FULFILLS'], milestone2)
with self.assertRaises(exceptions.InvalidMilestoneRelationshipTypeException):
data.fetch_courses_milestones(
[self.test_course_key, ],
'invalid_relationshipppp',
milestone1
)
开发者ID:GbalsaC,项目名称:bitnamiP,代码行数:22,代码来源:test_data.py
示例16: add_prerequisite_course
def add_prerequisite_course(course_key, prerequisite_course_key):
"""
It would create a milestone, then it would set newly created
milestones as requirement for course referred by `course_key`
and it would set newly created milestone as fulfillment
milestone for course referred by `prerequisite_course_key`.
"""
if not is_prerequisite_courses_enabled():
return None
milestone_name = _('Course {course_id} requires {prerequisite_course_id}').format(
course_id=unicode(course_key),
prerequisite_course_id=unicode(prerequisite_course_key)
)
milestone = milestones_api.add_milestone({
'name': milestone_name,
'namespace': unicode(prerequisite_course_key),
'description': _('System defined milestone'),
})
# add requirement course milestone
milestones_api.add_course_milestone(course_key, 'requires', milestone)
# add fulfillment course milestone
milestones_api.add_course_milestone(prerequisite_course_key, 'fulfills', milestone)
开发者ID:CraftAcademy,项目名称:edx-platform,代码行数:23,代码来源:milestones_helpers.py
示例17: test_milestones_fulfillment_paths_contains_special_characters
def test_milestones_fulfillment_paths_contains_special_characters(self):
"""
Unit Test: test_get_course_milestones_fulfillment_paths works correctly when milestone have some special
characters.
"""
namespace = six.text_type(self.test_course_key)
name = '�ťÉśt_Àübùr�'
local_milestone_1 = api.add_milestone({
'display_name': 'Local Milestone 1',
'name': name,
'namespace': namespace,
'description': 'Local Milestone 1 Description'
})
# Specify the milestone requirements
api.add_course_milestone(
self.test_course_key,
self.relationship_types['REQUIRES'],
local_milestone_1
)
# Specify the milestone fulfillments (via course and content)
api.add_course_milestone(
self.test_prerequisite_course_key,
self.relationship_types['FULFILLS'],
local_milestone_1
)
with self.assertNumQueries(4):
paths = api.get_course_milestones_fulfillment_paths(
self.test_course_key,
self.serialized_test_user
)
# Set up the key values we'll use to access/assert the response
milestone_key_1 = '{}.{}'.format(local_milestone_1['namespace'], local_milestone_1['name'])
self.assertEqual(len(paths[milestone_key_1]['courses']), 1)
开发者ID:edx,项目名称:edx-milestones,代码行数:36,代码来源:test_api.py
示例18: add_prerequisite_course
def add_prerequisite_course(course_key, prerequisite_course_key):
"""
It would create a milestone, then it would set newly created
milestones as requirement for course referred by `course_key`
and it would set newly created milestone as fulfilment
milestone for course referred by `prerequisite_course_key`.
"""
if not settings.FEATURES.get('ENABLE_PREREQUISITE_COURSES', False):
return None
from milestones import api as milestones_api
milestone_name = _('Course {course_id} requires {prerequisite_course_id}').format(
course_id=unicode(course_key),
prerequisite_course_id=unicode(prerequisite_course_key)
)
milestone = milestones_api.add_milestone({
'name': milestone_name,
'namespace': unicode(prerequisite_course_key),
'description': _('System defined milestone'),
})
# add requirement course milestone
milestones_api.add_course_milestone(course_key, 'requires', milestone)
# add fulfillment course milestone
milestones_api.add_course_milestone(prerequisite_course_key, 'fulfills', milestone)
开发者ID:nttks,项目名称:edx-platform,代码行数:24,代码来源:milestones_helpers.py
示例19: _create_entrance_exam
def _create_entrance_exam(request, course_key, entrance_exam_minimum_score_pct=None):
"""
Internal workflow operation to create an entrance exam
"""
# Provide a default value for the minimum score percent if nothing specified
if entrance_exam_minimum_score_pct is None:
entrance_exam_minimum_score_pct = _get_default_entrance_exam_minimum_pct()
# Confirm the course exists
course = modulestore().get_course(course_key)
if course is None:
return HttpResponse(status=400)
# Create the entrance exam item (currently it's just a chapter)
payload = {
'category': "chapter",
'display_name': "Entrance Exam",
'parent_locator': unicode(course.location),
'is_entrance_exam': True,
'in_entrance_exam': True,
}
parent_locator = unicode(course.location)
created_block = create_xblock(
parent_locator=parent_locator,
user=request.user,
category='chapter',
display_name='Entrance Exam',
is_entrance_exam=True
)
# Set the entrance exam metadata flags for this course
# Reload the course so we don't overwrite the new child reference
course = modulestore().get_course(course_key)
metadata = {
'entrance_exam_enabled': True,
'entrance_exam_minimum_score_pct': unicode(entrance_exam_minimum_score_pct),
'entrance_exam_id': unicode(created_block.location),
}
CourseMetadata.update_from_dict(metadata, course, request.user)
# Create the entrance exam section item.
create_xblock(
parent_locator=unicode(created_block.location),
user=request.user,
category='sequential',
display_name=_('Entrance Exam - Subsection')
)
# Add an entrance exam milestone if one does not already exist
milestone_namespace = generate_milestone_namespace(
NAMESPACE_CHOICES['ENTRANCE_EXAM'],
course_key
)
milestones = milestones_api.get_milestones(milestone_namespace)
if len(milestones):
milestone = milestones[0]
else:
description = 'Autogenerated during {} entrance exam creation.'.format(unicode(course.id))
milestone = milestones_api.add_milestone({
'name': 'Completed Course Entrance Exam',
'namespace': milestone_namespace,
'description': description
})
relationship_types = milestones_api.get_milestone_relationship_types()
milestones_api.add_course_milestone(
unicode(course.id),
relationship_types['REQUIRES'],
milestone
)
milestones_api.add_course_content_milestone(
unicode(course.id),
unicode(created_block.location),
relationship_types['FULFILLS'],
milestone
)
return HttpResponse(status=201)
开发者ID:mrgnr,项目名称:edx-platform,代码行数:77,代码来源:entrance_exam.py
示例20: test_get_course_milestones_fulfillment_paths
def test_get_course_milestones_fulfillment_paths(self): # pylint: disable=too-many-statements
"""
Unit Test: test_get_course_milestones_fulfillment_paths
"""
# Create three milestones in order tto cover all logical branches
namespace = six.text_type(self.test_course_key)
local_milestone_1 = api.add_milestone({
'display_name': 'Local Milestone 1',
'name': 'local_milestone_1',
'namespace': namespace,
'description': 'Local Milestone 1 Description'
})
local_milestone_2 = api.add_milestone({
'display_name': 'Local Milestone 2',
'name': 'local_milestone_2',
'namespace': namespace,
'description': 'Local Milestone 2 Description'
})
local_milestone_3 = api.add_milestone({
'display_name': 'Local Milestone 3',
'name': 'local_milestone_3',
'namespace': namespace,
'description': 'Local Milestone 3 Description'
})
# Specify the milestone requirements
api.add_course_milestone(
self.test_course_key,
self.relationship_types['REQUIRES'],
local_milestone_1
)
api.add_course_milestone(
self.test_course_key,
self.relationship_types['REQUIRES'],
local_milestone_2
)
api.add_course_milestone(
self.test_course_key,
self.relationship_types['REQUIRES'],
local_milestone_3
)
# Specify the milestone fulfillments (via course and content)
api.add_course_milestone(
self.test_prerequisite_course_key,
self.relationship_types['FULFILLS'],
local_milestone_1
)
api.add_course_milestone(
self.test_prerequisite_course_key,
self.relationship_types['FULFILLS'],
local_milestone_2
)
api.add_course_content_milestone(
self.test_course_key,
UsageKey.from_string('i4x://the/content/key/123456789'),
self.relationship_types['FULFILLS'],
local_milestone_2
)
api.add_course_content_milestone(
self.test_course_key,
UsageKey.from_string('i4x://the/content/key/123456789'),
self.relationship_types['FULFILLS'],
local_milestone_3
)
api.add_course_content_milestone(
self.test_course_key,
UsageKey.from_string('i4x://the/content/key/987654321'),
self.relationship_types['FULFILLS'],
local_milestone_3
)
# Confirm the starting state for this test (user has no milestones, course requires three)
self.assertEqual(
len(api.get_user_milestones(self.serialized_test_user, namespace=namespace)), 0)
self.assertEqual(
len(api.get_course_required_milestones(self.test_course_key, self.serialized_test_user)),
3
)
# Check the possible fulfillment paths for the milestones for this course
with self.assertNumQueries(8):
paths = api.get_course_milestones_fulfillment_paths(
self.test_course_key,
self.serialized_test_user
)
# Set up the key values we'll use to access/assert the response
milestone_key_1 = '{}.{}'.format(local_milestone_1['namespace'], local_milestone_1['name'])
milestone_key_2 = '{}.{}'.format(local_milestone_2['namespace'], local_milestone_2['name'])
milestone_key_3 = '{}.{}'.format(local_milestone_3['namespace'], local_milestone_3['name'])
# First round of assertions
self.assertEqual(len(paths[milestone_key_1]['courses']), 1)
self.assertIsNone(paths[milestone_key_1].get('content'))
self.assertEqual(len(paths[milestone_key_2]['courses']), 1)
self.assertEqual(len(paths[milestone_key_2]['content']), 1)
self.assertIsNone(paths[milestone_key_3].get('courses'))
self.assertEqual(len(paths[milestone_key_3]['content']), 2)
# Collect the first milestone (two should remain)
#.........这里部分代码省略.........
开发者ID:edx,项目名称:edx-milestones,代码行数:101,代码来源:test_api.py
注:本文中的milestones.api.add_course_milestone函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论