diff --git a/common/lib/xmodule/xmodule/html_module.py b/common/lib/xmodule/xmodule/html_module.py index de45af081a..89dbfb5fc0 100644 --- a/common/lib/xmodule/xmodule/html_module.py +++ b/common/lib/xmodule/xmodule/html_module.py @@ -36,7 +36,6 @@ class HtmlDescriptor(XmlDescriptor, EditingDescriptor): # are being edited in the cms @classmethod def backcompat_paths(cls, path): - origpath = path if path.endswith('.html.xml'): path = path[:-9] + '.html' #backcompat--look for html instead of xml candidates = [] @@ -45,9 +44,11 @@ class HtmlDescriptor(XmlDescriptor, EditingDescriptor): _, _, path = path.partition(os.sep) # also look for .html versions instead of .xml - if origpath.endswith('.xml'): - candidates.append(origpath[:-4] + '.html') - return candidates + nc = [] + for candidate in candidates: + if candidate.endswith('.xml'): + nc.append(candidate[:-4] + '.html') + return candidates + nc # NOTE: html descriptors are special. We do not want to parse and # export them ourselves, because that can break things (e.g. lxml @@ -80,7 +81,7 @@ class HtmlDescriptor(XmlDescriptor, EditingDescriptor): # online and has imported all current (fall 2012) courses from xml if not system.resources_fs.exists(filepath): candidates = cls.backcompat_paths(filepath) - #log.debug("candidates = {0}".format(candidates)) + log.debug("candidates = {0}".format(candidates)) for candidate in candidates: if system.resources_fs.exists(candidate): filepath = candidate diff --git a/common/lib/xmodule/xmodule/tests/test_export.py b/common/lib/xmodule/xmodule/tests/test_export.py index e1e48cc796..7358d89dde 100644 --- a/common/lib/xmodule/xmodule/tests/test_export.py +++ b/common/lib/xmodule/xmodule/tests/test_export.py @@ -1,6 +1,7 @@ +import unittest + from fs.osfs import OSFS from nose.tools import assert_equals, assert_true -from nose import SkipTest from path import path from tempfile import mkdtemp @@ -18,10 +19,7 @@ DATA_DIR = TEST_DIR / 'data' def strip_metadata(descriptor, key): """ - HACK: data_dir metadata tags break equality because they aren't real metadata - remove them. - - Recursively strips same tag from all children. + Recursively strips tag from all children. """ print "strip {key} from {desc}".format(key=key, desc=descriptor.location.url()) descriptor.metadata.pop(key, None) @@ -35,50 +33,66 @@ def check_gone(descriptor, key): for d in descriptor.get_children(): check_gone(d, key) -def check_export_roundtrip(data_dir, course_dir): - print "Starting import" - initial_import = XMLModuleStore(data_dir, eager=True, course_dirs=[course_dir]) - - courses = initial_import.get_courses() - assert_equals(len(courses), 1) - initial_course = courses[0] - - print "Starting export" - export_dir = mkdtemp() - print "export_dir: {0}".format(export_dir) - fs = OSFS(export_dir) - export_course_dir = 'export' - export_fs = fs.makeopendir(export_course_dir) - - xml = initial_course.export_to_xml(export_fs) - with export_fs.open('course.xml', 'w') as course_xml: - course_xml.write(xml) - - print "Starting second import" - second_import = XMLModuleStore(export_dir, eager=True, - course_dirs=[export_course_dir]) - - courses2 = second_import.get_courses() - assert_equals(len(courses2), 1) - exported_course = courses2[0] - - print "Checking course equality" - strip_metadata(initial_course, 'data_dir') - strip_metadata(exported_course, 'data_dir') - - assert_equals(initial_course, exported_course) - - print "Checking key equality" - assert_equals(initial_import.modules.keys(), second_import.modules.keys()) - - print "Checking module equality" - for location in initial_import.modules.keys(): - print "Checking", location - assert_equals(initial_import.modules[location], second_import.modules[location]) -def test_toy_roundtrip(): - dir = "" - # TODO: add paths and make this run. - raise SkipTest() - check_export_roundtrip(dir) +class RoundTripTestCase(unittest.TestCase): + '''Check that our test courses roundtrip properly''' + def check_export_roundtrip(self, data_dir, course_dir): + print "Starting import" + initial_import = XMLModuleStore(data_dir, eager=True, course_dirs=[course_dir]) + + courses = initial_import.get_courses() + self.assertEquals(len(courses), 1) + initial_course = courses[0] + + print "Starting export" + export_dir = mkdtemp() + print "export_dir: {0}".format(export_dir) + fs = OSFS(export_dir) + export_course_dir = 'export' + export_fs = fs.makeopendir(export_course_dir) + + xml = initial_course.export_to_xml(export_fs) + with export_fs.open('course.xml', 'w') as course_xml: + course_xml.write(xml) + + print "Starting second import" + second_import = XMLModuleStore(export_dir, eager=True, + course_dirs=[export_course_dir]) + + courses2 = second_import.get_courses() + self.assertEquals(len(courses2), 1) + exported_course = courses2[0] + + print "Checking course equality" + # HACK: data_dir metadata tags break equality because they + # aren't real metadata, and depend on paths. Remove them. + strip_metadata(initial_course, 'data_dir') + strip_metadata(exported_course, 'data_dir') + + self.assertEquals(initial_course, exported_course) + + print "Checking key equality" + self.assertEquals(sorted(initial_import.modules.keys()), + sorted(second_import.modules.keys())) + + print "Checking module equality" + for location in initial_import.modules.keys(): + print "Checking", location + if location.category == 'html': + print ("Skipping html modules--they can't import in" + " final form without writing files...") + continue + self.assertEquals(initial_import.modules[location], + second_import.modules[location]) + + + def setUp(self): + self.maxDiff = None + + def test_toy_roundtrip(self): + self.check_export_roundtrip(DATA_DIR, "toy") + + + def test_full_roundtrip(self): + self.check_export_roundtrip(DATA_DIR, "full") diff --git a/common/lib/xmodule/xmodule/tests/test_import.py b/common/lib/xmodule/xmodule/tests/test_import.py index d2080e1bf7..af7464cfdc 100644 --- a/common/lib/xmodule/xmodule/tests/test_import.py +++ b/common/lib/xmodule/xmodule/tests/test_import.py @@ -51,8 +51,6 @@ class DummySystem(XMLParsingSystem): class ImportTestCase(unittest.TestCase): '''Make sure module imports work properly, including for malformed inputs''' - - @staticmethod def get_system(): '''Get a dummy system''' diff --git a/common/lib/xmodule/xmodule/xml_module.py b/common/lib/xmodule/xmodule/xml_module.py index cb0d05a83e..1318270def 100644 --- a/common/lib/xmodule/xmodule/xml_module.py +++ b/common/lib/xmodule/xmodule/xml_module.py @@ -76,7 +76,7 @@ class XmlDescriptor(XModuleDescriptor): metadata_to_strip = ('data_dir', # VS[compat] -- remove the below attrs once everything is in the CMS - 'course', 'org', 'url_name') + 'course', 'org', 'url_name', 'filename') # A dictionary mapping xml attribute names AttrMaps that describe how # to import and export them diff --git a/common/test/data/simple/course.xml b/common/test/data/simple/course.xml index b92158cdb7..0ecc153724 100644 --- a/common/test/data/simple/course.xml +++ b/common/test/data/simple/course.xml @@ -2,7 +2,7 @@