From b7955fab77338ebb779ecb1e172911bae80c9f64 Mon Sep 17 00:00:00 2001 From: Syed Hassan Raza Date: Thu, 2 Apr 2015 18:30:14 +0500 Subject: [PATCH] Static tab as orphan --- cms/djangoapps/contentstore/views/tests/test_item.py | 9 ++++++--- .../xmodule/modulestore/split_mongo/split_draft.py | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cms/djangoapps/contentstore/views/tests/test_item.py b/cms/djangoapps/contentstore/views/tests/test_item.py index 3bc3982f99..3632fd4d75 100644 --- a/cms/djangoapps/contentstore/views/tests/test_item.py +++ b/cms/djangoapps/contentstore/views/tests/test_item.py @@ -27,7 +27,7 @@ from xmodule.capa_module import CapaDescriptor from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, TEST_DATA_SPLIT_MODULESTORE -from xmodule.modulestore.tests.factories import ItemFactory, LibraryFactory, check_mongo_calls +from xmodule.modulestore.tests.factories import ItemFactory, LibraryFactory, check_mongo_calls, CourseFactory from xmodule.x_module import STUDIO_VIEW, STUDENT_VIEW from xblock.exceptions import NoSuchHandlerError from xblock_django.user_service import DjangoXBlockUserService @@ -310,11 +310,14 @@ class GetItemTest(ItemTest): ) +@ddt.ddt class DeleteItem(ItemTest): """Tests for '/xblock' DELETE url.""" - def test_delete_static_page(self): + @ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split) + def test_delete_static_page(self, store): + course = CourseFactory.create(default_store=store) # Add static tab - resp = self.create_xblock(category='static_tab') + resp = self.create_xblock(category='static_tab', parent_usage_key=course.location) usage_key = self.response_usage_key(resp) # Now delete it. There was a bug that the delete was failing (static tabs do not exist in draft modulestore). diff --git a/common/lib/xmodule/xmodule/modulestore/split_mongo/split_draft.py b/common/lib/xmodule/xmodule/modulestore/split_mongo/split_draft.py index e69c172d73..b3d4301e84 100644 --- a/common/lib/xmodule/xmodule/modulestore/split_mongo/split_draft.py +++ b/common/lib/xmodule/xmodule/modulestore/split_mongo/split_draft.py @@ -213,7 +213,11 @@ class DraftVersioningModuleStore(SplitMongoModuleStore, ModuleStoreDraftAndPubli parent_loc = self.get_parent_location(branched_location) SplitMongoModuleStore.delete_item(self, branched_location, user_id) # publish parent w/o child if deleted element is direct only (not based on type of parent) - if branch == ModuleStoreEnum.BranchName.draft and branched_location.block_type in DIRECT_ONLY_CATEGORIES: + if ( + branch == ModuleStoreEnum.BranchName.draft and + branched_location.block_type in DIRECT_ONLY_CATEGORIES and parent_loc + ): + # will publish if its not an orphan self.publish(parent_loc.version_agnostic(), user_id, blacklist=EXCLUDE_ALL, **kwargs) def _map_revision_to_branch(self, key, revision=None):