Skip to content

Commit

Permalink
feat: deserialize tag info from xml [FC-0049] (#2181)
Browse files Browse the repository at this point in the history
* feat: deserialize tags from xml + test
* chore: bump version
  • Loading branch information
rpenido authored Feb 29, 2024
1 parent c76a89c commit 5329fea
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 3 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.1.0'
__version__ = '6.2.0'
11 changes: 10 additions & 1 deletion openassessment/xblock/openassessmentblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from webob import Response
from xblock.core import XBlock
from xblock.exceptions import NoSuchServiceError
from xblock.fields import Boolean, Integer, List, Scope, String
from xblock.fields import Boolean, Dict, Integer, List, Scope, String

from openassessment.staffgrader.staff_grader_mixin import StaffGraderMixin
from openassessment.workflow.errors import AssessmentWorkflowError
Expand Down Expand Up @@ -283,6 +283,9 @@ class OpenAssessmentBlock(
help="A title to display to a student (plain text)."
)

xml_attributes = Dict(help="Map of unhandled xml attributes, used only for storage between import and export",
default={}, scope=Scope.settings)

white_listed_file_types = List(
default=[],
scope=Scope.content,
Expand Down Expand Up @@ -934,6 +937,12 @@ def parse_xml(cls, node, runtime, keys, id_generator):
block.text_response_editor = config['text_response_editor']
block.title = config['title']
block.white_listed_file_types_string = config['white_listed_file_types']

# Deserialize and add tag data info to block if any
if hasattr(block, 'read_tags_from_node') and callable(block.read_tags_from_node): # pylint: disable=no-member
# This comes from TaggedBlockMixin
block.read_tags_from_node(node) # pylint: disable=no-member

return block

@property
Expand Down
93 changes: 93 additions & 0 deletions openassessment/xblock/test/data/content_tags.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<openassessment text_response="required" file_upload_response="" group_access="{&quot;381451918&quot;: [1179773159]}" prompts_type="text" tags-v1="test content tags">
<title>Open Assessment Test</title>
<prompts>
<prompt>
<description>Given the state of the world today, what do you think should be done to combat poverty? Please answer in a short essay of 200-300 words.</description>
</prompt>
<prompt>
<description>Given the state of the world today, what do you think should be done to combat pollution?</description>
</prompt>
</prompts>
<rubric>
<criterion>
<name>Concise</name>
<prompt>How concise is it?</prompt>
<option points="0">
<name>Neal Stephenson (late)</name>
<explanation>Neal Stephenson explanation</explanation>
</option>
<option points="1">
<name>HP Lovecraft</name>
<explanation>HP Lovecraft explanation</explanation>
</option>
<option points="3">
<name>Robert Heinlein</name>
<explanation>Robert Heinlein explanation</explanation>
</option>
<option points="4">
<name>Neal Stephenson (early)</name>
<explanation>Neal Stephenson (early) explanation</explanation>
</option>
<option points="5">
<name>Earnest Hemingway</name>
<explanation>Earnest Hemingway</explanation>
</option>
</criterion>
<criterion>
<name>Clear-headed</name>
<prompt>How clear is the thinking?</prompt>
<option points="0">
<name>Yogi Berra</name>
<explanation>Yogi Berra explanation</explanation>
</option>
<option points="1">
<name>Hunter S. Thompson</name>
<explanation>Hunter S. Thompson explanation</explanation>
</option>
<option points="2">
<name>Robert Heinlein</name>
<explanation>Robert Heinlein explanation</explanation>
</option>
<option points="3">
<name>Isaac Asimov</name>
<explanation>Isaac Asimov explanation</explanation>
</option>
<option points="10">
<name>Spock</name>
<explanation>Spock explanation</explanation>
</option>
</criterion>
<criterion>
<name>Form</name>
<prompt>Lastly, how is its form? Punctuation, grammar, and spelling all count.</prompt>
<option points="0">
<name>lolcats</name>
<explanation>lolcats explanation</explanation>
</option>
<option points="1">
<name>Facebook</name>
<explanation>Facebook explanation</explanation>
</option>
<option points="2">
<name>Reddit</name>
<explanation>Reddit explanation</explanation>
</option>
<option points="3">
<name>metafilter</name>
<explanation>metafilter explanation</explanation>
</option>
<option points="4">
<name>Usenet, 1996</name>
<explanation>Usenet, 1996 explanation</explanation>
</option>
<option points="5">
<name>The Elements of Style</name>
<explanation>The Elements of Style explanation</explanation>
</option>
</criterion>
</rubric>
<assessments>
<assessment name="peer-assessment" must_grade="5" must_be_graded_by="3" />
<assessment name="self-assessment" />
</assessments>
</openassessment>
33 changes: 32 additions & 1 deletion openassessment/xblock/test/test_openassessment.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from unittest import mock
from unittest.mock import MagicMock, Mock, PropertyMock, patch
from django.test.utils import override_settings
from workbench.runtime import WorkbenchRuntime

import ddt
import pytz
Expand All @@ -24,6 +25,29 @@
from .base import XBlockHandlerTestCase, scenario


original_construct_xblock_from_class = WorkbenchRuntime.construct_xblock_from_class


def _read_tags_from_node(self, node):
"""
This method is originally defined in the XmlMixin in edx-platform.
"""
assert 'tags-v1' in node.attrib
self.xml_attributes['tags-v1'] = str(node.attrib['tags-v1'])


def _construct_xblock_from_class(*args, **kwargs):
"""
Mock the original construct_xblock_from_class method to add the read_tags_from_node method and xml_attributes
property to the xblock.
In edx-platform, these members are part of the XmlMixin.
"""
xblock = original_construct_xblock_from_class(*args, **kwargs)
xblock.read_tags_from_node = lambda node: _read_tags_from_node(xblock, node)
return xblock


def assert_is_closed(
xblock,
now,
Expand Down Expand Up @@ -733,6 +757,12 @@ def test_mfe_views_supported__rearranged_steps(self, xblock):
# Given this ORA has rearranged our assessment steps
self.assertTrue(xblock.mfe_views_supported)

@patch.object(WorkbenchRuntime, 'construct_xblock_from_class', new=_construct_xblock_from_class)
@scenario('data/content_tags.xml')
def test_content_tags(self, xblock):
# Check if content tags are set properly
self.assertEqual(xblock.xml_attributes["tags-v1"], "test content tags")


class TestDates(XBlockHandlerTestCase):
""" Test Assessment Dates. """
Expand Down Expand Up @@ -1160,7 +1190,8 @@ def defined_manual_dates(self, xblock, step):
dt.datetime.fromisoformat(assessment.get('start')),
dt.datetime.fromisoformat(assessment.get('due'))
)
return None

assert False, f"Assessment {step} not found" # pragma: no cover

def setup_dates(self, xblock, course_dates=None, subsection_dates=None):
"""
Expand Down

0 comments on commit 5329fea

Please sign in to comment.