diff --git a/common/lib/xmodule/xmodule/modulestore/mongo/base.py b/common/lib/xmodule/xmodule/modulestore/mongo/base.py index f1c66545b7..dfd63fbc24 100644 --- a/common/lib/xmodule/xmodule/modulestore/mongo/base.py +++ b/common/lib/xmodule/xmodule/modulestore/mongo/base.py @@ -436,6 +436,10 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo """ A Mongodb backed ModuleStore """ + + # If no name is specified for the asset metadata collection, this name is used. + DEFAULT_ASSET_COLLECTION_NAME = 'assetstore' + # TODO (cpennington): Enable non-filesystem filestores # pylint: disable=C0103 # pylint: disable=W0201 @@ -474,9 +478,9 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo self.collection = self.database[collection] # Collection which stores asset metadata. - self.asset_collection = None - if asset_collection is not None: - self.asset_collection = self.database[asset_collection] + if asset_collection is None: + asset_collection = self.DEFAULT_ASSET_COLLECTION_NAME + self.asset_collection = self.database[asset_collection] if user is not None and password is not None: self.database.authenticate(user, password) @@ -1465,9 +1469,6 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo Returns: Asset info for the course """ - if self.asset_collection is None: - return None - # Using the course_key, find or insert the course asset metadata document. # A single document exists per course to store the course asset metadata. course_key = self.fill_in_run(course_key) @@ -1493,9 +1494,6 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo Returns: True if info save was successful, else False """ - if self.asset_collection is None: - return False - course_assets, asset_idx = self._find_course_asset(asset_metadata.asset_id) all_assets = SortedListWithKey([], key=itemgetter('filename')) # Assets should be pre-sorted, so add them efficiently without sorting. @@ -1552,9 +1550,6 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo ItemNotFoundError if no such item exists AttributeError is attr is one of the build in attrs. """ - if self.asset_collection is None: - return - course_assets, asset_idx = self._find_course_asset(asset_key) if asset_idx is None: raise ItemNotFoundError(asset_key) @@ -1581,9 +1576,6 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo Returns: Number of asset metadata entries deleted (0 or 1) """ - if self.asset_collection is None: - return 0 - course_assets, asset_idx = self._find_course_asset(asset_key) if asset_idx is None: return 0 @@ -1607,9 +1599,6 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo Arguments: course_key (CourseKey): course_identifier """ - if self.asset_collection is None: - return - # Using the course_id, find the course asset metadata document. # A single document exists per course to store the course asset metadata. course_assets = self._find_course_assets(course_key) diff --git a/common/lib/xmodule/xmodule/modulestore/split_mongo/mongo_connection.py b/common/lib/xmodule/xmodule/modulestore/split_mongo/mongo_connection.py index 027e8c8a93..7203e39b7d 100644 --- a/common/lib/xmodule/xmodule/modulestore/split_mongo/mongo_connection.py +++ b/common/lib/xmodule/xmodule/modulestore/split_mongo/mongo_connection.py @@ -93,10 +93,6 @@ class MongoConnection(object): wait_time=retry_wait_time ) - # Remove when adding official Split support for asset metadata storage. - if asset_collection: - pass - if user is not None and password is not None: self.database.authenticate(user, password) diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py b/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py index 8a0ea068d2..ab2afc1bc8 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py @@ -685,8 +685,8 @@ class TestMongoModuleStoreWithNoAssetCollection(TestMongoModuleStore): def test_no_asset_collection(self): courses = self.draft_store.get_courses() course = courses[0] - # Confirm that no asset collection means no asset metadata. - self.assertEquals(self.draft_store.get_all_asset_metadata(course.id, 'asset'), None) + # Confirm that no specified asset collection name means empty asset metadata. + self.assertEquals(self.draft_store.get_all_asset_metadata(course.id, 'asset'), []) class TestMongoKeyValueStore(object): diff --git a/lms/envs/common.py b/lms/envs/common.py index 6442bcf9d7..edfe6454bc 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -570,7 +570,9 @@ DOC_STORE_CONFIG = { 'host': 'localhost', 'db': 'xmodule', 'collection': 'modulestore', - 'asset_collection': 'assetstore', + # If 'asset_collection' defined, it'll be used + # as the collection name for asset metadata. + # Otherwise, a default collection name will be used. } MODULESTORE = { 'default': {