add a filter to get_courses to not surface any courses that haven't been mapped, unless the store provider has been labeled as 'default'

This commit is contained in:
Chris Dodge
2013-08-16 10:30:47 -04:00
parent ae6f97a368
commit 13ff461461
2 changed files with 15 additions and 1 deletions

View File

@@ -103,7 +103,20 @@ class MixedModuleStore(ModuleStoreBase):
'''
courses = []
for key in self.modulestores:
courses = courses + (self.modulestores[key].get_courses())
store_courses = self.modulestores[key].get_courses()
# If the store has not been labeled as 'default' then we should
# only surface courses that have a mapping entry, for example the XMLModuleStore will
# slurp up anything that is on disk, however, we don't want to surface those to
# consumers *unless* there is an explicit mapping in the configuration
if key != 'default':
for course in store_courses:
# make sure that the courseId is mapped to the store in question
if key == self.mappings.get(course.location.course_id, 'default'):
courses = courses + ([course])
else:
# if we're the 'default' store provider, then we surface all courses hosted in
# that store provider
courses = courses + (store_courses)
return courses

View File

@@ -187,6 +187,7 @@ class TestMixedModuleStore(object):
def test_get_courses(self):
# we should have 3 total courses aggregated
courses = self.store.get_courses()
assert_equals(len(courses), 3)
course_ids = []
for course in courses:
course_ids.append(course.location.course_id)