Commit e25754e2 by Usman Khalid

Update assessments format when serializing.

parent 2754222e
......@@ -83,9 +83,10 @@ def update_assessments_format(assessments):
list of dict
"""
for assessment in assessments:
if 'examples' in assessment:
if 'examples' in assessment and assessment['examples']:
for example in assessment['examples']:
if isinstance(example['answer'], unicode) or isinstance(example['answer'], str):
if (isinstance(example, dict) and
(isinstance(example['answer'], unicode) or isinstance(example['answer'], str))):
example['answer'] = {
'parts': [
{'text': example['answer']}
......
......@@ -120,9 +120,8 @@ class TestSerializeContent(TestCase):
self.oa_block.submission_start = data.get('submission_start')
self.oa_block.submission_due = data.get('submission_due')
self.oa_block.rubric_criteria = data.get('criteria', copy.deepcopy(self.BASIC_CRITERIA))
self.oa_block.rubric_assessments = update_assessments_format(
data.get('assessments', copy.deepcopy(self.BASIC_ASSESSMENTS))
)
self.oa_block.rubric_assessments = data.get('assessments', copy.deepcopy(self.BASIC_ASSESSMENTS))
self.oa_block.allow_file_upload = data.get('allow_file_upload')
self.oa_block.allow_latex = data.get('allow_latex')
self.oa_block.leaderboard_show = data.get('leaderboard_show', 0)
......@@ -231,7 +230,7 @@ class TestSerializeContent(TestCase):
def test_mutated_assessments_dict(self):
self._configure_xblock({})
for assessment_dict in update_assessments_format(self.BASIC_ASSESSMENTS):
for assessment_dict in self.BASIC_ASSESSMENTS:
for mutated_dict in self._dict_mutations(assessment_dict):
self.oa_block.rubric_assessments = [mutated_dict]
xml = serialize_content(self.oa_block)
......
......@@ -6,6 +6,7 @@ import lxml.etree as etree
import pytz
import dateutil.parser
import defusedxml.ElementTree as safe_etree
from data_conversion import update_assessments_format
from defaults import DEFAULT_RUBRIC_FEEDBACK_TEXT
......@@ -630,7 +631,7 @@ def serialize_assessments(assessments_root, oa_block):
None
"""
for assessment_dict in oa_block.rubric_assessments:
for assessment_dict in update_assessments_format(oa_block.rubric_assessments):
assessment = etree.SubElement(assessments_root, 'assessment')
......@@ -760,7 +761,7 @@ def serialize_examples_to_xml_str(assessment):
A unicode string of the XML serialized examples.
"""
examples = assessment.get('examples', [])
examples = update_assessments_format([assessment])[0].get('examples', [])
if not isinstance(examples, list):
examples = []
examples_root = etree.Element('examples')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment