Add roundtrip test for malformed module
* also fix error message in backcompat_module
This commit is contained in:
@@ -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 = '''<sequential display_name="oops"><video url="hi"></sequential>'''
|
||||
|
||||
@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 = '''<sequential display_name="oops"><video url="hi"></sequential>'''
|
||||
|
||||
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 = '''<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):
|
||||
# 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))
|
||||
|
||||
Reference in New Issue
Block a user