Commit 47851c50 by Don Mitchell

Replace create_xmodule with create_xblock

Refactor all callers (often replacing with more appropriate fn)

Also, added for_branch_setting method to old mongo and removed some
branch verification tests

Conflicts:
	common/lib/xmodule/xmodule/modulestore/mongo/draft.py
	common/lib/xmodule/xmodule/modulestore/split_mongo/split_draft.py
	common/lib/xmodule/xmodule/modulestore/xml_importer.py
parent 9efe5d92
...@@ -1412,17 +1412,14 @@ class ContentStoreTest(ContentStoreTestCase): ...@@ -1412,17 +1412,14 @@ class ContentStoreTest(ContentStoreTestCase):
self.assertGreater(len(verticals), 0) self.assertGreater(len(verticals), 0)
new_component_location = course.id.make_usage_key('html', 'new_component')
# crate a new module and add it as a child to a vertical # crate a new module and add it as a child to a vertical
new_object = self.store.create_xmodule(new_component_location)
self.store.update_item(new_object, self.user.id, allow_not_found=True)
parent = verticals[0] parent = verticals[0]
parent.children.append(new_component_location) new_module = self.store.create_child(
self.store.update_item(parent, self.user.id) self.user.id, parent.location, 'html', 'new_component'
)
# flush the cache # flush the cache
new_module = self.store.get_item(new_component_location) new_module = self.store.get_item(new_module.location)
# check for grace period definition which should be defined at the course level # check for grace period definition which should be defined at the course level
self.assertEqual(parent.graceperiod, new_module.graceperiod) self.assertEqual(parent.graceperiod, new_module.graceperiod)
...@@ -1438,7 +1435,7 @@ class ContentStoreTest(ContentStoreTestCase): ...@@ -1438,7 +1435,7 @@ class ContentStoreTest(ContentStoreTestCase):
self.store.update_item(new_module, self.user.id) self.store.update_item(new_module, self.user.id)
# flush the cache and refetch # flush the cache and refetch
new_module = self.store.get_item(new_component_location) new_module = self.store.get_item(new_module.location)
self.assertEqual(timedelta(1), new_module.graceperiod) self.assertEqual(timedelta(1), new_module.graceperiod)
......
...@@ -89,7 +89,8 @@ class TemplateTests(unittest.TestCase): ...@@ -89,7 +89,8 @@ class TemplateTests(unittest.TestCase):
) )
test_chapter = self.split_store.create_xblock( test_chapter = self.split_store.create_xblock(
test_course.system, 'chapter', {'display_name': 'chapter n'}, parent_xblock=test_course test_course.system, test_course.id, 'chapter', fields={'display_name': 'chapter n'},
parent_xblock=test_course
) )
self.assertIsInstance(test_chapter, SequenceDescriptor) self.assertIsInstance(test_chapter, SequenceDescriptor)
self.assertEqual(test_chapter.display_name, 'chapter n') self.assertEqual(test_chapter.display_name, 'chapter n')
...@@ -98,7 +99,8 @@ class TemplateTests(unittest.TestCase): ...@@ -98,7 +99,8 @@ class TemplateTests(unittest.TestCase):
# test w/ a definition (e.g., a problem) # test w/ a definition (e.g., a problem)
test_def_content = '<problem>boo</problem>' test_def_content = '<problem>boo</problem>'
test_problem = self.split_store.create_xblock( test_problem = self.split_store.create_xblock(
test_course.system, 'problem', {'data': test_def_content}, parent_xblock=test_chapter test_course.system, test_course.id, 'problem', fields={'data': test_def_content},
parent_xblock=test_chapter
) )
self.assertIsInstance(test_problem, CapaDescriptor) self.assertIsInstance(test_problem, CapaDescriptor)
self.assertEqual(test_problem.data, test_def_content) self.assertEqual(test_problem.data, test_def_content)
...@@ -115,13 +117,14 @@ class TemplateTests(unittest.TestCase): ...@@ -115,13 +117,14 @@ class TemplateTests(unittest.TestCase):
display_name='fun test course', user_id='testbot' display_name='fun test course', user_id='testbot'
) )
test_chapter = self.split_store.create_xblock( test_chapter = self.split_store.create_xblock(
test_course.system, 'chapter', {'display_name': 'chapter n'}, parent_xblock=test_course test_course.system, test_course.id, 'chapter', fields={'display_name': 'chapter n'},
parent_xblock=test_course
) )
self.assertEqual(test_chapter.display_name, 'chapter n') self.assertEqual(test_chapter.display_name, 'chapter n')
test_def_content = '<problem>boo</problem>' test_def_content = '<problem>boo</problem>'
# create child # create child
new_block = self.split_store.create_xblock( new_block = self.split_store.create_xblock(
test_course.system, test_course.system, test_course.id,
'problem', 'problem',
fields={ fields={
'data': test_def_content, 'data': test_def_content,
......
...@@ -15,6 +15,7 @@ from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory ...@@ -15,6 +15,7 @@ from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from opaque_keys.edx.locations import SlashSeparatedCourseKey, Location from opaque_keys.edx.locations import SlashSeparatedCourseKey, Location
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from opaque_keys.edx.locator import CourseLocator
class LMSLinksTestCase(TestCase): class LMSLinksTestCase(TestCase):
...@@ -249,16 +250,15 @@ class XBlockVisibilityTestCase(TestCase): ...@@ -249,16 +250,15 @@ class XBlockVisibilityTestCase(TestCase):
def _create_xblock_with_start_date(self, name, start_date, publish=False, visible_to_staff_only=False): def _create_xblock_with_start_date(self, name, start_date, publish=False, visible_to_staff_only=False):
"""Helper to create an xblock with a start date, optionally publishing it""" """Helper to create an xblock with a start date, optionally publishing it"""
location = Location('edX', 'visibility', '2012_Fall', 'vertical', name) course_key = CourseLocator('edX', 'visibility', '2012_Fall')
vertical = modulestore().create_xmodule(location) vertical = modulestore().create_item(
vertical.start = start_date self.dummy_user, course_key, 'vertical', name,
if visible_to_staff_only: fields={'start': start_date, 'visible_to_staff_only': visible_to_staff_only}
vertical.visible_to_staff_only = visible_to_staff_only )
modulestore().update_item(vertical, self.dummy_user, allow_not_found=True)
if publish: if publish:
modulestore().publish(location, self.dummy_user) modulestore().publish(vertical.location, self.dummy_user)
return vertical return vertical
......
...@@ -91,7 +91,7 @@ class CourseDetails(object): ...@@ -91,7 +91,7 @@ class CourseDetails(object):
try: try:
about_item = store.get_item(temploc) about_item = store.get_item(temploc)
except ItemNotFoundError: except ItemNotFoundError:
about_item = store.create_xmodule(temploc, runtime=course.runtime) about_item = store.create_xblock(course.runtime, course.id, 'about', about_key)
about_item.data = data about_item.data = data
store.update_item(about_item, user.id) store.update_item(about_item, user.id)
......
...@@ -491,18 +491,12 @@ class MixedModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase): ...@@ -491,18 +491,12 @@ class MixedModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase):
modulestore._drop_database() # pylint: disable=protected-access modulestore._drop_database() # pylint: disable=protected-access
@strip_key @strip_key
def create_xmodule(self, location, definition_data=None, metadata=None, runtime=None, fields={}, **kwargs): def create_xblock(self, runtime, course_key, block_type, block_id=None, fields=None, **kwargs):
""" """
Create the new xmodule but don't save it. Returns the new module. Create the new xmodule but don't save it. Returns the new module.
:param location: a Location--must have a category
:param definition_data: can be empty. The initial definition_data for the kvs
:param metadata: can be empty, the initial metadata for the kvs
:param runtime: if you already have an xblock from the course, the xblock.runtime value
:param fields: a dictionary of field names and values for the new xmodule
""" """
store = self._verify_modulestore_support(location.course_key, 'create_xmodule') store = self._verify_modulestore_support(course_key, 'create_xblock')
return store.create_xmodule(location, definition_data, metadata, runtime, fields, **kwargs) return store.create_xblock(runtime, course_key, block_type, block_id, fields or {}, **kwargs)
@strip_key @strip_key
def get_courses_for_wiki(self, wiki_slug, **kwargs): def get_courses_for_wiki(self, wiki_slug, **kwargs):
......
...@@ -476,6 +476,16 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase): ...@@ -476,6 +476,16 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase):
return course_key.replace(run=self._course_run_cache[cache_key]) return course_key.replace(run=self._course_run_cache[cache_key])
def for_branch_setting(self, location):
"""
Returns the Location that is for the current branch setting.
"""
if location.category in DIRECT_ONLY_CATEGORIES:
return location.replace(revision=MongoRevisionKey.published)
if self.get_branch_setting() == ModuleStoreEnum.Branch.draft_preferred:
return location.replace(revision=MongoRevisionKey.draft)
return location.replace(revision=MongoRevisionKey.published)
def _compute_metadata_inheritance_tree(self, course_id): def _compute_metadata_inheritance_tree(self, course_id):
''' '''
TODO (cdodge) This method can be deleted when the 'split module store' work has been completed TODO (cdodge) This method can be deleted when the 'split module store' work has been completed
...@@ -938,19 +948,11 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase): ...@@ -938,19 +948,11 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase):
if courses.count() > 0: if courses.count() > 0:
raise DuplicateCourseError(course_id, courses[0]['_id']) raise DuplicateCourseError(course_id, courses[0]['_id'])
location = course_id.make_usage_key('course', course_id.run) course = self.create_item(user_id, course_id, 'course', course_id.run, fields=fields, **kwargs)
course = self.create_xmodule(
location,
fields=fields,
**kwargs
)
self.update_item(course, user_id, allow_not_found=True)
# clone a default 'about' overview module as well # clone a default 'about' overview module as well
about_location = location.replace( about_location = course_id.make_usage_key('about', 'overview')
category='about',
name='overview'
)
overview_template = AboutDescriptor.get_template('overview.yaml') overview_template = AboutDescriptor.get_template('overview.yaml')
self.create_item( self.create_item(
user_id, user_id,
...@@ -963,25 +965,26 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase): ...@@ -963,25 +965,26 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase):
return course return course
def create_xmodule(self, location, definition_data=None, metadata=None, runtime=None, fields={}, **kwargs): def create_xblock(
self, runtime, course_key, block_type, block_id=None, fields=None,
metadata=None, definition_data=None, **kwargs
):
""" """
Create the new xmodule but don't save it. Returns the new module. Create the new xblock but don't save it. Returns the new module.
:param location: a Location--must have a category
:param definition_data: can be empty. The initial definition_data for the kvs
:param metadata: can be empty, the initial metadata for the kvs
:param runtime: if you already have an xblock from the course, the xblock.runtime value :param runtime: if you already have an xblock from the course, the xblock.runtime value
:param fields: a dictionary of field names and values for the new xmodule :param fields: a dictionary of field names and values for the new xmodule
""" """
location = location.replace(run=self.fill_in_run(location.course_key).run)
# differs from split mongo in that I believe most of this logic should be above the persistence
# layer but added it here to enable quick conversion. I'll need to reconcile these.
if metadata is None: if metadata is None:
metadata = {} metadata = {}
if definition_data is None: if definition_data is None:
definition_data = {} definition_data = {}
# @Cale, should this use LocalId like we do in split?
if block_id is None:
block_id = uuid4().hex # really need to make this more readable: e.g., u'{}{}'.format(block_type, uuid4().hex[:4]
if runtime is None: if runtime is None:
services = {} services = {}
if self.i18n_service: if self.i18n_service:
...@@ -990,7 +993,7 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase): ...@@ -990,7 +993,7 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase):
runtime = CachingDescriptorSystem( runtime = CachingDescriptorSystem(
modulestore=self, modulestore=self,
module_data={}, module_data={},
course_key=location.course_key, course_key=course_key,
default_class=self.default_class, default_class=self.default_class,
resources_fs=None, resources_fs=None,
error_tracker=self.error_tracker, error_tracker=self.error_tracker,
...@@ -1000,14 +1003,15 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase): ...@@ -1000,14 +1003,15 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase):
select=self.xblock_select, select=self.xblock_select,
services=services, services=services,
) )
xblock_class = runtime.load_block_type(location.category) xblock_class = runtime.load_block_type(block_type)
dbmodel = self._create_new_field_data(location.category, location, definition_data, metadata) location = course_key.make_usage_key(block_type, block_id)
dbmodel = self._create_new_field_data(block_type, location, definition_data, metadata)
xmodule = runtime.construct_xblock_from_class( xmodule = runtime.construct_xblock_from_class(
xblock_class, xblock_class,
# We're loading a descriptor, so student_id is meaningless # We're loading a descriptor, so student_id is meaningless
# We also don't have separate notions of definition and usage ids yet, # We also don't have separate notions of definition and usage ids yet,
# so we use the location for both. # so we use the location for both.
ScopeIds(None, location.category, location, location), ScopeIds(None, block_type, location, location),
dbmodel, dbmodel,
) )
if fields is not None: if fields is not None:
...@@ -1034,8 +1038,8 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase): ...@@ -1034,8 +1038,8 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase):
if block_id is None: if block_id is None:
block_id = uuid4().hex block_id = uuid4().hex
location = course_key.make_usage_key(block_type, block_id) runtime = kwargs.pop('runtime', None)
xblock = self.create_xmodule(location, **kwargs) xblock = self.create_xblock(runtime, course_key, block_type, block_id, **kwargs)
xblock = self.update_item(xblock, user_id, allow_not_found=True) xblock = self.update_item(xblock, user_id, allow_not_found=True)
return xblock return xblock
......
...@@ -12,9 +12,7 @@ import logging ...@@ -12,9 +12,7 @@ import logging
from opaque_keys.edx.locations import Location from opaque_keys.edx.locations import Location
from xmodule.exceptions import InvalidVersionError from xmodule.exceptions import InvalidVersionError
from xmodule.modulestore import PublishState, ModuleStoreEnum from xmodule.modulestore import PublishState, ModuleStoreEnum
from xmodule.modulestore.exceptions import ( from xmodule.modulestore.exceptions import ItemNotFoundError, DuplicateItemError, DuplicateCourseError
ItemNotFoundError, DuplicateItemError, InvalidBranchSetting, DuplicateCourseError
)
from xmodule.modulestore.mongo.base import ( from xmodule.modulestore.mongo.base import (
MongoModuleStore, MongoRevisionKey, as_draft, as_published, MongoModuleStore, MongoRevisionKey, as_draft, as_published,
SORT_REVISION_FAVOR_DRAFT SORT_REVISION_FAVOR_DRAFT
...@@ -292,7 +290,7 @@ class DraftModuleStore(MongoModuleStore): ...@@ -292,7 +290,7 @@ class DraftModuleStore(MongoModuleStore):
else ModuleStoreEnum.RevisionOption.draft_preferred else ModuleStoreEnum.RevisionOption.draft_preferred
return super(DraftModuleStore, self).get_parent_location(location, revision, **kwargs) return super(DraftModuleStore, self).get_parent_location(location, revision, **kwargs)
def create_xmodule(self, location, definition_data=None, metadata=None, runtime=None, fields={}, **kwargs): def create_xblock(self, runtime, course_key, block_type, block_id=None, fields=None, **kwargs):
""" """
Create the new xmodule but don't save it. Returns the new module with a draft locator if Create the new xmodule but don't save it. Returns the new module with a draft locator if
the category allows drafts. If the category does not allow drafts, just creates a published module. the category allows drafts. If the category does not allow drafts, just creates a published module.
...@@ -303,13 +301,11 @@ class DraftModuleStore(MongoModuleStore): ...@@ -303,13 +301,11 @@ class DraftModuleStore(MongoModuleStore):
:param runtime: if you already have an xmodule from the course, the xmodule.runtime value :param runtime: if you already have an xmodule from the course, the xmodule.runtime value
:param fields: a dictionary of field names and values for the new xmodule :param fields: a dictionary of field names and values for the new xmodule
""" """
self._verify_branch_setting(ModuleStoreEnum.Branch.draft_preferred) new_block = super(DraftModuleStore, self).create_xblock(
runtime, course_key, block_type, block_id, fields, **kwargs
if location.category not in DIRECT_ONLY_CATEGORIES:
location = as_draft(location)
return wrap_draft(
super(DraftModuleStore, self).create_xmodule(location, definition_data, metadata, runtime, fields)
) )
new_block.location = self.for_branch_setting(new_block.location)
return wrap_draft(new_block)
def get_items(self, course_key, revision=None, **kwargs): def get_items(self, course_key, revision=None, **kwargs):
""" """
...@@ -395,7 +391,7 @@ class DraftModuleStore(MongoModuleStore): ...@@ -395,7 +391,7 @@ class DraftModuleStore(MongoModuleStore):
DuplicateItemError: if the source or any of its descendants already has a draft copy. Only DuplicateItemError: if the source or any of its descendants already has a draft copy. Only
useful for unpublish b/c we don't want unpublish to overwrite any existing drafts. useful for unpublish b/c we don't want unpublish to overwrite any existing drafts.
""" """
# verify input conditions # verify input conditions: can only convert to draft branch; so, verify that's the setting
self._verify_branch_setting(ModuleStoreEnum.Branch.draft_preferred) self._verify_branch_setting(ModuleStoreEnum.Branch.draft_preferred)
_verify_revision_is_published(location) _verify_revision_is_published(location)
...@@ -440,13 +436,12 @@ class DraftModuleStore(MongoModuleStore): ...@@ -440,13 +436,12 @@ class DraftModuleStore(MongoModuleStore):
In addition to the superclass's behavior, this method converts the unit to draft if it's not In addition to the superclass's behavior, this method converts the unit to draft if it's not
direct-only and not already draft. direct-only and not already draft.
""" """
self._verify_branch_setting(ModuleStoreEnum.Branch.draft_preferred) draft_loc = self.for_branch_setting(xblock.location)
# if the xblock is direct-only, update the PUBLISHED version # if the revision is published, defer to base
if xblock.location.category in DIRECT_ONLY_CATEGORIES: if draft_loc.revision == MongoRevisionKey.published:
return super(DraftModuleStore, self).update_item(xblock, user_id, allow_not_found) return super(DraftModuleStore, self).update_item(xblock, user_id, allow_not_found)
draft_loc = as_draft(xblock.location)
if not super(DraftModuleStore, self).has_item(draft_loc): if not super(DraftModuleStore, self).has_item(draft_loc):
try: try:
# ignore any descendants which are already draft # ignore any descendants which are already draft
......
...@@ -78,6 +78,7 @@ from xmodule.modulestore.split_mongo.mongo_connection import MongoConnection ...@@ -78,6 +78,7 @@ from xmodule.modulestore.split_mongo.mongo_connection import MongoConnection
from xmodule.error_module import ErrorDescriptor from xmodule.error_module import ErrorDescriptor
from xmodule.modulestore.split_mongo import encode_key_for_mongo, decode_key_from_mongo from xmodule.modulestore.split_mongo import encode_key_for_mongo, decode_key_from_mongo
from _collections import defaultdict from _collections import defaultdict
from types import NoneType
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -1120,6 +1121,9 @@ class SplitMongoModuleStore(ModuleStoreWriteBase): ...@@ -1120,6 +1121,9 @@ class SplitMongoModuleStore(ModuleStoreWriteBase):
The implementation tries to detect which, if any changes, actually need to be saved and thus won't version The implementation tries to detect which, if any changes, actually need to be saved and thus won't version
the definition, structure, nor course if they didn't change. the definition, structure, nor course if they didn't change.
""" """
if allow_not_found and isinstance(descriptor.location.block_id, (LocalId, NoneType)):
return self.persist_xblock_dag(descriptor, user_id, force)
original_structure = self._lookup_course(descriptor.location)['structure'] original_structure = self._lookup_course(descriptor.location)['structure']
index_entry = self._get_index_if_valid(descriptor.location, force) index_entry = self._get_index_if_valid(descriptor.location, force)
...@@ -1181,7 +1185,10 @@ class SplitMongoModuleStore(ModuleStoreWriteBase): ...@@ -1181,7 +1185,10 @@ class SplitMongoModuleStore(ModuleStoreWriteBase):
# nothing changed, just return the one sent in # nothing changed, just return the one sent in
return descriptor return descriptor
def create_xblock(self, runtime, category, fields=None, block_id=None, definition_id=None, parent_xblock=None, **kwargs): def create_xblock(
self, runtime, course_key, block_type, block_id=None, fields=None,
definition_id=None, parent_xblock=None, **kwargs
):
""" """
This method instantiates the correct subclass of XModuleDescriptor based This method instantiates the correct subclass of XModuleDescriptor based
on the contents of json_data. It does not persist it and can create one which on the contents of json_data. It does not persist it and can create one which
...@@ -1190,13 +1197,13 @@ class SplitMongoModuleStore(ModuleStoreWriteBase): ...@@ -1190,13 +1197,13 @@ class SplitMongoModuleStore(ModuleStoreWriteBase):
parent_xblock is used to compute inherited metadata as well as to append the new xblock. parent_xblock is used to compute inherited metadata as well as to append the new xblock.
json_data: json_data:
- 'category': the xmodule category - 'block_type': the xmodule block_type
- 'fields': a dict of locally set fields (not inherited) in json format not pythonic typed format! - 'fields': a dict of locally set fields (not inherited) in json format not pythonic typed format!
- 'definition': the object id of the existing definition - 'definition': the object id of the existing definition
""" """
xblock_class = runtime.load_block_type(category) xblock_class = runtime.load_block_type(block_type)
json_data = { json_data = {
'category': category, 'category': block_type,
'fields': fields or {}, 'fields': fields or {},
} }
if definition_id is not None: if definition_id is not None:
......
...@@ -3,7 +3,7 @@ from factory.containers import CyclicDefinitionError ...@@ -3,7 +3,7 @@ from factory.containers import CyclicDefinitionError
from uuid import uuid4 from uuid import uuid4
from xmodule.modulestore import prefer_xmodules, ModuleStoreEnum from xmodule.modulestore import prefer_xmodules, ModuleStoreEnum
from opaque_keys.edx.locations import Location from opaque_keys.edx.locations import Location, SlashSeparatedCourseKey
from opaque_keys.edx.keys import UsageKey from opaque_keys.edx.keys import UsageKey
from xblock.core import XBlock from xblock.core import XBlock
from xmodule.tabs import StaticTab from xmodule.tabs import StaticTab
...@@ -55,20 +55,14 @@ class CourseFactory(XModuleFactory): ...@@ -55,20 +55,14 @@ class CourseFactory(XModuleFactory):
run = kwargs.get('run', name) run = kwargs.get('run', name)
user_id = kwargs.pop('user_id', ModuleStoreEnum.UserID.test) user_id = kwargs.pop('user_id', ModuleStoreEnum.UserID.test)
location = Location(org, number, run, 'course', name)
with store.branch_setting(ModuleStoreEnum.Branch.draft_preferred): with store.branch_setting(ModuleStoreEnum.Branch.draft_preferred):
# Write the data to the mongo datastore # Write the data to the mongo datastore
new_course = store.create_xmodule(location, metadata=kwargs.get('metadata', None)) kwargs.update(kwargs.get('metadata', {}))
course_key = SlashSeparatedCourseKey(org, number, run)
# The rest of kwargs become attributes on the course: # TODO - We really should call create_course here. However, since create_course verifies there are no
for k, v in kwargs.iteritems(): # duplicates, this breaks several tests that do not clean up properly in between tests.
setattr(new_course, k, v) new_course = store.create_xblock(None, course_key, 'course', block_id=run, fields=kwargs)
store.update_item(new_course, user_id, allow_not_found=True)
# Save the attributes we just set
new_course.save()
# Update the data in the mongo datastore
store.update_item(new_course, user_id)
return new_course return new_course
......
...@@ -9,7 +9,6 @@ from path import path ...@@ -9,7 +9,6 @@ from path import path
import re import re
import random import random
from xblock.fields import Scope
from xmodule.course_module import CourseDescriptor from xmodule.course_module import CourseDescriptor
from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.exceptions import ( from xmodule.modulestore.exceptions import (
...@@ -268,7 +267,7 @@ class SplitModuleTest(unittest.TestCase): ...@@ -268,7 +267,7 @@ class SplitModuleTest(unittest.TestCase):
"category": "problem", "category": "problem",
"fields": { "fields": {
"display_name": "Problem 3.1", "display_name": "Problem 3.1",
"graceperiod": "4 hours 0 minutes 0 seconds" "graceperiod": _time_delta_field.from_json("4 hours 0 minutes 0 seconds"),
}, },
}, },
{ {
...@@ -486,7 +485,7 @@ class SplitModuleTest(unittest.TestCase): ...@@ -486,7 +485,7 @@ class SplitModuleTest(unittest.TestCase):
parent = split_store.get_item(block_usage) parent = split_store.get_item(block_usage)
block_id = LocalId(spec['id']) block_id = LocalId(spec['id'])
child = split_store.create_xblock( child = split_store.create_xblock(
course.runtime, spec['category'], spec['fields'], block_id, parent_xblock=parent course.runtime, course.id, spec['category'], block_id, spec['fields'], parent_xblock=parent
) )
new_ele_dict[spec['id']] = child new_ele_dict[spec['id']] = child
course = split_store.persist_xblock_dag(course, revision['user_id']) course = split_store.persist_xblock_dag(course, revision['user_id'])
......
...@@ -345,8 +345,10 @@ def _import_module_and_update_references( ...@@ -345,8 +345,10 @@ def _import_module_and_update_references(
# Move the module to a new course # Move the module to a new course
new_usage_key = module.scope_ids.usage_id.map_into_course(dest_course_id) new_usage_key = module.scope_ids.usage_id.map_into_course(dest_course_id)
if new_usage_key.category == 'course': if new_usage_key.category == 'course':
new_usage_key = new_usage_key.replace(name=dest_course_id.run) block_id = dest_course_id.run
new_module = store.create_xmodule(new_usage_key, runtime=runtime) else:
block_id = module.location.block_id
new_module = store.create_xblock(runtime, dest_course_id, new_usage_key.category, block_id)
def _convert_reference_fields_to_new_namespace(reference): def _convert_reference_fields_to_new_namespace(reference):
""" """
......
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