Commit cd0aa7f3 by Ned Batchelder

Make CourseFactory more useful: accept arbitrary kwargs.

parent ef82f33b
......@@ -19,14 +19,13 @@ class XModuleCourseFactory(Factory):
ABSTRACT_FACTORY = True
@classmethod
def _create(cls, target_class, *args, **kwargs):
def _create(cls, target_class, **kwargs):
template = Location('i4x', 'edx', 'templates', 'course', 'Empty')
org = kwargs.get('org')
number = kwargs.get('number')
display_name = kwargs.get('display_name')
location = Location('i4x', org, number,
'course', Location.clean(display_name))
org = kwargs.pop('org', None)
number = kwargs.pop('number', None)
display_name = kwargs.pop('display_name', None)
location = Location('i4x', org, number, 'course', Location.clean(display_name))
try:
store = modulestore('direct')
......@@ -41,7 +40,7 @@ class XModuleCourseFactory(Factory):
new_course.display_name = display_name
new_course.lms.start = datetime.datetime.now(UTC)
new_course.tabs = kwargs.get(
new_course.tabs = kwargs.pop(
'tabs',
[
{"type": "courseware"},
......@@ -51,15 +50,18 @@ class XModuleCourseFactory(Factory):
{"type": "progress", "name": "Progress"}
]
)
new_course.discussion_link = kwargs.get('discussion_link')
# Update the data in the mongo datastore
store.update_metadata(new_course.location.url(), own_metadata(new_course))
data = kwargs.get('data')
data = kwargs.pop('data', None)
if data is not None:
store.update_item(new_course.location, data)
# The rest of kwargs become attributes on the course:
for k, v in kwargs.iteritems():
setattr(new_course, k, v)
# Update the data in the mongo datastore
store.update_metadata(new_course.location.url(), own_metadata(new_course))
# update_item updates the the course as it exists in the modulestore, but doesn't
# update the instance we are working with, so have to refetch the course after updating it.
new_course = store.get_instance(new_course.id, new_course.location)
......@@ -101,7 +103,7 @@ class XModuleItemFactory(Factory):
return parent._replace(category=attr.category, name=dest_name)
@classmethod
def _create(cls, target_class, *args, **kwargs):
def _create(cls, target_class, **kwargs):
"""
Uses *kwargs*:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment