Make unpublish raise the same errors in split and old-mongo when asked to unpublish a DIRECT_ONLY_CATEGORY
This commit is contained in:
@@ -87,6 +87,11 @@ class ModuleStoreDraftAndPublished(BranchSettingMixin, BulkOperationsMixin):
|
||||
|
||||
@abstractmethod
|
||||
def unpublish(self, location, user_id):
|
||||
"""
|
||||
Turn the published version into a draft, removing the published version.
|
||||
|
||||
Raises: InvalidVersionError if called on a DIRECT_ONLY_CATEGORY
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
|
||||
@@ -754,6 +754,10 @@ class DraftModuleStore(MongoModuleStore):
|
||||
NOTE: unlike publish, this gives an error if called above the draftable level as it's intended
|
||||
to remove things from the published version
|
||||
"""
|
||||
# ensure we are not creating a DRAFT of an item that is direct-only
|
||||
if location.category in DIRECT_ONLY_CATEGORIES:
|
||||
raise InvalidVersionError(location)
|
||||
|
||||
self._verify_branch_setting(ModuleStoreEnum.Branch.draft_preferred)
|
||||
self._convert_to_draft(location, user_id, delete_published=True)
|
||||
|
||||
|
||||
@@ -377,6 +377,9 @@ class DraftVersioningModuleStore(SplitMongoModuleStore, ModuleStoreDraftAndPubli
|
||||
Deletes the published version of the item.
|
||||
Returns the newly unpublished item.
|
||||
"""
|
||||
if location.block_type in DIRECT_ONLY_CATEGORIES:
|
||||
raise InvalidVersionError(location)
|
||||
|
||||
with self.bulk_operations(location.course_key):
|
||||
self.delete_item(location, user_id, revision=ModuleStoreEnum.RevisionOption.published_only)
|
||||
return self.get_item(location.for_branch(ModuleStoreEnum.BranchName.draft), **kwargs)
|
||||
|
||||
@@ -925,49 +925,16 @@ class ElementalUnpublishingTests(DraftPublishedOpBaseTestSetup):
|
||||
self.assertOLXIsDraftOnly(block_list_unpublished_children)
|
||||
self.assertOLXIsDraftOnly(block_list_untouched)
|
||||
|
||||
@ddt.data(DRAFT_MODULESTORE_SETUP, MongoModulestoreBuilder())
|
||||
def test_unpublish_old_mongo_draft_sequential(self, modulestore_builder):
|
||||
@ddt.data(SPLIT_MODULESTORE_SETUP, DRAFT_MODULESTORE_SETUP, MongoModulestoreBuilder())
|
||||
def test_unpublish_draft_sequential(self, modulestore_builder):
|
||||
with self._setup_test(modulestore_builder):
|
||||
|
||||
# MODULESTORE_DIFFERENCE:
|
||||
# In old Mongo, you cannot successfully unpublish an autopublished sequential.
|
||||
# An exception is thrown.
|
||||
block_list_to_unpublish = (
|
||||
('sequential', 'sequential03'),
|
||||
)
|
||||
with self.assertRaises(InvalidVersionError):
|
||||
self.unpublish(block_list_to_unpublish)
|
||||
|
||||
@ddt.data(SPLIT_MODULESTORE_SETUP)
|
||||
def test_unpublish_split_draft_sequential(self, modulestore_builder):
|
||||
with self._setup_test(modulestore_builder):
|
||||
|
||||
# MODULESTORE_DIFFERENCE:
|
||||
# In Split, the sequential is deleted.
|
||||
# The sequential's children are orphaned - but they stay in
|
||||
# the same draft state they were before.
|
||||
block_list_to_unpublish = (
|
||||
('sequential', 'sequential03'),
|
||||
)
|
||||
block_list_unpublished_children = (
|
||||
('vertical', 'vertical06'),
|
||||
('vertical', 'vertical07'),
|
||||
('html', 'html12'),
|
||||
('html', 'html13'),
|
||||
('html', 'html14'),
|
||||
('html', 'html15'),
|
||||
)
|
||||
# The autopublished sequential is published - its children are draft.
|
||||
self.assertOLXIsPublishedOnly(block_list_to_unpublish)
|
||||
self.assertOLXIsDraftOnly(block_list_unpublished_children)
|
||||
# Unpublish the sequential.
|
||||
self.unpublish(block_list_to_unpublish)
|
||||
# Since the sequential was autopublished, a draft version of the sequential never existed.
|
||||
# So unpublishing the sequential doesn't make it a draft - it deletes it!
|
||||
self.assertOLXIsDeleted(block_list_to_unpublish)
|
||||
# Its children are orphaned and remain as drafts.
|
||||
self.assertOLXIsDraftOnly(block_list_unpublished_children)
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class ElementalDeleteItemTests(DraftPublishedOpBaseTestSetup):
|
||||
|
||||
@@ -45,7 +45,7 @@ class TestCCXModulestoreWrapper(SharedModuleStoreTestCase):
|
||||
) for _ in xrange(2) for s in sequentials
|
||||
]
|
||||
cls.blocks = [
|
||||
ItemFactory.create(parent=v) for _ in xrange(2) for v in verticals
|
||||
ItemFactory.create(parent=v, category='html') for _ in xrange(2) for v in verticals
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
|
||||
Reference in New Issue
Block a user