Fix when checking in mongo store, has_course with a split course key returns False.

This commit is contained in:
Mushtaq Ali
2016-08-24 17:28:04 +05:00
parent 2dc4f5d6bf
commit ec13ba4340
3 changed files with 30 additions and 0 deletions

View File

@@ -1118,6 +1118,11 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
otherwise, do a case sensitive search
"""
assert isinstance(course_key, CourseKey)
if not course_key.deprecated: # split course_key
# The supplied CourseKey is of the wrong type, so it can't possibly be stored in this modulestore.
return False
if isinstance(course_key, LibraryLocator):
return None # Libraries require split mongo
course_key = self.fill_in_run(course_key)

View File

@@ -300,6 +300,14 @@ class TestMongoModuleStore(TestMongoModuleStoreBase):
with self.assertRaises(ItemNotFoundError):
self.draft_store.get_course(course_key)
def test_has_mongo_course_with_split_course_key(self):
"""
Test `has course` using split course key would return False.
"""
course_key = CourseKey.from_string('course-v1:edX+simple+2012_Fall')
self.assertFalse(self.draft_store.has_course(course_key))
def test_has_course_with_library(self):
"""
Test that has_course() returns False when called with a LibraryLocator.