From 0d83d2e645a4a701ebad7e5158493c198d552370 Mon Sep 17 00:00:00 2001 From: Victor Shnayder Date: Mon, 30 Jul 2012 11:51:14 -0400 Subject: [PATCH] Add roundtrip test for malformed module * also fix error message in backcompat_module --- common/lib/xmodule/tests/test_import.py | 35 ++++++++++++++++--- .../lib/xmodule/xmodule/backcompat_module.py | 2 +- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/common/lib/xmodule/tests/test_import.py b/common/lib/xmodule/tests/test_import.py index c0bd9af3d0..6643b93a67 100644 --- a/common/lib/xmodule/tests/test_import.py +++ b/common/lib/xmodule/tests/test_import.py @@ -9,11 +9,9 @@ from xmodule.modulestore import Location class ImportTestCase(unittest.TestCase): '''Make sure module imports work properly, including for malformed inputs''' - def test_fallback(self): - '''Make sure that malformed xml loads as a MalformedDescriptorb.''' - - bad_xml = '''''' - + @staticmethod + def get_system(): + '''Get a dummy system''' # Shouldn't need any system params, because the initial parse should fail def load_item(loc): raise Exception("Shouldn't be called") @@ -31,8 +29,35 @@ class ImportTestCase(unittest.TestCase): ignore_errors_handler, process_xml) system.render_template = render_template + return system + + def test_fallback(self): + '''Make sure that malformed xml loads as a MalformedDescriptorb.''' + + bad_xml = '''''' + + system = self.get_system() + descriptor = XModuleDescriptor.load_from_xml(bad_xml, system, 'org', 'course', None) self.assertEqual(descriptor.__class__.__name__, 'MalformedDescriptor') + + def test_reimport(self): + '''Make sure an already-exported malformed xml tag loads properly''' + + bad_xml = '''''' + system = self.get_system() + descriptor = XModuleDescriptor.load_from_xml(bad_xml, system, 'org', 'course', + None) + resource_fs = None + tag_xml = descriptor.export_to_xml(resource_fs) + re_import_descriptor = XModuleDescriptor.load_from_xml(tag_xml, system, + 'org', 'course', + None) + self.assertEqual(re_import_descriptor.__class__.__name__, + 'MalformedDescriptor') + + self.assertEqual(descriptor.definition['data'], + re_import_descriptor.definition['data']) diff --git a/common/lib/xmodule/xmodule/backcompat_module.py b/common/lib/xmodule/xmodule/backcompat_module.py index 997ad476c4..da0d6788e4 100644 --- a/common/lib/xmodule/xmodule/backcompat_module.py +++ b/common/lib/xmodule/xmodule/backcompat_module.py @@ -32,7 +32,7 @@ def process_includes(fn): # read in and convert to XML incxml = etree.XML(ifp.read()) - # insert new XML into tree in place of inlcude + # insert new XML into tree in place of include parent.insert(parent.index(next_include), incxml) except Exception: msg = "Error in problem xml include: %s" % (etree.tostring(next_include, pretty_print=True))