fix: support parsing the pointer-tag OLX for external XBlocks (#37133)

Previously, the built-in XBlocks (problem, video, etc) could be parsed
from pointer tag syntax, but externally-defined XBlocks (drag-and-drop,
ORA, etc.) could only be parsed from inline syntax. This is because the
built-in blocks have special parsing logic, defined in XmlMixin,
which is not available to external blocks.

This PR shifts the pointer tag parsing "up a level" such that the parent
blocks parse the pointer tag, regardless of whether the child is built-in
or external:
* vertical (aka unit)
* split_test (aka content experiment)
* itembank (aka problem bank)
* library_content (aka randomized legacy library)

The following parent blocks still lack support for external pointer-tag children;
we will fix this in a follow-up PR:
* randomize
* all externally defined container blocks

Part of: https://github.com/openedx/XBlock/issues/823
This commit is contained in:
M. Tayyab Tahir Qureshi
2025-10-03 20:54:30 +05:00
committed by GitHub
parent c943c223b4
commit d382721cf8
6 changed files with 78 additions and 16 deletions

View File

@@ -42,13 +42,14 @@ class InMemorySystem(XMLParsingSystem, MakoDescriptorSystem): # pylint: disable
)
self.id_generator = Mock()
def process_xml(self, xml): # pylint: disable=method-hidden
def process_xml(self, xml, def_id=None, def_loaded=False): # pylint: disable=method-hidden
"""Parse `xml` as an XBlock, and add it to `self._blocks`"""
self.get_asides = Mock(return_value=[])
block = self.xblock_from_node(
etree.fromstring(xml),
None,
CourseLocationManager(self.course_id),
def_id,
)
self._blocks[str(block.location)] = block
return block
@@ -61,7 +62,7 @@ class InMemorySystem(XMLParsingSystem, MakoDescriptorSystem): # pylint: disable
class XModuleXmlImportTest(TestCase):
"""Base class for tests that use basic XML parsing"""
@classmethod
def process_xml(cls, xml_import_data):
def process_xml(cls, xml_import_data, def_id=None, def_loaded=False):
"""Use the `xml_import_data` to import an :class:`XBlock` from XML."""
system = InMemorySystem(xml_import_data)
return system.process_xml(xml_import_data.xml_string)
return system.process_xml(xml_import_data.xml_string, def_id)