Commit 79df5456 by Syed Hassan Raza

Mongo courses wrong course_key restriction

parent 18a2b535
...@@ -9,6 +9,7 @@ from xmodule.modulestore import ModuleStoreEnum ...@@ -9,6 +9,7 @@ from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from xmodule.modulestore.exceptions import ItemNotFoundError
class TestArgParsing(unittest.TestCase): class TestArgParsing(unittest.TestCase):
...@@ -107,6 +108,17 @@ class TestMigrateToSplit(ModuleStoreTestCase): ...@@ -107,6 +108,17 @@ class TestMigrateToSplit(ModuleStoreTestCase):
"org.dept", "name", "run", "org.dept", "name", "run",
) )
split_store = modulestore()._get_modulestore_by_type(ModuleStoreEnum.Type.split) split_store = modulestore()._get_modulestore_by_type(ModuleStoreEnum.Type.split)
locator = split_store.make_course_key(self.course.id.org, self.course.id.course, self.course.id.run) locator = split_store.make_course_key("org.dept", "name", "run")
course_from_split = modulestore().get_course(locator) course_from_split = split_store.get_course(locator)
self.assertIsNotNone(course_from_split) self.assertIsNotNone(course_from_split)
# Getting the original course with mongo course_id
mongo_store = modulestore()._get_modulestore_by_type(ModuleStoreEnum.Type.mongo)
mongo_locator = mongo_store.make_course_key(self.course.id.org, self.course.id.course, self.course.id.run)
course_from_mongo = mongo_store.get_course(mongo_locator)
self.assertIsNotNone(course_from_mongo)
# Throws ItemNotFoundError when try to access original course with split course_id
split_locator = split_store.make_course_key(self.course.id.org, self.course.id.course, self.course.id.run)
with self.assertRaises(ItemNotFoundError):
mongo_store.get_course(split_locator)
...@@ -1088,6 +1088,11 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo ...@@ -1088,6 +1088,11 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
Get the course with the given courseid (org/course/run) Get the course with the given courseid (org/course/run)
""" """
assert isinstance(course_key, CourseKey) 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.
raise ItemNotFoundError(course_key)
course_key = self.fill_in_run(course_key) course_key = self.fill_in_run(course_key)
location = course_key.make_usage_key('course', course_key.run) location = course_key.make_usage_key('course', course_key.run)
try: try:
......
...@@ -24,6 +24,7 @@ from xblock.runtime import KeyValueStore ...@@ -24,6 +24,7 @@ from xblock.runtime import KeyValueStore
from xblock.exceptions import InvalidScopeError from xblock.exceptions import InvalidScopeError
from xmodule.tests import DATA_DIR from xmodule.tests import DATA_DIR
from opaque_keys.edx.keys import CourseKey
from opaque_keys.edx.locations import Location from opaque_keys.edx.locations import Location
from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.mongo import MongoKeyValueStore from xmodule.modulestore.mongo import MongoKeyValueStore
...@@ -290,6 +291,15 @@ class TestMongoModuleStore(TestMongoModuleStoreBase): ...@@ -290,6 +291,15 @@ class TestMongoModuleStore(TestMongoModuleStoreBase):
assert_false(self.draft_store.has_course(mix_cased)) assert_false(self.draft_store.has_course(mix_cased))
assert_false(self.draft_store.has_course(mix_cased, ignore_case=True)) assert_false(self.draft_store.has_course(mix_cased, ignore_case=True))
def test_get_mongo_course_with_split_course_key(self):
"""
Test mongo course using split course_key will not able to access it.
"""
course_key = CourseKey.from_string('course-v1:edX+simple+2012_Fall')
with self.assertRaises(ItemNotFoundError):
self.draft_store.get_course(course_key)
def test_has_course_with_library(self): def test_has_course_with_library(self):
""" """
Test that has_course() returns False when called with a LibraryLocator. Test that has_course() returns False when called with a LibraryLocator.
......
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