Commit 1a1635d4 by Chris Dodge

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

parent b61d7b2c
......@@ -11,6 +11,7 @@ import json
from fs.osfs import OSFS
import copy
from json import loads
import traceback
from django.contrib.auth.models import User
from contentstore.utils import get_modulestore
......@@ -284,17 +285,27 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
def test_export_course(self):
module_store = modulestore('direct')
draft_store = modulestore('draft')
content_store = contentstore()
import_from_xml(module_store, 'common/test/data/', ['full'])
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())
print 'Exporting to tempdir = {0}'.format(root_dir)
# 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
self.verify_content_existence(module_store, root_dir, location, 'tabs', 'static_tab', '.html')
......@@ -328,15 +339,24 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
delete_course(module_store, content_store, location)
# 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]))
self.assertGreater(len(items), 0)
for descriptor in items:
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)
# 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)
def test_course_handouts_rewrites(self):
......@@ -404,7 +424,8 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
try:
export_to_xml(module_store, content_store, location, root_dir, 'test_export')
exported = True
except Exception:
except Exception,e:
print 'Exception thrown: {0}'.format(traceback.format_exc())
pass
self.assertTrue(exported)
......
......@@ -54,6 +54,7 @@ def export_to_xml(modulestore, contentstore, course_location, root_dir, course_d
# NOTE: this code assumes that verticals are the top most draftable container
# should we change the application, then this assumption will no longer
# be valid
if draft_modulestore is not None:
draft_items = draft_modulestore.get_items([None, course_location.org, course_location.course,
'vertical', None, 'draft'])
......
......@@ -276,6 +276,12 @@ def import_from_xml(store, data_dir, course_dirs=None,
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:
# turn back on all write signalling
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,
store.refresh_cached_metadata_inheritance_tree(target_location_namespace if
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
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