Commit 7cebb873 by Chris Dodge

allow for an optional throw_on_not_found on contentstore().find() so we can…

allow for an optional throw_on_not_found on contentstore().find() so we can clean up caller logic in the tests
parent dc94ea10
...@@ -435,14 +435,12 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -435,14 +435,12 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
import_from_xml(module_store, 'common/test/data/', ['full'], static_content_store=content_store) import_from_xml(module_store, 'common/test/data/', ['full'], static_content_store=content_store)
content = None # look up original (and thumbnail) in content store, should be there after import
try: location = StaticContent.get_location_from_path('/c4x/edX/full/asset/circuits_duality.gif')
location = StaticContent.get_location_from_path('/c4x/edX/full/asset/circuits_duality.gif') content = content_store.find(location, throw_on_not_found=False)
content = content_store.find(location) thumbnail_location = content.thumbnail_location
except NotFoundError:
pass
self.assertIsNotNone(content) self.assertIsNotNone(content)
self.assertIsNotNone(thumbnail_location)
# go through the website to do the delete, since the soft-delete logic is in the view # go through the website to do the delete, since the soft-delete logic is in the view
...@@ -453,26 +451,14 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -453,26 +451,14 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
asset_location = StaticContent.get_location_from_path('/c4x/edX/full/asset/circuits_duality.gif') asset_location = StaticContent.get_location_from_path('/c4x/edX/full/asset/circuits_duality.gif')
# now try to find it in store, but they should not be there any longer # now try to find it in store, but they should not be there any longer
content = None content = content_store.find(asset_location, throw_on_not_found=False)
thumbnail = None thumbnail = content_store.find(thumbnail_location, throw_on_not_found=False)
try:
content = content_store.find(asset_location)
thumbnail = trash_store.find(content.thumbnail_location)
except NotFoundError:
pass
self.assertIsNone(content) self.assertIsNone(content)
self.assertIsNone(thumbnail) self.assertIsNone(thumbnail)
# now try to find it and the thumbnail in trashcan # now try to find it and the thumbnail in trashcan - should be in there
content = None content = trash_store.find(asset_location, throw_on_not_found=False)
thumbnail = None thumbnail = trash_store.find(thumbnail_location, throw_on_not_found=False)
try:
content = trash_store.find(asset_location)
thumbnail = trash_store.find(content.thumbnail_location)
except NotFoundError:
pass
# should be in trashcan
self.assertIsNotNone(content) self.assertIsNotNone(content)
self.assertIsNotNone(thumbnail) self.assertIsNotNone(thumbnail)
...@@ -480,13 +466,8 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -480,13 +466,8 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
restore_asset_from_trashcan('/c4x/edX/full/asset/circuits_duality.gif') restore_asset_from_trashcan('/c4x/edX/full/asset/circuits_duality.gif')
# now try to find it in courseware store, and they should be back after restore # now try to find it in courseware store, and they should be back after restore
content = None content = content_store.find(asset_location, throw_on_not_found=False)
thumbnail = None thumbnail = content_store.find(thumbnail_location, throw_on_not_found=False)
try:
content = content_store.find(asset_location)
thumbnail = trash_store.find(content.thumbnail_location)
except NotFoundError:
pass
self.assertIsNotNone(content) self.assertIsNotNone(content)
self.assertIsNotNone(thumbnail) self.assertIsNotNone(thumbnail)
...@@ -502,13 +483,8 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -502,13 +483,8 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
course_location = CourseDescriptor.id_to_location('edX/full/6.002_Spring_2012') course_location = CourseDescriptor.id_to_location('edX/full/6.002_Spring_2012')
content = None location = StaticContent.get_location_from_path('/c4x/edX/full/asset/circuits_duality.gif')
try: content = content_store.find(location, throw_on_not_found=False)
location = StaticContent.get_location_from_path('/c4x/edX/full/asset/circuits_duality.gif')
content = content_store.find(location)
except NotFoundError:
pass
self.assertIsNotNone(content) self.assertIsNotNone(content)
# go through the website to do the delete, since the soft-delete logic is in the view # go through the website to do the delete, since the soft-delete logic is in the view
......
...@@ -43,7 +43,7 @@ class MongoContentStore(ContentStore): ...@@ -43,7 +43,7 @@ class MongoContentStore(ContentStore):
if self.fs.exists({"_id": id}): if self.fs.exists({"_id": id}):
self.fs.delete(id) self.fs.delete(id)
def find(self, location): def find(self, location, throw_on_not_found=True):
id = StaticContent.get_id_from_location(location) id = StaticContent.get_id_from_location(location)
try: try:
with self.fs.get(id) as fp: with self.fs.get(id) as fp:
...@@ -52,7 +52,10 @@ class MongoContentStore(ContentStore): ...@@ -52,7 +52,10 @@ class MongoContentStore(ContentStore):
thumbnail_location=fp.thumbnail_location if hasattr(fp, 'thumbnail_location') else None, thumbnail_location=fp.thumbnail_location if hasattr(fp, 'thumbnail_location') else None,
import_path=fp.import_path if hasattr(fp, 'import_path') else None) import_path=fp.import_path if hasattr(fp, 'import_path') else None)
except NoFile: except NoFile:
raise NotFoundError() if throw_on_not_found:
raise NotFoundError()
else:
return None
def export(self, location, output_directory): def export(self, location, output_directory):
content = self.find(location) content = self.find(location)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment