Merge pull request #6097 from edx/jeskew/fix_exception_on_fill_run
When fill_in_run() fails, handle failure instead of exception.
This commit is contained in:
@@ -1486,9 +1486,16 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
|
||||
# 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)
|
||||
course_assets = self.asset_collection.find_one(
|
||||
{'course_id': unicode(course_key)},
|
||||
)
|
||||
if course_key.run is None:
|
||||
log.warning(u'No run found for combo org "{}" course "{}" on asset request.'.format(
|
||||
course_key.org, course_key.course
|
||||
))
|
||||
course_assets = None
|
||||
else:
|
||||
# Complete course key, so query for asset metadata.
|
||||
course_assets = self.asset_collection.find_one(
|
||||
{'course_id': unicode(course_key)},
|
||||
)
|
||||
|
||||
doc_id = None if course_assets is None else course_assets['_id']
|
||||
if course_assets is None:
|
||||
@@ -1607,9 +1614,7 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
|
||||
dest_course_key (CourseKey): identifier of course to copy to
|
||||
"""
|
||||
source_assets = self._find_course_assets(source_course_key)
|
||||
dest_assets = {'assets': source_assets.asset_md.copy()}
|
||||
dest_assets['course_id'] = unicode(dest_course_key)
|
||||
|
||||
dest_assets = {'assets': source_assets.asset_md.copy(), 'course_id': unicode(dest_course_key)}
|
||||
self.asset_collection.remove({'course_id': unicode(dest_course_key)})
|
||||
# Update the document.
|
||||
self.asset_collection.insert(dest_assets)
|
||||
|
||||
@@ -29,7 +29,7 @@ from xmodule.modulestore import ModuleStoreEnum
|
||||
from xmodule.modulestore.mongo import MongoKeyValueStore
|
||||
from xmodule.modulestore.draft import DraftModuleStore
|
||||
from opaque_keys.edx.locations import SlashSeparatedCourseKey, AssetLocation
|
||||
from opaque_keys.edx.locator import LibraryLocator
|
||||
from opaque_keys.edx.locator import LibraryLocator, CourseLocator
|
||||
from opaque_keys.edx.keys import UsageKey
|
||||
from xmodule.modulestore.xml_exporter import export_to_xml
|
||||
from xmodule.modulestore.xml_importer import import_from_xml, perform_xlint
|
||||
@@ -42,6 +42,8 @@ from xmodule.x_module import XModuleMixin
|
||||
from xmodule.modulestore.mongo.base import as_draft
|
||||
from xmodule.modulestore.tests.mongo_connection import MONGO_PORT_NUM, MONGO_HOST
|
||||
from xmodule.modulestore.edit_info import EditInfoMixin
|
||||
from xmodule.modulestore.exceptions import ItemNotFoundError
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -701,6 +703,11 @@ class TestMongoModuleStoreWithNoAssetCollection(TestMongoModuleStore):
|
||||
# Confirm that no specified asset collection name means empty asset metadata.
|
||||
self.assertEquals(self.draft_store.get_all_asset_metadata(course.id, 'asset'), [])
|
||||
|
||||
def test_no_asset_invalid_key(self):
|
||||
course_key = CourseLocator(org="edx3", course="test_course", run=None, deprecated=True)
|
||||
# Confirm that invalid course key raises ItemNotFoundError
|
||||
self.assertRaises(ItemNotFoundError, lambda: self.draft_store.get_all_asset_metadata(course_key, 'asset')[:1])
|
||||
|
||||
|
||||
class TestMongoKeyValueStore(object):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user