Merge pull request #4381 from edx/nimisha/split-converge-api
Nimisha/split converge api
This commit is contained in:
@@ -36,7 +36,7 @@ def get_course_updates(location, provided_id, user_id):
|
||||
try:
|
||||
course_updates = modulestore().get_item(location)
|
||||
except ItemNotFoundError:
|
||||
course_updates = modulestore().create_and_save_xmodule(location, user_id)
|
||||
course_updates = modulestore().create_item(user_id, location.course_key, location.block_type, location.block_id)
|
||||
|
||||
course_update_items = get_course_update_items(course_updates, provided_id)
|
||||
return _get_visible_update(course_update_items)
|
||||
@@ -51,7 +51,7 @@ def update_course_updates(location, update, passed_id=None, user=None):
|
||||
try:
|
||||
course_updates = modulestore().get_item(location)
|
||||
except ItemNotFoundError:
|
||||
course_updates = modulestore().create_and_save_xmodule(location, user.id)
|
||||
course_updates = modulestore().create_item(user.id, location.course_key, location.block_type, location.block_id)
|
||||
|
||||
course_update_items = list(reversed(get_course_update_items(course_updates)))
|
||||
|
||||
|
||||
@@ -575,7 +575,7 @@ class ContentStoreToyCourseTest(ContentStoreTestCase):
|
||||
|
||||
location = course.id.make_usage_key('chapter', 'neuvo')
|
||||
# Ensure draft mongo store does not create drafts for things that shouldn't be draft
|
||||
newobject = draft_store.create_and_save_xmodule(location, self.user.id)
|
||||
newobject = draft_store.create_item(self.user.id, location.course_key, location.block_type, location.block_id)
|
||||
self.assertFalse(getattr(newobject, 'is_draft', False))
|
||||
with self.assertRaises(InvalidVersionError):
|
||||
draft_store.convert_to_draft(location, self.user.id)
|
||||
@@ -1392,12 +1392,9 @@ class ContentStoreTest(ContentStoreTestCase):
|
||||
|
||||
def test_forum_id_generation(self):
|
||||
course = CourseFactory.create(org='edX', course='999', display_name='Robot Super Course')
|
||||
new_component_location = course.id.make_usage_key('discussion', 'new_component')
|
||||
|
||||
# crate a new module and add it as a child to a vertical
|
||||
self.store.create_and_save_xmodule(new_component_location, self.user.id)
|
||||
|
||||
new_discussion_item = self.store.get_item(new_component_location)
|
||||
new_discussion_item = self.store.create_item(self.user.id, course.id, 'discussion', 'new_component')
|
||||
|
||||
self.assertNotEquals(new_discussion_item.discussion_id, '$$GUID$$')
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ class TemplateTests(unittest.TestCase):
|
||||
self.assertIsInstance(self.split_store.get_course(id_locator), CourseDescriptor)
|
||||
# and by guid
|
||||
self.assertIsInstance(self.split_store.get_item(guid_locator), CourseDescriptor)
|
||||
self.split_store.delete_course(id_locator, ModuleStoreEnum.UserID.test)
|
||||
self.split_store.delete_course(id_locator, 'testbot')
|
||||
# test can no longer retrieve by id
|
||||
self.assertRaises(ItemNotFoundError, self.split_store.get_course, id_locator)
|
||||
# but can by guid
|
||||
@@ -187,16 +187,16 @@ class TemplateTests(unittest.TestCase):
|
||||
)
|
||||
first_problem.max_attempts = 3
|
||||
first_problem.save() # decache the above into the kvs
|
||||
updated_problem = self.split_store.update_item(first_problem, ModuleStoreEnum.UserID.test)
|
||||
updated_problem = self.split_store.update_item(first_problem, 'testbot')
|
||||
self.assertIsNotNone(updated_problem.previous_version)
|
||||
self.assertEqual(updated_problem.previous_version, first_problem.update_version)
|
||||
self.assertNotEqual(updated_problem.update_version, first_problem.update_version)
|
||||
updated_loc = self.split_store.delete_item(updated_problem.location, ModuleStoreEnum.UserID.test, 'testbot')
|
||||
self.split_store.delete_item(updated_problem.location, 'testbot')
|
||||
|
||||
second_problem = persistent_factories.ItemFactory.create(
|
||||
display_name='problem 2',
|
||||
parent_location=BlockUsageLocator.make_relative(
|
||||
updated_loc, block_type='problem', block_id=sub.location.block_id
|
||||
test_course.location.version_agnostic(), block_type='problem', block_id=sub.location.block_id
|
||||
),
|
||||
user_id='testbot', category='problem',
|
||||
data="<problem></problem>"
|
||||
|
||||
@@ -33,8 +33,14 @@ class TestOrphan(CourseTestCase):
|
||||
def _create_item(self, category, name, data, metadata, parent_category, parent_name, runtime):
|
||||
location = self.course.location.replace(category=category, name=name)
|
||||
store = modulestore()
|
||||
store.create_and_save_xmodule(
|
||||
location, self.user.id, definition_data=data, metadata=metadata, runtime=runtime
|
||||
store.create_item(
|
||||
self.user.id,
|
||||
location.course_key,
|
||||
location.block_type,
|
||||
location.block_id,
|
||||
definition_data=data,
|
||||
metadata=metadata,
|
||||
runtime=runtime
|
||||
)
|
||||
if parent_name:
|
||||
# add child to parent in mongo
|
||||
|
||||
@@ -151,11 +151,11 @@ class CourseTestCase(ModuleStoreTestCase):
|
||||
self.assertEqual(self.store.compute_publish_state(draft_vertical), PublishState.draft)
|
||||
|
||||
# create a Private (draft only) vertical
|
||||
private_vertical = self.store.create_and_save_xmodule(course_id.make_usage_key('vertical', self.PRIVATE_VERTICAL), self.user.id)
|
||||
private_vertical = self.store.create_item(self.user.id, course_id, 'vertical', self.PRIVATE_VERTICAL)
|
||||
self.assertEqual(self.store.compute_publish_state(private_vertical), PublishState.private)
|
||||
|
||||
# create a Published (no draft) vertical
|
||||
public_vertical = self.store.create_and_save_xmodule(course_id.make_usage_key('vertical', self.PUBLISHED_VERTICAL), self.user.id)
|
||||
public_vertical = self.store.create_item(self.user.id, course_id, 'vertical', self.PUBLISHED_VERTICAL)
|
||||
public_vertical = self.store.publish(public_vertical.location, self.user.id)
|
||||
self.assertEqual(self.store.compute_publish_state(public_vertical), PublishState.public)
|
||||
|
||||
|
||||
@@ -287,7 +287,7 @@ def _save_item(user, usage_key, data=None, children=None, metadata=None, nullout
|
||||
if usage_key.category in CREATE_IF_NOT_FOUND:
|
||||
# New module at this location, for pages that are not pre-created.
|
||||
# Used for course info handouts.
|
||||
existing_item = store.create_and_save_xmodule(usage_key, user.id)
|
||||
existing_item = store.create_item(user.id, usage_key.course_key, usage_key.block_type, usage_key.block_id)
|
||||
else:
|
||||
raise
|
||||
except InvalidLocationError:
|
||||
@@ -416,9 +416,11 @@ def _create_item(request):
|
||||
if display_name is not None:
|
||||
metadata['display_name'] = display_name
|
||||
|
||||
created_block = store.create_and_save_xmodule(
|
||||
dest_usage_key,
|
||||
created_block = store.create_child(
|
||||
request.user.id,
|
||||
usage_key,
|
||||
dest_usage_key.block_type,
|
||||
block_id=dest_usage_key.block_id,
|
||||
definition_data=data,
|
||||
metadata=metadata,
|
||||
runtime=parent.runtime,
|
||||
@@ -437,11 +439,6 @@ def _create_item(request):
|
||||
)
|
||||
store.update_item(course, request.user.id)
|
||||
|
||||
# TODO replace w/ nicer accessor
|
||||
if not 'detached' in parent.runtime.load_block_type(category)._class_tags:
|
||||
parent.children.append(created_block.location)
|
||||
store.update_item(parent, request.user.id)
|
||||
|
||||
return JsonResponse({"locator": unicode(created_block.location), "courseKey": unicode(created_block.location.course_key)})
|
||||
|
||||
|
||||
@@ -465,11 +462,11 @@ def _duplicate_item(parent_usage_key, duplicate_source_usage_key, user, display_
|
||||
else:
|
||||
duplicate_metadata['display_name'] = _("Duplicate of '{0}'").format(source_item.display_name)
|
||||
|
||||
dest_module = store.create_and_save_xmodule(
|
||||
dest_usage_key,
|
||||
|
||||
|
||||
dest_module = store.create_item(
|
||||
user.id,
|
||||
dest_usage_key.course_key,
|
||||
dest_usage_key.block_type,
|
||||
block_id=dest_usage_key.block_id,
|
||||
definition_data=source_item.get_explicitly_set_fields_by_scope(Scope.content),
|
||||
metadata=duplicate_metadata,
|
||||
runtime=source_item.runtime,
|
||||
@@ -531,7 +528,7 @@ def orphan_handler(request, course_key_string):
|
||||
course_usage_key = CourseKey.from_string(course_key_string)
|
||||
if request.method == 'GET':
|
||||
if has_course_access(request.user, course_usage_key):
|
||||
return JsonResponse(modulestore().get_orphans(course_usage_key))
|
||||
return JsonResponse([unicode(item) for item in modulestore().get_orphans(course_usage_key)])
|
||||
else:
|
||||
raise PermissionDenied()
|
||||
if request.method == 'DELETE':
|
||||
@@ -539,11 +536,9 @@ def orphan_handler(request, course_key_string):
|
||||
store = modulestore()
|
||||
items = store.get_orphans(course_usage_key)
|
||||
for itemloc in items:
|
||||
# get_orphans returns the deprecated string format w/o revision
|
||||
usage_key = course_usage_key.make_usage_key_from_deprecated_string(itemloc)
|
||||
# need to delete all versions
|
||||
store.delete_item(usage_key, request.user.id, revision=ModuleStoreEnum.RevisionOption.all)
|
||||
return JsonResponse({'deleted': items})
|
||||
store.delete_item(itemloc, request.user.id, revision=ModuleStoreEnum.RevisionOption.all)
|
||||
return JsonResponse({'deleted': [unicode(item) for item in items]})
|
||||
else:
|
||||
raise PermissionDenied()
|
||||
|
||||
@@ -559,7 +554,7 @@ def _get_module_info(usage_key, user, rewrite_static_links=True):
|
||||
except ItemNotFoundError:
|
||||
if usage_key.category in CREATE_IF_NOT_FOUND:
|
||||
# Create a new one for certain categories only. Used for course info handouts.
|
||||
module = store.create_and_save_xmodule(usage_key, user.id)
|
||||
module = store.create_item(user.id, usage_key.course_key, usage_key.block_type, block_id=usage_key.block_id)
|
||||
else:
|
||||
raise
|
||||
|
||||
|
||||
@@ -130,7 +130,12 @@ class CourseUpdateTest(CourseTestCase):
|
||||
'''
|
||||
# get the updates and populate 'data' field with some data.
|
||||
location = self.course.id.make_usage_key('course_info', 'updates')
|
||||
course_updates = modulestore().create_and_save_xmodule(location, self.user.id)
|
||||
course_updates = modulestore().create_item(
|
||||
self.user.id,
|
||||
location.course_key,
|
||||
location.block_type,
|
||||
block_id=location.block_id
|
||||
)
|
||||
update_date = u"January 23, 2014"
|
||||
update_content = u"Hello world!"
|
||||
update_data = u"<ol><li><h2>" + update_date + "</h2>" + update_content + "</li></ol>"
|
||||
@@ -204,7 +209,12 @@ class CourseUpdateTest(CourseTestCase):
|
||||
'''Test trying to add to a saved course_update which is not an ol.'''
|
||||
# get the updates and set to something wrong
|
||||
location = self.course.id.make_usage_key('course_info', 'updates')
|
||||
modulestore().create_and_save_xmodule(location, self.user.id)
|
||||
modulestore().create_item(
|
||||
self.user.id,
|
||||
location.course_key,
|
||||
location.block_type,
|
||||
block_id=location.block_id
|
||||
)
|
||||
course_updates = modulestore().get_item(location)
|
||||
course_updates.data = 'bad news'
|
||||
modulestore().update_item(course_updates, self.user.id)
|
||||
@@ -229,8 +239,7 @@ class CourseUpdateTest(CourseTestCase):
|
||||
"""
|
||||
Test that a user can successfully post on course updates and handouts of a course
|
||||
"""
|
||||
course_key = SlashSeparatedCourseKey('Org1', 'Course_1', 'Run_1')
|
||||
course_update_url = self.create_update_url(course_key=course_key)
|
||||
course_update_url = self.create_update_url(course_key=self.course.id)
|
||||
|
||||
# create a course via the view handler
|
||||
self.client.ajax_post(course_update_url)
|
||||
|
||||
@@ -63,7 +63,7 @@ STATICFILES_DIRS += [
|
||||
MODULESTORE['default']['OPTIONS']['stores'].append(
|
||||
{
|
||||
'NAME': 'split',
|
||||
'ENGINE': 'xmodule.modulestore.split_mongo.split.SplitMongoModuleStore',
|
||||
'ENGINE': 'xmodule.modulestore.split_mongo.split_draft.DraftVersioningModuleStore',
|
||||
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
|
||||
'OPTIONS': {
|
||||
'render_template': 'edxmako.shortcuts.render_to_string',
|
||||
|
||||
Reference in New Issue
Block a user