Merge pull request #13303 from edx/efischer/tnl_5057
TNL 5057 Silence XML parse error in capa_module
This commit is contained in:
@@ -220,9 +220,13 @@ class CapaDescriptor(CapaFields, RawDescriptor):
|
||||
@property
|
||||
def problem_types(self):
|
||||
""" Low-level problem type introspection for content libraries filtering by problem type """
|
||||
tree = etree.XML(self.data)
|
||||
try:
|
||||
tree = etree.XML(self.data)
|
||||
except etree.XMLSyntaxError:
|
||||
log.error('Error parsing problem types from xml for capa module {}'.format(self.display_name))
|
||||
return None # short-term fix to prevent errors (TNL-5057). Will be more properly addressed in TNL-4525.
|
||||
registered_tags = responsetypes.registry.registered_tags()
|
||||
return set([node.tag for node in tree.iter() if node.tag in registered_tags])
|
||||
return {node.tag for node in tree.iter() if node.tag in registered_tags}
|
||||
|
||||
def index_dictionary(self):
|
||||
"""
|
||||
@@ -263,9 +267,10 @@ class CapaDescriptor(CapaFields, RawDescriptor):
|
||||
Returns whether the given view has support for the given functionality.
|
||||
"""
|
||||
if functionality == "multi_device":
|
||||
return all(
|
||||
types = self.problem_types # Avoid calculating this property twice
|
||||
return types is not None and all(
|
||||
responsetypes.registry.get_class_for_tag(tag).multi_device_support
|
||||
for tag in self.problem_types
|
||||
for tag in types
|
||||
)
|
||||
return False
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import textwrap
|
||||
import unittest
|
||||
import ddt
|
||||
|
||||
from lxml import etree
|
||||
from mock import Mock, patch, DEFAULT
|
||||
import webob
|
||||
from webob.multidict import MultiDict
|
||||
@@ -2517,6 +2518,21 @@ class CapaDescriptorTest(unittest.TestCase):
|
||||
}
|
||||
)
|
||||
|
||||
def test_invalid_xml_handling(self):
|
||||
"""
|
||||
Tests to confirm that invalid XML does not throw a wake-up-ops level error.
|
||||
See TNL-5057 for quick fix, TNL-5245 for full resolution.
|
||||
"""
|
||||
sample_invalid_xml = textwrap.dedent("""
|
||||
<problem>
|
||||
</proble-oh no my finger broke and I can't close the problem tag properly...
|
||||
""")
|
||||
descriptor = self._create_descriptor(sample_invalid_xml, name="Invalid XML")
|
||||
try:
|
||||
descriptor.has_support(None, "multi_device")
|
||||
except etree.XMLSyntaxError:
|
||||
self.fail("Exception raised during XML parsing, this method should be resilient to such errors")
|
||||
|
||||
|
||||
class ComplexEncoderTest(unittest.TestCase):
|
||||
def test_default(self):
|
||||
|
||||
Reference in New Issue
Block a user