From 09d90b16af472f702a13fdcb828b8e238b9a92b3 Mon Sep 17 00:00:00 2001 From: cahrens Date: Tue, 11 Feb 2014 13:37:18 -0500 Subject: [PATCH] Clean up of modulestore references (primarly LMS). STUD-1151 --- .../contentstore/tests/test_orphan.py | 10 +++-- common/djangoapps/student/views.py | 4 +- .../xmodule/modulestore/tests/django_utils.py | 2 +- lms/djangoapps/bulk_email/forms.py | 4 +- lms/djangoapps/bulk_email/tests/test_forms.py | 4 +- .../tests/test_submitting_problems.py | 2 +- lms/djangoapps/dashboard/sysadmin.py | 8 ++-- .../instructor/views/instructor_dashboard.py | 4 +- lms/djangoapps/instructor/views/legacy.py | 4 +- lms/envs/cms/dev.py | 27 ++++++++---- lms/envs/cms/mixed_dev.py | 43 ------------------- lms/envs/cms/preview_dev.py | 17 -------- lms/envs/dev_mongo.py | 27 ------------ 13 files changed, 40 insertions(+), 116 deletions(-) delete mode 100644 lms/envs/cms/mixed_dev.py delete mode 100644 lms/envs/cms/preview_dev.py delete mode 100644 lms/envs/dev_mongo.py diff --git a/cms/djangoapps/contentstore/tests/test_orphan.py b/cms/djangoapps/contentstore/tests/test_orphan.py index 0bdcb69bbc..2bda394f73 100644 --- a/cms/djangoapps/contentstore/tests/test_orphan.py +++ b/cms/djangoapps/contentstore/tests/test_orphan.py @@ -3,8 +3,9 @@ Test finding orphans via the view and django config """ import json from contentstore.tests.utils import CourseTestCase -from xmodule.modulestore.django import editable_modulestore, loc_mapper +from xmodule.modulestore.django import loc_mapper from student.models import CourseEnrollment +from xmodule.modulestore.django import modulestore class TestOrphan(CourseTestCase): """ @@ -28,13 +29,14 @@ class TestOrphan(CourseTestCase): def _create_item(self, category, name, data, metadata, parent_category, parent_name, runtime): location = self.course.location.replace(category=category, name=name) - editable_modulestore('direct').create_and_save_xmodule(location, data, metadata, runtime) + store = modulestore('direct') + store.create_and_save_xmodule(location, data, metadata, runtime) if parent_name: # add child to parent in mongo parent_location = self.course.location.replace(category=parent_category, name=parent_name) - parent = editable_modulestore('direct').get_item(parent_location) + parent = store.get_item(parent_location) parent.children.append(location.url()) - editable_modulestore('direct').update_item(parent, self.user.id) + store.update_item(parent, self.user.id) def test_mongo_orphan(self): """ diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index ac047cd6da..bb00430da3 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -49,7 +49,7 @@ from certificates.models import CertificateStatuses, certificate_status_for_stud from xmodule.course_module import CourseDescriptor from xmodule.modulestore.exceptions import ItemNotFoundError from xmodule.modulestore.django import modulestore -from xmodule.modulestore import MONGO_MODULESTORE_TYPE +from xmodule.modulestore import XML_MODULESTORE_TYPE from collections import namedtuple @@ -441,7 +441,7 @@ def dashboard(request): show_email_settings_for = frozenset( course.id for course, _enrollment in course_enrollment_pairs if ( settings.FEATURES['ENABLE_INSTRUCTOR_EMAIL'] and - modulestore().get_modulestore_type(course.id) == MONGO_MODULESTORE_TYPE and + modulestore().get_modulestore_type(course.id) != XML_MODULESTORE_TYPE and CourseAuthorization.instructor_email_enabled(course.id) ) ) diff --git a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py index 2f1bdf6460..71887629c4 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py @@ -204,7 +204,7 @@ class ModuleStoreTestCase(TestCase): 'course' is an instance of CourseDescriptor for which we want to update metadata. """ - store = editable_modulestore('direct') + store = editable_modulestore() store.update_item(course, '**replace_user**') updated_course = store.get_instance(course.id, course.location) return updated_course diff --git a/lms/djangoapps/bulk_email/forms.py b/lms/djangoapps/bulk_email/forms.py index 2a7b686ed2..bc68cf5aa0 100644 --- a/lms/djangoapps/bulk_email/forms.py +++ b/lms/djangoapps/bulk_email/forms.py @@ -9,7 +9,7 @@ from django.core.exceptions import ValidationError from bulk_email.models import CourseEmailTemplate, COURSE_EMAIL_MESSAGE_BODY_TAG, CourseAuthorization from courseware.courses import get_course_by_id -from xmodule.modulestore import MONGO_MODULESTORE_TYPE +from xmodule.modulestore import XML_MODULESTORE_TYPE from xmodule.modulestore.django import modulestore log = logging.getLogger(__name__) @@ -69,7 +69,7 @@ class CourseAuthorizationAdminForm(forms.ModelForm): # pylint: disable=R0924 raise forms.ValidationError(msg) # Now, try and discern if it is a Studio course - HTML editor doesn't work with XML courses - is_studio_course = modulestore().get_modulestore_type(course_id) == MONGO_MODULESTORE_TYPE + is_studio_course = modulestore().get_modulestore_type(course_id) != XML_MODULESTORE_TYPE if not is_studio_course: msg = "Course Email feature is only available for courses authored in Studio. " msg += '"{0}" appears to be an XML backed course.'.format(course_id) diff --git a/lms/djangoapps/bulk_email/tests/test_forms.py b/lms/djangoapps/bulk_email/tests/test_forms.py index 01401ca20e..e463f9e7df 100644 --- a/lms/djangoapps/bulk_email/tests/test_forms.py +++ b/lms/djangoapps/bulk_email/tests/test_forms.py @@ -11,7 +11,7 @@ from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE from xmodule.modulestore.django import modulestore -from xmodule.modulestore import MONGO_MODULESTORE_TYPE +from xmodule.modulestore import XML_MODULESTORE_TYPE from mock import patch @@ -119,7 +119,7 @@ class CourseAuthorizationXMLFormTest(ModuleStoreTestCase): def test_xml_course_authorization(self): course_id = 'edX/toy/2012_Fall' # Assert this is an XML course - self.assertTrue(modulestore().get_modulestore_type(course_id) != MONGO_MODULESTORE_TYPE) + self.assertEqual(modulestore().get_modulestore_type(course_id), XML_MODULESTORE_TYPE) form_data = {'course_id': course_id, 'email_enabled': True} form = CourseAuthorizationAdminForm(data=form_data) diff --git a/lms/djangoapps/courseware/tests/test_submitting_problems.py b/lms/djangoapps/courseware/tests/test_submitting_problems.py index c1c69ea60a..45daed6d77 100644 --- a/lms/djangoapps/courseware/tests/test_submitting_problems.py +++ b/lms/djangoapps/courseware/tests/test_submitting_problems.py @@ -229,7 +229,7 @@ class TestCourseGrader(TestSubmittingProblems): """ self.course.grading_policy = grading_policy - store = editable_modulestore('direct') + store = editable_modulestore() store.update_item(self.course, '**replace_user**') self.refresh_course() diff --git a/lms/djangoapps/dashboard/sysadmin.py b/lms/djangoapps/dashboard/sysadmin.py index 9ee70973d6..81c0e2824e 100644 --- a/lms/djangoapps/dashboard/sysadmin.py +++ b/lms/djangoapps/dashboard/sysadmin.py @@ -38,7 +38,7 @@ from external_auth.views import generate_password from student.models import CourseEnrollment, UserProfile, Registration import track.views from xmodule.contentstore.django import contentstore -from xmodule.modulestore import MONGO_MODULESTORE_TYPE +from xmodule.modulestore import XML_MODULESTORE_TYPE from xmodule.modulestore.django import modulestore from xmodule.modulestore.store_utilities import delete_course from xmodule.modulestore.xml import XMLModuleStore @@ -530,8 +530,8 @@ class Courses(SysadminDashboardView): course_id, escape(str(err)) ) - is_mongo_course = (modulestore().get_modulestore_type(course_id) == MONGO_MODULESTORE_TYPE) - if course_found and not is_mongo_course: + is_xml_course = (modulestore().get_modulestore_type(course_id) == XML_MODULESTORE_TYPE) + if course_found and is_xml_course: cdir = course.data_dir self.def_ms.courses.pop(cdir) @@ -546,7 +546,7 @@ class Courses(SysadminDashboardView): u"{0} = {1} ({2})".format( cdir, course.id, course.display_name)) - elif course_found and is_mongo_course: + elif course_found and not is_xml_course: # delete course that is stored with mongodb backend loc = course.location content_store = contentstore() diff --git a/lms/djangoapps/instructor/views/instructor_dashboard.py b/lms/djangoapps/instructor/views/instructor_dashboard.py index 0f4bad1520..b368153bd6 100644 --- a/lms/djangoapps/instructor/views/instructor_dashboard.py +++ b/lms/djangoapps/instructor/views/instructor_dashboard.py @@ -13,7 +13,7 @@ from django.conf import settings from xmodule_modifiers import wrap_xblock from xmodule.html_module import HtmlDescriptor -from xmodule.modulestore import MONGO_MODULESTORE_TYPE +from xmodule.modulestore import XML_MODULESTORE_TYPE from xmodule.modulestore.django import modulestore from xblock.field_data import DictFieldData from xblock.fields import ScopeIds @@ -34,7 +34,7 @@ def instructor_dashboard_2(request, course_id): """Display the instructor dashboard for a course.""" course = get_course_by_id(course_id, depth=None) - is_studio_course = (modulestore().get_modulestore_type(course_id) == MONGO_MODULESTORE_TYPE) + is_studio_course = (modulestore().get_modulestore_type(course_id) != XML_MODULESTORE_TYPE) access = { 'admin': request.user.is_staff, diff --git a/lms/djangoapps/instructor/views/legacy.py b/lms/djangoapps/instructor/views/legacy.py index b62bad05e5..33c1851479 100644 --- a/lms/djangoapps/instructor/views/legacy.py +++ b/lms/djangoapps/instructor/views/legacy.py @@ -24,7 +24,7 @@ from django.utils import timezone from xmodule_modifiers import wrap_xblock import xmodule.graders as xmgraders -from xmodule.modulestore import MONGO_MODULESTORE_TYPE +from xmodule.modulestore import XML_MODULESTORE_TYPE from xmodule.modulestore.django import modulestore from xmodule.modulestore.exceptions import ItemNotFoundError from xmodule.html_module import HtmlDescriptor @@ -831,7 +831,7 @@ def instructor_dashboard(request, course_id): instructor_tasks = None # determine if this is a studio-backed course so we can provide a link to edit this course in studio - is_studio_course = modulestore().get_modulestore_type(course_id) == MONGO_MODULESTORE_TYPE + is_studio_course = modulestore().get_modulestore_type(course_id) != XML_MODULESTORE_TYPE studio_url = None if is_studio_course: diff --git a/lms/envs/cms/dev.py b/lms/envs/cms/dev.py index ef7ead27f2..57b362ce52 100644 --- a/lms/envs/cms/dev.py +++ b/lms/envs/cms/dev.py @@ -30,15 +30,24 @@ modulestore_options = { MODULESTORE = { 'default': { - 'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore', - 'DOC_STORE_CONFIG': DOC_STORE_CONFIG, - 'OPTIONS': modulestore_options, - }, - 'draft': { - 'ENGINE': 'xmodule.modulestore.mongo.DraftMongoModuleStore', - 'DOC_STORE_CONFIG': DOC_STORE_CONFIG, - 'OPTIONS': modulestore_options, - }, + 'ENGINE': 'xmodule.modulestore.mixed.MixedModuleStore', + 'OPTIONS': { + 'reference_type': 'Location', + 'mappings': {}, + 'stores': { + 'default': { + 'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore', + 'DOC_STORE_CONFIG': DOC_STORE_CONFIG, + 'OPTIONS': modulestore_options, + }, + 'draft': { + 'ENGINE': 'xmodule.modulestore.mongo.DraftMongoModuleStore', + 'DOC_STORE_CONFIG': DOC_STORE_CONFIG, + 'OPTIONS': modulestore_options, + }, + }, + } + } } CONTENTSTORE = { diff --git a/lms/envs/cms/mixed_dev.py b/lms/envs/cms/mixed_dev.py deleted file mode 100644 index 35c5e0b82c..0000000000 --- a/lms/envs/cms/mixed_dev.py +++ /dev/null @@ -1,43 +0,0 @@ -""" -This configuration is to run the MixedModuleStore on a localdev environment -""" - -# We intentionally define lots of variables that aren't used, and -# want to import all variables from base settings files -# pylint: disable=W0401, W0614 - -from .dev import * - -MODULESTORE = { - 'default': { - 'ENGINE': 'xmodule.modulestore.mixed.MixedModuleStore', - 'OPTIONS': { - 'reference_type': 'Location', - 'mappings': { - 'MITx/2.01x/2013_Spring': 'xml' - }, - 'stores': { - 'xml': { - 'ENGINE': 'xmodule.modulestore.xml.XMLModuleStore', - 'OPTIONS': { - 'data_dir': DATA_DIR, - 'default_class': 'xmodule.hidden_module.HiddenDescriptor', - } - }, - 'default': { - 'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore', - 'DOC_STORE_CONFIG': { - 'host': 'localhost', - 'db': 'xmodule', - 'collection': 'modulestore', - }, - 'OPTIONS': { - 'default_class': 'xmodule.hidden_module.HiddenDescriptor', - 'fs_root': DATA_DIR, - 'render_template': 'edxmako.shortcuts.render_to_string', - } - } - }, - } - } -} diff --git a/lms/envs/cms/preview_dev.py b/lms/envs/cms/preview_dev.py deleted file mode 100644 index 4a65b50e59..0000000000 --- a/lms/envs/cms/preview_dev.py +++ /dev/null @@ -1,17 +0,0 @@ -""" -Settings for the LMS that runs alongside the CMS on AWS -""" - -# We intentionally define lots of variables that aren't used, and -# want to import all variables from base settings files -# pylint: disable=W0401, W0614 - -from .dev import * - -MODULESTORE = { - 'default': { - 'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore', - 'DOC_STORE_CONFIG': DOC_STORE_CONFIG, - 'OPTIONS': modulestore_options - }, -} diff --git a/lms/envs/dev_mongo.py b/lms/envs/dev_mongo.py deleted file mode 100644 index 4d304028d7..0000000000 --- a/lms/envs/dev_mongo.py +++ /dev/null @@ -1,27 +0,0 @@ -""" -This config file runs the dev environment, but with mongo as the datastore -""" - -# We intentionally define lots of variables that aren't used, and -# want to import all variables from base settings files -# pylint: disable=W0401, W0614 - -from .dev import * - -GITHUB_REPO_ROOT = ENV_ROOT / "data" - -MODULESTORE = { - 'default': { - 'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore', - 'DOC_STORE_CONFIG': { - 'host': 'localhost', - 'db': 'xmodule', - 'collection': 'modulestore', - }, - 'OPTIONS': { - 'default_class': 'xmodule.hidden_module.HiddenDescriptor', - 'fs_root': GITHUB_REPO_ROOT, - 'render_template': 'edxmako.shortcuts.render_to_string', - } - } -}