Merge pull request #4896 from Kelketek/fix_path_to_location
path_to_location now returns 404 on orphaned items. Resolves LMS-9661.
This commit is contained in:
@@ -60,14 +60,14 @@ def path_to_location(modulestore, usage_key):
|
||||
# Found it!
|
||||
path = (next_usage, path)
|
||||
return flatten(path)
|
||||
elif parent is None:
|
||||
# Orphaned item.
|
||||
return None
|
||||
|
||||
# otherwise, add parent locations at the end
|
||||
newpath = (next_usage, path)
|
||||
queue.append((parent, newpath))
|
||||
|
||||
# If we're here, there is no path
|
||||
return None
|
||||
|
||||
if not modulestore.has_item(usage_key):
|
||||
raise ItemNotFoundError(usage_key)
|
||||
|
||||
|
||||
@@ -22,7 +22,8 @@ from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator
|
||||
from django.conf import settings
|
||||
from xmodule.modulestore.tests.factories import check_mongo_calls
|
||||
from xmodule.modulestore.search import path_to_location
|
||||
from xmodule.modulestore.exceptions import DuplicateCourseError
|
||||
from xmodule.modulestore.exceptions import DuplicateCourseError, NoPathToItem
|
||||
|
||||
if not settings.configured:
|
||||
settings.configure()
|
||||
from xmodule.modulestore.mixed import MixedModuleStore
|
||||
@@ -723,6 +724,18 @@ class TestMixedModuleStore(unittest.TestCase):
|
||||
with self.assertRaises(ItemNotFoundError):
|
||||
path_to_location(self.store, location)
|
||||
|
||||
# Orphaned items should not be found.
|
||||
orphan = course_key.make_usage_key('chapter', 'OrphanChapter')
|
||||
self.store.create_item(
|
||||
self.user_id,
|
||||
orphan.course_key,
|
||||
orphan.block_type,
|
||||
block_id=orphan.block_id
|
||||
)
|
||||
|
||||
with self.assertRaises(NoPathToItem):
|
||||
path_to_location(self.store, orphan)
|
||||
|
||||
def test_xml_path_to_location(self):
|
||||
"""
|
||||
Make sure that path_to_location works: should be passed a modulestore
|
||||
|
||||
Reference in New Issue
Block a user