Skip to content

Commit

Permalink
feat: Serialize tag data in OpenAssessmentBlocks (#2171)
Browse files Browse the repository at this point in the history
  • Loading branch information
yusuf-musleh authored Feb 13, 2024
1 parent a255a08 commit 7c33111
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion openassessment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Initialization Information for Open Assessment Module
"""

__version__ = '6.0.32'
__version__ = '6.0.33'
34 changes: 34 additions & 0 deletions openassessment/xblock/test/test_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,40 @@ def test_serialize_assessments(self, data):
xml_str = serialize_assessments_to_xml_str(self.oa_block)
self.assertIn(data['assessments'][0]['name'], xml_str)

@ddt.file_data('data/serialize.json')
def test_serialize_with_tags(self, data):
self._configure_xblock(data)

# Create a mocked serialize tag data method that returns no data
def add_tags_to_node_no_tags(node): # pylint: disable=unused-argument
return

# Manually add the mocked method to the OpenAssessment block instance
# This method will be added in the edx-platform repo through applying XBLOCK_MIXINS
self.oa_block.add_tags_to_node = add_tags_to_node_no_tags

xml = serialize_content(self.oa_block)

# Confirm that no tags appear in the xml
self.assertNotIn("tags-v1", xml)

# Create a mocked serialize tag data method that returns data
def add_tags_to_node_with_tags(node):
# return "lightcast-skills:Typing,Microsoft Office"
node.set('tags-v1', 'lightcast-skills:Typing,Microsoft Office')

# Manually add the mocked method to the OpenAssessment block instance
# This method will be added in the edx-platform repo through applying XBLOCK_MIXINS
self.oa_block.add_tags_to_node = add_tags_to_node_with_tags

xml = serialize_content(self.oa_block)

# Confirm that tags appear in the xml
self.assertIn("tags-v1=\"lightcast-skills:Typing,Microsoft Office\"", xml)

# Clear the mocked serialize tag data method
del self.oa_block.add_tags_to_node

def test_mutated_criteria_dict(self):
self._configure_xblock({})

Expand Down
5 changes: 5 additions & 0 deletions openassessment/xblock/utils/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,11 @@ def serialize_content_to_xml(oa_block, root):
if oa_block.show_rubric_during_response is not None:
root.set('show_rubric_during_response', str(oa_block.show_rubric_during_response))

# Serialize and add tag data if any
if hasattr(oa_block, 'add_tags_to_node') and callable(oa_block.add_tags_to_node): # pylint: disable=no-member
# This comes from TaggedBlockMixin
oa_block.add_tags_to_node(root) # pylint: disable=no-member


def serialize_content(oa_block):
"""
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "edx-ora2",
"version": "6.0.32",
"version": "6.0.33",
"repository": "https://github.com/openedx/edx-ora2.git",
"dependencies": {
"@edx/frontend-build": "8.0.6",
Expand Down

0 comments on commit 7c33111

Please sign in to comment.