Commit 944d2d61 by cahrens

Make sure to get the correct modulestore on delete (static tabs do not exist in draft modulestore).

#324
parent fca63f06
...@@ -74,7 +74,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -74,7 +74,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
self.client.login(username=uname, password=password) self.client.login(username=uname, password=password)
def check_edit_unit(self, test_course_name): def check_edit_unit(self, test_course_name):
import_from_xml(modulestore(), 'common/test/data/', [test_course_name]) import_from_xml(modulestore('direct'), 'common/test/data/', [test_course_name])
for descriptor in modulestore().get_items(Location(None, None, 'vertical', None, None)): for descriptor in modulestore().get_items(Location(None, None, 'vertical', None, None)):
print "Checking ", descriptor.location.url() print "Checking ", descriptor.location.url()
...@@ -101,7 +101,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -101,7 +101,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
Unfortunately, None = published for the revision field, so get_items() would return Unfortunately, None = published for the revision field, so get_items() would return
both draft and non-draft copies. both draft and non-draft copies.
''' '''
store = modulestore() store = modulestore('direct')
draft_store = modulestore('draft') draft_store = modulestore('draft')
import_from_xml(store, 'common/test/data/', ['simple']) import_from_xml(store, 'common/test/data/', ['simple'])
...@@ -128,7 +128,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -128,7 +128,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
module as 'own-metadata' when publishing. Also verifies the metadata inheritance is module as 'own-metadata' when publishing. Also verifies the metadata inheritance is
properly computed properly computed
''' '''
store = modulestore() store = modulestore('direct')
draft_store = modulestore('draft') draft_store = modulestore('draft')
import_from_xml(store, 'common/test/data/', ['simple']) import_from_xml(store, 'common/test/data/', ['simple'])
...@@ -186,7 +186,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -186,7 +186,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
self.assertEqual(html_module.lms.graceperiod, new_graceperiod) self.assertEqual(html_module.lms.graceperiod, new_graceperiod)
def test_get_depth_with_drafts(self): def test_get_depth_with_drafts(self):
import_from_xml(modulestore(), 'common/test/data/', ['simple']) import_from_xml(modulestore('direct'), 'common/test/data/', ['simple'])
course = modulestore('draft').get_item( course = modulestore('draft').get_item(
Location(['i4x', 'edX', 'simple', 'course', '2012_Fall', None]), Location(['i4x', 'edX', 'simple', 'course', '2012_Fall', None]),
...@@ -221,17 +221,17 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -221,17 +221,17 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
self.assertEqual(num_drafts, 1) self.assertEqual(num_drafts, 1)
def test_import_textbook_as_content_element(self): def test_import_textbook_as_content_element(self):
import_from_xml(modulestore(), 'common/test/data/', ['full'])
module_store = modulestore('direct') module_store = modulestore('direct')
import_from_xml(module_store, 'common/test/data/', ['full'])
course = module_store.get_item(Location(['i4x', 'edX', 'full', 'course', '6.002_Spring_2012', None])) course = module_store.get_item(Location(['i4x', 'edX', 'full', 'course', '6.002_Spring_2012', None]))
self.assertGreater(len(course.textbooks), 0) self.assertGreater(len(course.textbooks), 0)
def test_static_tab_reordering(self): def test_static_tab_reordering(self):
import_from_xml(modulestore(), 'common/test/data/', ['full'])
module_store = modulestore('direct') module_store = modulestore('direct')
import_from_xml(module_store, 'common/test/data/', ['full'])
course = module_store.get_item(Location(['i4x', 'edX', 'full', 'course', '6.002_Spring_2012', None])) course = module_store.get_item(Location(['i4x', 'edX', 'full', 'course', '6.002_Spring_2012', None]))
# reverse the ordering # reverse the ordering
...@@ -253,10 +253,8 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -253,10 +253,8 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
self.assertEqual(reverse_tabs, course_tabs) self.assertEqual(reverse_tabs, course_tabs)
def test_import_polls(self): def test_import_polls(self):
import_from_xml(modulestore(), 'common/test/data/', ['full'])
module_store = modulestore('direct') module_store = modulestore('direct')
found = False import_from_xml(module_store, 'common/test/data/', ['full'])
items = module_store.get_items(['i4x', 'edX', 'full', 'poll_question', None, None]) items = module_store.get_items(['i4x', 'edX', 'full', 'poll_question', None, None])
found = len(items) > 0 found = len(items) > 0
...@@ -270,9 +268,8 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -270,9 +268,8 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
self.assertGreater(err_cnt, 0) self.assertGreater(err_cnt, 0)
def test_delete(self): def test_delete(self):
import_from_xml(modulestore(), 'common/test/data/', ['full'])
direct_store = modulestore('direct') direct_store = modulestore('direct')
import_from_xml(direct_store, 'common/test/data/', ['full'])
sequential = direct_store.get_item(Location(['i4x', 'edX', 'full', 'sequential', 'Administrivia_and_Circuit_Elements', None])) sequential = direct_store.get_item(Location(['i4x', 'edX', 'full', 'sequential', 'Administrivia_and_Circuit_Elements', None]))
...@@ -306,8 +303,9 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -306,8 +303,9 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
This test case verifies that a course can use specialized override for about data, e.g. /about/Fall_2012/effort.html This test case verifies that a course can use specialized override for about data, e.g. /about/Fall_2012/effort.html
while there is a base definition in /about/effort.html while there is a base definition in /about/effort.html
''' '''
import_from_xml(modulestore(), 'common/test/data/', ['full'])
module_store = modulestore('direct') module_store = modulestore('direct')
import_from_xml(module_store, 'common/test/data/', ['full'])
effort = module_store.get_item(Location(['i4x', 'edX', 'full', 'about', 'effort', None])) effort = module_store.get_item(Location(['i4x', 'edX', 'full', 'about', 'effort', None]))
self.assertEqual(effort.data, '6 hours') self.assertEqual(effort.data, '6 hours')
...@@ -316,9 +314,8 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -316,9 +314,8 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
self.assertEqual(effort.data, 'TBD') self.assertEqual(effort.data, 'TBD')
def test_remove_hide_progress_tab(self): def test_remove_hide_progress_tab(self):
import_from_xml(modulestore(), 'common/test/data/', ['full'])
module_store = modulestore('direct') module_store = modulestore('direct')
import_from_xml(module_store, 'common/test/data/', ['full'])
source_location = CourseDescriptor.id_to_location('edX/full/6.002_Spring_2012') source_location = CourseDescriptor.id_to_location('edX/full/6.002_Spring_2012')
course = module_store.get_item(source_location) course = module_store.get_item(source_location)
...@@ -333,14 +330,14 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -333,14 +330,14 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
'display_name': 'Robot Super Course', 'display_name': 'Robot Super Course',
} }
import_from_xml(modulestore(), 'common/test/data/', ['full']) module_store = modulestore('direct')
import_from_xml(module_store, 'common/test/data/', ['full'])
resp = self.client.post(reverse('create_new_course'), course_data) resp = self.client.post(reverse('create_new_course'), course_data)
self.assertEqual(resp.status_code, 200) self.assertEqual(resp.status_code, 200)
data = parse_json(resp) data = parse_json(resp)
self.assertEqual(data['id'], 'i4x://MITx/999/course/Robot_Super_Course') self.assertEqual(data['id'], 'i4x://MITx/999/course/Robot_Super_Course')
module_store = modulestore('direct')
content_store = contentstore() content_store = contentstore()
source_location = CourseDescriptor.id_to_location('edX/full/6.002_Spring_2012') source_location = CourseDescriptor.id_to_location('edX/full/6.002_Spring_2012')
...@@ -365,9 +362,9 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -365,9 +362,9 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
self.assertEqual(resp.status_code, 400) self.assertEqual(resp.status_code, 400)
def test_delete_course(self): def test_delete_course(self):
import_from_xml(modulestore(), 'common/test/data/', ['full'])
module_store = modulestore('direct') module_store = modulestore('direct')
import_from_xml(module_store, 'common/test/data/', ['full'])
content_store = contentstore() content_store = contentstore()
location = CourseDescriptor.id_to_location('edX/full/6.002_Spring_2012') location = CourseDescriptor.id_to_location('edX/full/6.002_Spring_2012')
...@@ -523,8 +520,9 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -523,8 +520,9 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
self.assertContains(resp, '/c4x/edX/full/asset/handouts_schematic_tutorial.pdf') self.assertContains(resp, '/c4x/edX/full/asset/handouts_schematic_tutorial.pdf')
def test_prefetch_children(self): def test_prefetch_children(self):
import_from_xml(modulestore(), 'common/test/data/', ['full'])
module_store = modulestore('direct') module_store = modulestore('direct')
import_from_xml(module_store, 'common/test/data/', ['full'])
location = CourseDescriptor.id_to_location('edX/full/6.002_Spring_2012') location = CourseDescriptor.id_to_location('edX/full/6.002_Spring_2012')
wrapper = MongoCollectionFindWrapper(module_store.collection.find) wrapper = MongoCollectionFindWrapper(module_store.collection.find)
...@@ -736,7 +734,7 @@ class ContentStoreTest(ModuleStoreTestCase): ...@@ -736,7 +734,7 @@ class ContentStoreTest(ModuleStoreTestCase):
Import and walk through some common URL endpoints. This just verifies non-500 and no other Import and walk through some common URL endpoints. This just verifies non-500 and no other
correct behavior, so it is not a deep test correct behavior, so it is not a deep test
""" """
import_from_xml(modulestore(), 'common/test/data/', ['simple']) import_from_xml(modulestore('direct'), 'common/test/data/', ['simple'])
loc = Location(['i4x', 'edX', 'simple', 'course', '2012_Fall', None]) loc = Location(['i4x', 'edX', 'simple', 'course', '2012_Fall', None])
resp = self.client.get(reverse('course_index', resp = self.client.get(reverse('course_index',
kwargs={'org': loc.org, kwargs={'org': loc.org,
...@@ -838,9 +836,11 @@ class ContentStoreTest(ModuleStoreTestCase): ...@@ -838,9 +836,11 @@ class ContentStoreTest(ModuleStoreTestCase):
json.dumps({'id': del_loc.url()}), "application/json") json.dumps({'id': del_loc.url()}), "application/json")
self.assertEqual(200, resp.status_code) self.assertEqual(200, resp.status_code)
def test_import_metadata_with_attempts_empty_string(self): def test_import_metadata_with_attempts_empty_string(self):
import_from_xml(modulestore(), 'common/test/data/', ['simple'])
module_store = modulestore('direct') module_store = modulestore('direct')
import_from_xml(module_store, 'common/test/data/', ['simple'])
did_load_item = False did_load_item = False
try: try:
module_store.get_item(Location(['i4x', 'edX', 'simple', 'problem', 'ps01-simple', None])) module_store.get_item(Location(['i4x', 'edX', 'simple', 'problem', 'ps01-simple', None]))
...@@ -852,8 +852,9 @@ class ContentStoreTest(ModuleStoreTestCase): ...@@ -852,8 +852,9 @@ class ContentStoreTest(ModuleStoreTestCase):
self.assertTrue(did_load_item) self.assertTrue(did_load_item)
def test_forum_id_generation(self): def test_forum_id_generation(self):
import_from_xml(modulestore(), 'common/test/data/', ['full'])
module_store = modulestore('direct') module_store = modulestore('direct')
import_from_xml(module_store, 'common/test/data/', ['full'])
new_component_location = Location('i4x', 'edX', 'full', 'discussion', 'new_component') new_component_location = Location('i4x', 'edX', 'full', 'discussion', 'new_component')
source_template_location = Location('i4x', 'edx', 'templates', 'discussion', 'Discussion_Tag') source_template_location = Location('i4x', 'edx', 'templates', 'discussion', 'Discussion_Tag')
...@@ -865,9 +866,8 @@ class ContentStoreTest(ModuleStoreTestCase): ...@@ -865,9 +866,8 @@ class ContentStoreTest(ModuleStoreTestCase):
self.assertNotEquals(new_discussion_item.discussion_id, '$$GUID$$') self.assertNotEquals(new_discussion_item.discussion_id, '$$GUID$$')
def test_update_modulestore_signal_did_fire(self): def test_update_modulestore_signal_did_fire(self):
import_from_xml(modulestore(), 'common/test/data/', ['full'])
module_store = modulestore('direct') module_store = modulestore('direct')
import_from_xml(module_store, 'common/test/data/', ['full'])
try: try:
module_store.modulestore_update_signal = Signal(providing_args=['modulestore', 'course_id', 'location']) module_store.modulestore_update_signal = Signal(providing_args=['modulestore', 'course_id', 'location'])
...@@ -891,9 +891,9 @@ class ContentStoreTest(ModuleStoreTestCase): ...@@ -891,9 +891,9 @@ class ContentStoreTest(ModuleStoreTestCase):
self.assertTrue(self.got_signal) self.assertTrue(self.got_signal)
def test_metadata_inheritance(self): def test_metadata_inheritance(self):
import_from_xml(modulestore(), 'common/test/data/', ['full'])
module_store = modulestore('direct') module_store = modulestore('direct')
import_from_xml(module_store, 'common/test/data/', ['full'])
course = module_store.get_item(Location(['i4x', 'edX', 'full', 'course', '6.002_Spring_2012', None])) course = module_store.get_item(Location(['i4x', 'edX', 'full', 'course', '6.002_Spring_2012', None]))
verticals = module_store.get_items(['i4x', 'edX', 'full', 'vertical', None, None]) verticals = module_store.get_items(['i4x', 'edX', 'full', 'vertical', None, None])
......
...@@ -17,7 +17,6 @@ from xmodule.modulestore.tests.factories import CourseFactory ...@@ -17,7 +17,6 @@ from xmodule.modulestore.tests.factories import CourseFactory
from models.settings.course_metadata import CourseMetadata from models.settings.course_metadata import CourseMetadata
from xmodule.modulestore.xml_importer import import_from_xml from xmodule.modulestore.xml_importer import import_from_xml
from xmodule.modulestore.django import modulestore
from xmodule.fields import Date from xmodule.fields import Date
...@@ -256,7 +255,7 @@ class CourseMetadataEditingTest(CourseTestCase): ...@@ -256,7 +255,7 @@ class CourseMetadataEditingTest(CourseTestCase):
def setUp(self): def setUp(self):
CourseTestCase.setUp(self) CourseTestCase.setUp(self)
# add in the full class too # add in the full class too
import_from_xml(modulestore(), 'common/test/data/', ['full']) import_from_xml(get_modulestore(self.course_location), 'common/test/data/', ['full'])
self.fullcourse_location = Location(['i4x', 'edX', 'full', 'course', '6.002_Spring_2012', None]) self.fullcourse_location = Location(['i4x', 'edX', 'full', 'course', '6.002_Spring_2012', None])
def test_fetch_initial_fields(self): def test_fetch_initial_fields(self):
......
from contentstore.utils import get_modulestore, get_url_reverse
from contentstore.tests.test_course_settings import CourseTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from django.core.urlresolvers import reverse
class DeleteItem(CourseTestCase):
def setUp(self):
""" Creates the test course with a static page in it. """
super(DeleteItem, self).setUp()
self.course = CourseFactory.create(org='mitX', number='333', display_name='Dummy Course')
def testDeleteStaticPage(self):
# Add static tab
data = {
'parent_location': 'i4x://mitX/333/course/Dummy_Course',
'template': 'i4x://edx/templates/static_tab/Empty'
}
resp = self.client.post(reverse('clone_item'), data)
self.assertEqual(resp.status_code, 200)
# Now delete it. There was a bug that the delete was failing (static tabs do not exist in draft modulestore).
resp = self.client.post(reverse('delete_item'), resp.content, "application/json")
self.assertEqual(resp.status_code, 200)
...@@ -113,7 +113,7 @@ def delete_item(request): ...@@ -113,7 +113,7 @@ def delete_item(request):
delete_children = request.POST.get('delete_children', False) delete_children = request.POST.get('delete_children', False)
delete_all_versions = request.POST.get('delete_all_versions', False) delete_all_versions = request.POST.get('delete_all_versions', False)
store = modulestore() store = get_modulestore(item_location)
item = store.get_item(item_location) item = store.get_item(item_location)
......
...@@ -48,7 +48,7 @@ MODULESTORE_OPTIONS = { ...@@ -48,7 +48,7 @@ MODULESTORE_OPTIONS = {
MODULESTORE = { MODULESTORE = {
'default': { 'default': {
'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore', 'ENGINE': 'xmodule.modulestore.mongo.DraftMongoModuleStore',
'OPTIONS': MODULESTORE_OPTIONS 'OPTIONS': MODULESTORE_OPTIONS
}, },
'direct': { 'direct': {
......
...@@ -31,11 +31,11 @@ class ModuleStoreTestCase(TestCase): ...@@ -31,11 +31,11 @@ class ModuleStoreTestCase(TestCase):
@staticmethod @staticmethod
def load_templates_if_necessary(): def load_templates_if_necessary():
''' '''
Load templates into the modulestore only if they do not already exist. Load templates into the direct modulestore only if they do not already exist.
We need the templates, because they are copied to create We need the templates, because they are copied to create
XModules such as sections and problems XModules such as sections and problems
''' '''
modulestore = xmodule.modulestore.django.modulestore() modulestore = xmodule.modulestore.django.modulestore('direct')
# Count the number of templates # Count the number of templates
query = {"_id.course": "templates"} query = {"_id.course": "templates"}
......
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