From b87d469c89b24d8ca8577e85c2234990ce0e8bfb Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Mon, 21 Jul 2014 15:14:14 -0400 Subject: [PATCH] Add make_course_key to modulestores, so that external clients don't need to assume a CourseKey subtype. Conflicts: common/lib/xmodule/xmodule/modulestore/xml_importer.py --- common/lib/xmodule/xmodule/modulestore/mixed.py | 9 +++++++++ .../tests/test_cross_modulestore_import_export.py | 10 +++++++--- common/lib/xmodule/xmodule/modulestore/xml_importer.py | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/common/lib/xmodule/xmodule/modulestore/mixed.py b/common/lib/xmodule/xmodule/modulestore/mixed.py index 766cd82d1e..3b3f927c9f 100644 --- a/common/lib/xmodule/xmodule/modulestore/mixed.py +++ b/common/lib/xmodule/xmodule/modulestore/mixed.py @@ -170,6 +170,15 @@ class MixedModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase): # return the default store return self.default_modulestore + # return the first store, as the default + return self.default_modulestore + + @property + def default_modulestore(self): + """ + Return the default modulestore + """ + return self.modulestores[0] def _get_modulestore_by_type(self, modulestore_type): """ diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_cross_modulestore_import_export.py b/common/lib/xmodule/xmodule/modulestore/tests/test_cross_modulestore_import_export.py index 0ea2fae369..903117dd64 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_cross_modulestore_import_export.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_cross_modulestore_import_export.py @@ -235,7 +235,10 @@ MODULESTORE_SETUPS = ( MixedModulestoreBuilder([('split', VersioningModulestoreBuilder())]), ) CONTENTSTORE_SETUPS = (MongoContentstoreBuilder(),) -COURSE_DATA_NAMES = ('toy', 'manual-testing-complete') +COURSE_DATA_NAMES = ( + 'toy', + 'manual-testing-complete', +) @ddt.ddt @@ -259,8 +262,6 @@ class CrossStoreXMLRoundtrip(CourseComparisonTest): )) @ddt.unpack def test_round_trip(self, source_builder, dest_builder, source_content_builder, dest_content_builder, course_data_name): - source_course_key = SlashSeparatedCourseKey('source', 'course', 'key') - dest_course_key = SlashSeparatedCourseKey('dest', 'course', 'key') # Construct the contentstore for storing the first import with source_content_builder.build() as source_content: @@ -270,6 +271,9 @@ class CrossStoreXMLRoundtrip(CourseComparisonTest): with dest_content_builder.build() as dest_content: # Construct the modulestore for storing the second import (using the second contentstore) with dest_builder.build(dest_content) as dest_store: + source_course_key = source_store.make_course_key('source', 'course', 'key') + dest_course_key = dest_store.make_course_key('dest', 'course', 'key') + import_from_xml( source_store, 'test_user', diff --git a/common/lib/xmodule/xmodule/modulestore/xml_importer.py b/common/lib/xmodule/xmodule/modulestore/xml_importer.py index 57063581c7..de4bb31028 100644 --- a/common/lib/xmodule/xmodule/modulestore/xml_importer.py +++ b/common/lib/xmodule/xmodule/modulestore/xml_importer.py @@ -168,7 +168,7 @@ def import_from_xml( if target_course_id is not None: dest_course_id = target_course_id else: - dest_course_id = course_key + dest_course_id = store.make_course_key(course_key.org, course_key.course, course_key.run) # Creates a new course if it doesn't already exist if create_new_course_if_not_present and not store.has_course(dest_course_id, ignore_case=True):