Commit 0d83d2e6 by Victor Shnayder

Add roundtrip test for malformed module

* also fix error message in backcompat_module
parent 53608922
...@@ -9,11 +9,9 @@ from xmodule.modulestore import Location ...@@ -9,11 +9,9 @@ from xmodule.modulestore import Location
class ImportTestCase(unittest.TestCase): class ImportTestCase(unittest.TestCase):
'''Make sure module imports work properly, including for malformed inputs''' '''Make sure module imports work properly, including for malformed inputs'''
def test_fallback(self): @staticmethod
'''Make sure that malformed xml loads as a MalformedDescriptorb.''' def get_system():
'''Get a dummy system'''
bad_xml = '''<sequential display_name="oops"><video url="hi"></sequential>'''
# Shouldn't need any system params, because the initial parse should fail # Shouldn't need any system params, because the initial parse should fail
def load_item(loc): def load_item(loc):
raise Exception("Shouldn't be called") raise Exception("Shouldn't be called")
...@@ -31,8 +29,35 @@ class ImportTestCase(unittest.TestCase): ...@@ -31,8 +29,35 @@ class ImportTestCase(unittest.TestCase):
ignore_errors_handler, process_xml) ignore_errors_handler, process_xml)
system.render_template = render_template system.render_template = render_template
return system
def test_fallback(self):
'''Make sure that malformed xml loads as a MalformedDescriptorb.'''
bad_xml = '''<sequential display_name="oops"><video url="hi"></sequential>'''
system = self.get_system()
descriptor = XModuleDescriptor.load_from_xml(bad_xml, system, 'org', 'course', descriptor = XModuleDescriptor.load_from_xml(bad_xml, system, 'org', 'course',
None) None)
self.assertEqual(descriptor.__class__.__name__, self.assertEqual(descriptor.__class__.__name__,
'MalformedDescriptor') 'MalformedDescriptor')
def test_reimport(self):
'''Make sure an already-exported malformed xml tag loads properly'''
bad_xml = '''<sequential display_name="oops"><video url="hi"></sequential>'''
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'])
...@@ -32,7 +32,7 @@ def process_includes(fn): ...@@ -32,7 +32,7 @@ def process_includes(fn):
# read in and convert to XML # read in and convert to XML
incxml = etree.XML(ifp.read()) 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) parent.insert(parent.index(next_include), incxml)
except Exception: except Exception:
msg = "Error in problem xml include: %s" % (etree.tostring(next_include, pretty_print=True)) msg = "Error in problem xml include: %s" % (etree.tostring(next_include, pretty_print=True))
......
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