Commit 1a1635d4 by Chris Dodge

Fix tests and extend export/import unit test with draft testing.

parent b61d7b2c
...@@ -11,6 +11,7 @@ import json ...@@ -11,6 +11,7 @@ import json
from fs.osfs import OSFS from fs.osfs import OSFS
import copy import copy
from json import loads from json import loads
import traceback
from django.contrib.auth.models import User from django.contrib.auth.models import User
from contentstore.utils import get_modulestore from contentstore.utils import get_modulestore
...@@ -284,17 +285,27 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -284,17 +285,27 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
def test_export_course(self): def test_export_course(self):
module_store = modulestore('direct') module_store = modulestore('direct')
draft_store = modulestore('draft')
content_store = contentstore() content_store = contentstore()
import_from_xml(module_store, 'common/test/data/', ['full']) 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')
# get a vertical (and components in it) to put into 'draft'
vertical = module_store.get_item(Location(['i4x', 'edX', 'full',
'vertical', 'vertical_66', None]), depth=1)
draft_store.clone_item(vertical.location, vertical.location)
for child in vertical.get_children():
draft_store.clone_item(child.location, child.location)
root_dir = path(mkdtemp_clean()) root_dir = path(mkdtemp_clean())
print 'Exporting to tempdir = {0}'.format(root_dir) print 'Exporting to tempdir = {0}'.format(root_dir)
# export out to a tempdir # export out to a tempdir
export_to_xml(module_store, content_store, location, root_dir, 'test_export') export_to_xml(module_store, content_store, location, root_dir, 'test_export', draft_modulestore=draft_store)
# check for static tabs # check for static tabs
self.verify_content_existence(module_store, root_dir, location, 'tabs', 'static_tab', '.html') self.verify_content_existence(module_store, root_dir, location, 'tabs', 'static_tab', '.html')
...@@ -328,15 +339,24 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -328,15 +339,24 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
delete_course(module_store, content_store, location) delete_course(module_store, content_store, location)
# reimport # reimport
import_from_xml(module_store, root_dir, ['test_export']) import_from_xml(module_store, root_dir, ['test_export'], draft_store=draft_store)
items = module_store.get_items(Location(['i4x', 'edX', 'full', 'vertical', None])) items = module_store.get_items(Location(['i4x', 'edX', 'full', 'vertical', None]))
self.assertGreater(len(items), 0) self.assertGreater(len(items), 0)
for descriptor in items: for descriptor in items:
print "Checking {0}....".format(descriptor.location.url()) print "Checking {0}....".format(descriptor.location.url())
resp = self.client.get(reverse('edit_unit', kwargs={'location': descriptor.location.url()})) non_draft_loc = descriptor.location._replace(revision=None)
resp = self.client.get(reverse('edit_unit', kwargs={'location': non_draft_loc.url()}))
self.assertEqual(resp.status_code, 200) self.assertEqual(resp.status_code, 200)
# verify that we have the content in the draft store as well
vertical = draft_store.get_item(Location(['i4x', 'edX', 'full',
'vertical', 'vertical_66', None]), depth=1)
self.assertTrue(hasattr(vertical, 'is_draft'))
for child in vertical.get_children():
self.assertTrue(hasattr(child, 'is_draft'))
shutil.rmtree(root_dir) shutil.rmtree(root_dir)
def test_course_handouts_rewrites(self): def test_course_handouts_rewrites(self):
...@@ -404,7 +424,8 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -404,7 +424,8 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
try: try:
export_to_xml(module_store, content_store, location, root_dir, 'test_export') export_to_xml(module_store, content_store, location, root_dir, 'test_export')
exported = True exported = True
except Exception: except Exception,e:
print 'Exception thrown: {0}'.format(traceback.format_exc())
pass pass
self.assertTrue(exported) self.assertTrue(exported)
......
...@@ -54,13 +54,14 @@ def export_to_xml(modulestore, contentstore, course_location, root_dir, course_d ...@@ -54,13 +54,14 @@ def export_to_xml(modulestore, contentstore, course_location, root_dir, course_d
# NOTE: this code assumes that verticals are the top most draftable container # NOTE: this code assumes that verticals are the top most draftable container
# should we change the application, then this assumption will no longer # should we change the application, then this assumption will no longer
# be valid # be valid
draft_items = draft_modulestore.get_items([None, course_location.org, course_location.course, if draft_modulestore is not None:
'vertical', None, 'draft']) draft_items = draft_modulestore.get_items([None, course_location.org, course_location.course,
'vertical', None, 'draft'])
if len(draft_items)>0: if len(draft_items)>0:
draft_course_dir = export_fs.makeopendir('drafts') draft_course_dir = export_fs.makeopendir('drafts')
for draft_item in draft_items: for draft_item in draft_items:
draft_item.export_to_xml(draft_course_dir) draft_item.export_to_xml(draft_course_dir)
def export_extra_content(export_fs, modulestore, course_location, category_type, dirname, file_suffix=''): def export_extra_content(export_fs, modulestore, course_location, category_type, dirname, file_suffix=''):
......
...@@ -276,6 +276,12 @@ def import_from_xml(store, data_dir, course_dirs=None, ...@@ -276,6 +276,12 @@ def import_from_xml(store, data_dir, course_dirs=None,
import_module(module, store, course_data_path, static_content_store) import_module(module, store, course_data_path, static_content_store)
# now import any 'draft' items
if draft_store is not None:
import_course_draft(xml_module_store, draft_store, course_data_path,
static_content_store, target_location_namespace if target_location_namespace is not None
else course_location)
finally: finally:
# turn back on all write signalling # turn back on all write signalling
if pseudo_course_id in store.ignore_write_events_on_courses: if pseudo_course_id in store.ignore_write_events_on_courses:
...@@ -283,10 +289,6 @@ def import_from_xml(store, data_dir, course_dirs=None, ...@@ -283,10 +289,6 @@ def import_from_xml(store, data_dir, course_dirs=None,
store.refresh_cached_metadata_inheritance_tree(target_location_namespace if store.refresh_cached_metadata_inheritance_tree(target_location_namespace if
target_location_namespace is not None else course_location) target_location_namespace is not None else course_location)
# now import any 'draft' items
if draft_store is not None:
import_course_draft(xml_module_store, draft_store, course_data_path, static_content_store, target_location_namespace)
return xml_module_store, course_items return xml_module_store, course_items
def import_module(module, store, course_data_path, static_content_store, allow_not_found=False): def import_module(module, store, course_data_path, static_content_store, allow_not_found=False):
......
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