From b6590228a3e7c07bc0f5743e6ae4e54169fd367f Mon Sep 17 00:00:00 2001 From: Nimisha Asthagiri Date: Wed, 3 Sep 2014 14:32:06 -0400 Subject: [PATCH] LMS-11342 Fix Split reimport issue. --- cms/djangoapps/contentstore/tests/test_import.py | 15 ++++++++++++--- .../modulestore/split_mongo/split_draft.py | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/test_import.py b/cms/djangoapps/contentstore/tests/test_import.py index 89d1a3c316..ac994880fc 100644 --- a/cms/djangoapps/contentstore/tests/test_import.py +++ b/cms/djangoapps/contentstore/tests/test_import.py @@ -8,14 +8,14 @@ Tests for import_from_xml using the mongo modulestore. from django.test.client import Client from django.test.utils import override_settings from django.conf import settings +import ddt import copy from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore from xmodule.contentstore.django import contentstore -from xmodule.modulestore.exceptions import DuplicateCourseError -from xmodule.modulestore.tests.factories import check_exact_number_of_calls, check_number_of_calls, CourseFactory +from xmodule.modulestore.tests.factories import check_exact_number_of_calls, check_number_of_calls from opaque_keys.edx.locations import SlashSeparatedCourseKey, AssetLocation from xmodule.modulestore.xml_importer import import_from_xml from xmodule.exceptions import NotFoundError @@ -25,6 +25,7 @@ TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE) TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex +@ddt.ddt @override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE) class ContentStoreImportTest(ModuleStoreTestCase): """ @@ -37,7 +38,7 @@ class ContentStoreImportTest(ModuleStoreTestCase): self.client = Client() self.client.login(username=self.user.username, password=password) - def load_test_import_course(self): + def load_test_import_course(self, target_course_id=None, create_new_course_if_not_present=False): ''' Load the standard course used to test imports (for do_import_static=False behavior). @@ -52,6 +53,8 @@ class ContentStoreImportTest(ModuleStoreTestCase): static_content_store=content_store, do_import_static=False, verbose=True, + target_course_id=target_course_id, + create_new_course_if_not_present=create_new_course_if_not_present, ) course_id = SlashSeparatedCourseKey('edX', 'test_import_course', '2012_Fall') course = module_store.get_course(course_id) @@ -168,6 +171,12 @@ class ContentStoreImportTest(ModuleStoreTestCase): with check_number_of_calls(store, '_compute_metadata_inheritance_tree', 2): self.load_test_import_course() + @ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split) + def test_reimport(self, default_ms_type): + with modulestore().default_store(default_ms_type): + __, __, course = self.load_test_import_course(create_new_course_if_not_present=True) + self.load_test_import_course(target_course_id=course.id) + def test_rewrite_reference_list(self): module_store = modulestore() target_course_id = SlashSeparatedCourseKey('testX', 'conditional_copy', 'copy_run') 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 6fd7caf5ec..8c6abc2cd5 100644 --- a/common/lib/xmodule/xmodule/modulestore/split_mongo/split_draft.py +++ b/common/lib/xmodule/xmodule/modulestore/split_mongo/split_draft.py @@ -386,7 +386,7 @@ class DraftVersioningModuleStore(ModuleStoreDraftAndPublished, SplitMongoModuleS course_key = self._map_revision_to_branch(course_key) # cast to branch_setting return self._update_item_from_fields( user_id, course_key, block_type, block_id, partitioned_fields, None, allow_not_found=True, force=True - ) + ) or self.get_item(new_usage_key) def compute_published_info_internal(self, xblock): """