add a delete-all-versions flag to the delete_item method in the modulestores. Extend tests to verify. Still wip

This commit is contained in:
Chris Dodge
2013-04-25 15:24:31 -04:00
parent e43c2bd410
commit f6417b4f71
4 changed files with 41 additions and 18 deletions

View File

@@ -264,15 +264,27 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
def test_delete(self):
import_from_xml(modulestore(), 'common/test/data/', ['full'])
module_store = modulestore('direct')
direct_store = modulestore('direct')
draft_store = modulestore('draft')
sequential = module_store.get_item(Location(['i4x', 'edX', 'full', 'sequential', 'Administrivia_and_Circuit_Elements', None]))
sequential = direct_store.get_item(Location(['i4x', 'edX', 'full', 'sequential', 'Administrivia_and_Circuit_Elements', None]))
chapter = module_store.get_item(Location(['i4x', 'edX', 'full', 'chapter', 'Week_1', None]))
chapter = direct_store.get_item(Location(['i4x', 'edX', 'full', 'chapter', 'Week_1', None]))
# make sure the parent no longer points to the child object which was deleted
# make sure the parent points to the child object which is to be deleted
self.assertTrue(sequential.location.url() in chapter.children)
# get a vertical (and components in it) to put into 'draft'
vertical = direct_store.get_item(Location(['i4x', 'edX', 'full',
'vertical', 'vertical_66', None]))
private_item_location = vertical.location._replace(name='private_vertical')
draft_store.clone_item(vertical.location, private_item_location)
direct_store.update_children(sequential.location, sequential.children +
[private_item_location.url()])
self.client.post(
reverse('delete_item'),
json.dumps({'id': sequential.location.url(), 'delete_children': 'true', 'delete_all_versions': 'true'}),
@@ -281,18 +293,28 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
found = False
try:
module_store.get_item(Location(['i4x', 'edX', 'full', 'sequential', 'Administrivia_and_Circuit_Elements', None]))
draft_store.get_item(Location(['i4x', 'edX', 'full', 'sequential', 'Administrivia_and_Circuit_Elements', None]))
found = True
except ItemNotFoundError:
pass
self.assertFalse(found)
chapter = module_store.get_item(Location(['i4x', 'edX', 'full', 'chapter', 'Week_1', None]))
chapter = draft_store.get_item(Location(['i4x', 'edX', 'full', 'chapter', 'Week_1', None]))
# make sure the parent no longer points to the child object which was deleted
self.assertFalse(sequential.location.url() in chapter.children)
# make sure we can't look up the private vertical
found_private = False
try:
draft_store.get_item(private_item_location)
found_private = True
except ItemNotFoundError:
pass
self.assertFalse(found_private)
def test_about_overrides(self):
'''
This test case verifies that a course can use specialized override for about data, e.g. /about/Fall_2012/effort.html

View File

@@ -624,16 +624,9 @@ def delete_item(request):
# if caller wants to only delete the draft than the caller should put item.location.revision='draft'
if delete_children:
_xmodule_recurse(item, lambda i: store.delete_item(i.location))
_xmodule_recurse(item, lambda i: store.delete_item(i.location, delete_all_versions))
else:
store.delete_item(item.location)
# cdodge: this is a bit of a hack until I can talk with Cale about the
# semantics of delete_item whereby the store is draft aware. Right now calling
# delete_item on a vertical tries to delete the draft version leaving the
# requested delete to never occur
if item.location.revision is None and item.location.category == 'vertical' and delete_all_versions:
modulestore('direct').delete_item(item.location)
store.delete_item(item.location, delete_all_versions)
# cdodge: we need to remove our parent's pointer to us so that it is no longer dangling
if delete_all_versions: