Merge pull request #4232 from edx/nimisha/modulestore-enum-constants
ModulestoreEnum class.
This commit is contained in:
@@ -3,7 +3,7 @@ Script for finding all courses whose org/name pairs == other courses when ignori
|
||||
"""
|
||||
from django.core.management.base import BaseCommand
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from xmodule.modulestore import MONGO_MODULESTORE_TYPE
|
||||
from xmodule.modulestore import ModuleStoreEnum
|
||||
|
||||
|
||||
#
|
||||
@@ -16,7 +16,7 @@ class Command(BaseCommand):
|
||||
help = 'List all courses ids in the Mongo Modulestore which may collide when ignoring case'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
mstore = modulestore()._get_modulestore_by_type(MONGO_MODULESTORE_TYPE) # pylint: disable=protected-access
|
||||
mstore = modulestore()._get_modulestore_by_type(ModuleStoreEnum.Type.mongo) # pylint: disable=protected-access
|
||||
if hasattr(mstore, 'collection'):
|
||||
map_fn = '''
|
||||
function () {
|
||||
|
||||
@@ -6,7 +6,7 @@ import unittest
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.management import CommandError, call_command
|
||||
from contentstore.management.commands.migrate_to_split import Command
|
||||
from xmodule.modulestore import SPLIT_MONGO_MODULESTORE_TYPE, REVISION_OPTION_PUBLISHED_ONLY
|
||||
from xmodule.modulestore import ModuleStoreEnum
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
from xmodule.modulestore.django import modulestore, clear_existing_modulestores
|
||||
@@ -56,7 +56,7 @@ class TestMigrateToSplit(ModuleStoreTestCase):
|
||||
password = 'foo'
|
||||
self.user = User.objects.create_user(uname, email, password)
|
||||
self.course = CourseFactory()
|
||||
self.addCleanup(ModuleStoreTestCase.drop_mongo_collections, SPLIT_MONGO_MODULESTORE_TYPE)
|
||||
self.addCleanup(ModuleStoreTestCase.drop_mongo_collections, ModuleStoreEnum.Type.split)
|
||||
self.addCleanup(clear_existing_modulestores)
|
||||
|
||||
def test_user_email(self):
|
||||
@@ -84,6 +84,6 @@ class TestMigrateToSplit(ModuleStoreTestCase):
|
||||
str(self.user.id),
|
||||
"org.dept+name.run",
|
||||
)
|
||||
locator = CourseLocator(org="org.dept", offering="name.run", branch=REVISION_OPTION_PUBLISHED_ONLY)
|
||||
locator = CourseLocator(org="org.dept", offering="name.run", branch=ModuleStoreEnum.RevisionOption.published_only)
|
||||
course_from_split = modulestore('split').get_course(locator)
|
||||
self.assertIsNotNone(course_from_split)
|
||||
|
||||
@@ -27,10 +27,8 @@ from xmodule.contentstore.content import StaticContent
|
||||
from xmodule.contentstore.django import contentstore, _CONTENTSTORE
|
||||
from xmodule.contentstore.utils import restore_asset_from_trashcan, empty_asset_trashcan
|
||||
from xmodule.exceptions import NotFoundError, InvalidVersionError
|
||||
from xmodule.modulestore import (
|
||||
mongo, MONGO_MODULESTORE_TYPE, PublishState,
|
||||
REVISION_OPTION_PUBLISHED_ONLY, REVISION_OPTION_DRAFT_ONLY, KEY_REVISION_PUBLISHED, BRANCH_PUBLISHED_ONLY
|
||||
)
|
||||
from xmodule.modulestore import mongo, PublishState, ModuleStoreEnum
|
||||
from xmodule.modulestore.mongo.base import MongoRevisionKey
|
||||
from xmodule.modulestore.mixed import store_branch_setting
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from xmodule.modulestore.exceptions import ItemNotFoundError
|
||||
@@ -204,13 +202,13 @@ class ContentStoreToyCourseTest(ContentStoreTestCase):
|
||||
store.convert_to_draft(html_module_from_draft_store.location, self.user.id)
|
||||
|
||||
# Query get_items() and find the html item. This should just return back a single item (not 2).
|
||||
direct_store_items = store.get_items(course_key, revision=REVISION_OPTION_PUBLISHED_ONLY)
|
||||
direct_store_items = store.get_items(course_key, revision=ModuleStoreEnum.RevisionOption.published_only)
|
||||
html_items_from_direct_store = [item for item in direct_store_items if (item.location == html_usage_key)]
|
||||
self.assertEqual(len(html_items_from_direct_store), 1)
|
||||
self.assertFalse(getattr(html_items_from_direct_store[0], 'is_draft', False))
|
||||
|
||||
# Fetch from the draft store.
|
||||
draft_store_items = store.get_items(course_key, revision=REVISION_OPTION_DRAFT_ONLY)
|
||||
draft_store_items = store.get_items(course_key, revision=ModuleStoreEnum.RevisionOption.draft_only)
|
||||
html_items_from_draft_store = [item for item in draft_store_items if (item.location == html_usage_key)]
|
||||
self.assertEqual(len(html_items_from_draft_store), 1)
|
||||
self.assertTrue(getattr(html_items_from_draft_store[0], 'is_draft', False))
|
||||
@@ -663,9 +661,9 @@ class ContentStoreToyCourseTest(ContentStoreTestCase):
|
||||
clone_course(module_store, content_store, source_course_id, dest_course_id, self.user.id)
|
||||
|
||||
# first assert that all draft content got cloned as well
|
||||
draft_items = module_store.get_items(source_course_id, revision=REVISION_OPTION_DRAFT_ONLY)
|
||||
draft_items = module_store.get_items(source_course_id, revision=ModuleStoreEnum.RevisionOption.draft_only)
|
||||
self.assertGreater(len(draft_items), 0)
|
||||
draft_clone_items = module_store.get_items(dest_course_id, revision=REVISION_OPTION_DRAFT_ONLY)
|
||||
draft_clone_items = module_store.get_items(dest_course_id, revision=ModuleStoreEnum.RevisionOption.draft_only)
|
||||
self.assertGreater(len(draft_clone_items), 0)
|
||||
self.assertEqual(len(draft_items), len(draft_clone_items))
|
||||
|
||||
@@ -868,7 +866,7 @@ class ContentStoreToyCourseTest(ContentStoreTestCase):
|
||||
|
||||
# add the new private and new public to list of children
|
||||
sequential = module_store.get_item(course_id.make_usage_key('sequential', 'vertical_sequential'))
|
||||
private_location_no_draft = private_vertical.location.replace(revision=KEY_REVISION_PUBLISHED)
|
||||
private_location_no_draft = private_vertical.location.replace(revision=MongoRevisionKey.published)
|
||||
sequential.children.append(private_location_no_draft)
|
||||
sequential.children.append(public_vertical_location)
|
||||
module_store.update_item(sequential, self.user.id)
|
||||
@@ -939,7 +937,11 @@ class ContentStoreToyCourseTest(ContentStoreTestCase):
|
||||
target_course_id=course_id,
|
||||
)
|
||||
|
||||
items = module_store.get_items(course_id, category='vertical', revision=REVISION_OPTION_PUBLISHED_ONLY)
|
||||
items = module_store.get_items(
|
||||
course_id,
|
||||
category='vertical',
|
||||
revision=ModuleStoreEnum.RevisionOption.published_only
|
||||
)
|
||||
self._check_verticals(items)
|
||||
|
||||
def verify_item_publish_state(item, publish_state):
|
||||
@@ -1124,7 +1126,7 @@ class ContentStoreToyCourseTest(ContentStoreTestCase):
|
||||
self.assertContains(resp, '/c4x/edX/toy/asset/handouts_sample_handout.txt')
|
||||
|
||||
def test_prefetch_children(self):
|
||||
mongo_store = modulestore()._get_modulestore_by_type(MONGO_MODULESTORE_TYPE)
|
||||
mongo_store = modulestore()._get_modulestore_by_type(ModuleStoreEnum.Type.mongo)
|
||||
import_from_xml(modulestore(), self.user.id, 'common/test/data/', ['toy'])
|
||||
course_id = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')
|
||||
|
||||
@@ -1132,7 +1134,7 @@ class ContentStoreToyCourseTest(ContentStoreTestCase):
|
||||
mongo_store.collection.find = wrapper.find
|
||||
|
||||
# set the branch to 'publish' in order to prevent extra lookups of draft versions
|
||||
with store_branch_setting(mongo_store, BRANCH_PUBLISHED_ONLY):
|
||||
with store_branch_setting(mongo_store, ModuleStoreEnum.Branch.published_only):
|
||||
course = mongo_store.get_course(course_id, depth=2)
|
||||
|
||||
# make sure we haven't done too many round trips to DB
|
||||
|
||||
@@ -17,7 +17,7 @@ from student.tests.factories import UserFactory
|
||||
from student.roles import CourseInstructorRole, CourseStaffRole, GlobalStaff, OrgStaffRole, OrgInstructorRole
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls
|
||||
from xmodule.modulestore import MONGO_MODULESTORE_TYPE
|
||||
from xmodule.modulestore import ModuleStoreEnum
|
||||
from opaque_keys.edx.locations import SlashSeparatedCourseKey
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from xmodule.error_module import ErrorDescriptor
|
||||
@@ -199,7 +199,7 @@ class TestCourseListing(ModuleStoreTestCase):
|
||||
self.assertGreaterEqual(iteration_over_courses_time_2.elapsed, iteration_over_groups_time_2.elapsed)
|
||||
|
||||
# Now count the db queries
|
||||
store = modulestore()._get_modulestore_by_type(MONGO_MODULESTORE_TYPE)
|
||||
store = modulestore()._get_modulestore_by_type(ModuleStoreEnum.Type.mongo)
|
||||
with check_mongo_calls(store.collection, USER_COURSES_COUNT):
|
||||
courses_list = _accessible_courses_list_from_groups(self.request)
|
||||
|
||||
@@ -262,7 +262,7 @@ class TestCourseListing(ModuleStoreTestCase):
|
||||
Create good courses, courses that won't load, and deleted courses which still have
|
||||
roles. Test course listing.
|
||||
"""
|
||||
store = modulestore()._get_modulestore_by_type(MONGO_MODULESTORE_TYPE)
|
||||
store = modulestore()._get_modulestore_by_type(ModuleStoreEnum.Type.mongo)
|
||||
|
||||
course_location = SlashSeparatedCourseKey('testOrg', 'testCourse', 'RunBabyRun')
|
||||
self._create_course_with_access_groups(course_location, self.user)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import unittest
|
||||
|
||||
from xmodule import templates
|
||||
from xmodule.modulestore import SPLIT_MONGO_MODULESTORE_TYPE, BRANCH_NAME_DRAFT
|
||||
from xmodule.modulestore import ModuleStoreEnum
|
||||
from xmodule.modulestore.tests import persistent_factories
|
||||
from xmodule.course_module import CourseDescriptor
|
||||
from xmodule.modulestore.django import modulestore, clear_existing_modulestores, _MIXED_MODULESTORE, \
|
||||
@@ -21,9 +21,9 @@ class TemplateTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
clear_existing_modulestores() # redundant w/ cleanup but someone was getting errors
|
||||
self.addCleanup(ModuleStoreTestCase.drop_mongo_collections, SPLIT_MONGO_MODULESTORE_TYPE)
|
||||
self.addCleanup(ModuleStoreTestCase.drop_mongo_collections, ModuleStoreEnum.Type.split)
|
||||
self.addCleanup(clear_existing_modulestores)
|
||||
self.split_store = modulestore()._get_modulestore_by_type(SPLIT_MONGO_MODULESTORE_TYPE)
|
||||
self.split_store = modulestore()._get_modulestore_by_type(ModuleStoreEnum.Type.split)
|
||||
|
||||
def test_get_templates(self):
|
||||
found = templates.all_templates()
|
||||
@@ -156,7 +156,7 @@ class TemplateTests(unittest.TestCase):
|
||||
persistent_factories.ItemFactory.create(display_name='chapter 1',
|
||||
parent_location=test_course.location)
|
||||
|
||||
id_locator = test_course.id.for_branch(BRANCH_NAME_DRAFT)
|
||||
id_locator = test_course.id.for_branch(ModuleStoreEnum.BranchName.draft)
|
||||
guid_locator = test_course.location.course_agnostic()
|
||||
# verify it can be retrieved by id
|
||||
self.assertIsInstance(self.split_store.get_course(id_locator), CourseDescriptor)
|
||||
@@ -241,7 +241,7 @@ class SplitAndLocMapperTests(unittest.TestCase):
|
||||
mapper = loc_mapper()
|
||||
|
||||
# instantiate mixed modulestore and thus split
|
||||
split_store = modulestore()._get_modulestore_by_type(SPLIT_MONGO_MODULESTORE_TYPE)
|
||||
split_store = modulestore()._get_modulestore_by_type(ModuleStoreEnum.Type.split)
|
||||
|
||||
# split must inject the same location mapper object since the mapper existed before it did
|
||||
self.assertEqual(split_store.loc_mapper, mapper)
|
||||
@@ -254,7 +254,7 @@ class SplitAndLocMapperTests(unittest.TestCase):
|
||||
self.assertIsNone(_loc_singleton)
|
||||
|
||||
# instantiate split before location mapper
|
||||
split_store = modulestore()._get_modulestore_by_type(SPLIT_MONGO_MODULESTORE_TYPE)
|
||||
split_store = modulestore()._get_modulestore_by_type(ModuleStoreEnum.Type.split)
|
||||
|
||||
# split must have instantiated loc_mapper
|
||||
mapper = loc_mapper()
|
||||
|
||||
@@ -21,7 +21,7 @@ from xblock.fragment import Fragment
|
||||
|
||||
import xmodule
|
||||
from xmodule.tabs import StaticTab, CourseTabList
|
||||
from xmodule.modulestore import PublishState, REVISION_OPTION_ALL
|
||||
from xmodule.modulestore import PublishState, ModuleStoreEnum
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from xmodule.modulestore.draft import DIRECT_ONLY_CATEGORIES
|
||||
from xmodule.modulestore.exceptions import ItemNotFoundError, InvalidLocationError, DuplicateItemError
|
||||
@@ -527,7 +527,7 @@ def orphan_handler(request, course_key_string):
|
||||
# get_orphans returns the deprecated string format w/o revision
|
||||
usage_key = course_usage_key.make_usage_key_from_deprecated_string(itemloc)
|
||||
# need to delete all versions
|
||||
store.delete_item(usage_key, request.user.id, revision=REVISION_OPTION_ALL)
|
||||
store.delete_item(usage_key, request.user.id, revision=ModuleStoreEnum.RevisionOption.all)
|
||||
return JsonResponse({'deleted': items})
|
||||
else:
|
||||
raise PermissionDenied()
|
||||
|
||||
@@ -247,7 +247,7 @@ XBLOCK_MIXINS = (LmsBlockMixin, InheritanceMixin, XModuleMixin)
|
||||
XBLOCK_SELECT_FUNCTION = prefer_xmodules
|
||||
|
||||
############################ Modulestore Configuration ################################
|
||||
MODULESTORE_BRANCH = 'draft'
|
||||
MODULESTORE_BRANCH = 'draft-preferred'
|
||||
|
||||
############################ DJANGO_BUILTINS ################################
|
||||
# Change DEBUG/TEMPLATE_DEBUG in your environment settings files, not here
|
||||
|
||||
Reference in New Issue
Block a user