Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-ora2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-ora2
Commits
d92cce76
Commit
d92cce76
authored
Jun 11, 2014
by
Stephen Sanchez
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #429 from edx/sanchez/include_prompt_flag
Sanchez/include prompt flag
parents
30f052e0
c0aadeb7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
12 deletions
+22
-12
openassessment/xblock/test/test_xml.py
+8
-4
openassessment/xblock/xml.py
+14
-8
No files found.
openassessment/xblock/test/test_xml.py
View file @
d92cce76
...
...
@@ -124,16 +124,15 @@ class TestSerializeContent(TestCase):
parsed_expected
=
etree
.
fromstring
(
""
.
join
(
data
[
'expected_xml'
]))
# Pretty-print and reparse the expected XML
pretty_expected
=
etree
.
tostring
(
parsed_expected
,
pretty_print
=
True
,
encoding
=
'u
tf-8
'
)
pretty_expected
=
etree
.
tostring
(
parsed_expected
,
pretty_print
=
True
,
encoding
=
'u
nicode
'
)
parsed_expected
=
etree
.
fromstring
(
pretty_expected
)
# Walk both trees, comparing elements and attributes
actual_elements
=
[
el
for
el
in
parsed_actual
.
getiterator
()]
expected_elements
=
[
el
for
el
in
parsed_expected
.
getiterator
()]
self
.
assertEqual
(
len
(
actual_elements
),
len
(
expected_elements
),
msg
=
"Incorrect XML output:
\n
Actual: {}
\n
Expected: {}"
.
format
(
xml
,
pretty_expected
)
msg
=
u
"Incorrect XML output:
\n
Actual: {}
\n
Expected: {}"
.
format
(
xml
,
pretty_expected
)
)
for
actual
,
expected
in
zip
(
actual_elements
,
expected_elements
):
...
...
@@ -155,18 +154,23 @@ class TestSerializeContent(TestCase):
def
test_serialize_rubric
(
self
,
data
):
self
.
_configure_xblock
(
data
)
xml_str
=
serialize_rubric_to_xml_str
(
self
.
oa_block
)
self
.
assertIn
(
"<rubric>"
,
xml_str
)
if
data
[
'prompt'
]:
self
.
assertNotIn
(
data
[
'prompt'
],
xml_str
)
@ddt.file_data
(
'data/serialize.json'
)
def
test_serialize_examples
(
self
,
data
):
self
.
_configure_xblock
(
data
)
for
assessment
in
data
[
'assessments'
]:
if
'student-training'
==
assessment
[
'name'
]:
if
'student-training'
==
assessment
[
'name'
]
and
assessment
[
'examples'
]
:
xml_str
=
serialize_examples_to_xml_str
(
assessment
)
self
.
assertIn
(
assessment
[
'examples'
][
0
][
'answer'
],
xml_str
)
@ddt.file_data
(
'data/serialize.json'
)
def
test_serialize_assessments
(
self
,
data
):
self
.
_configure_xblock
(
data
)
xml_str
=
serialize_assessments_to_xml_str
(
self
.
oa_block
)
self
.
assertIn
(
data
[
'assessments'
][
0
][
'name'
],
xml_str
)
def
test_mutated_criteria_dict
(
self
):
self
.
oa_block
.
title
=
"Test title"
...
...
openassessment/xblock/xml.py
View file @
d92cce76
...
...
@@ -124,7 +124,7 @@ def _serialize_criteria(criteria_root, criteria_list):
_serialize_options
(
criterion_el
,
options_list
)
def
serialize_rubric
(
rubric_root
,
oa_block
):
def
serialize_rubric
(
rubric_root
,
oa_block
,
include_prompt
=
True
):
"""
Serialize a rubric dictionary as XML, adding children to the XML
with root node `rubric_root`.
...
...
@@ -138,11 +138,14 @@ def serialize_rubric(rubric_root, oa_block):
rubric_dict (dict): A dictionary representation of the rubric, of the form
described in the serialized Rubric model (peer grading serializers).
Kwargs:
include_prompt (bool): Whether or not to include the prompt in the
serialized format for a rubric. Defaults to True.
Returns:
None
"""
# Rubric prompt (default to empty text); None indicates no input element
if
oa_block
.
prompt
is
not
None
:
if
include_prompt
and
oa_block
.
prompt
is
not
None
:
prompt
=
etree
.
SubElement
(
rubric_root
,
'prompt'
)
prompt
.
text
=
unicode
(
oa_block
.
prompt
)
...
...
@@ -555,12 +558,15 @@ def serialize_content(oa_block):
serialize_content_to_xml
(
oa_block
,
root
)
# Return a UTF-8 representation of the XML
return
etree
.
tostring
(
root
,
pretty_print
=
True
,
encoding
=
'u
tf-8
'
)
return
etree
.
tostring
(
root
,
pretty_print
=
True
,
encoding
=
'u
nicode
'
)
def
serialize_rubric_to_xml_str
(
oa_block
):
"""
Serialize the OpenAssessment XBlock's rubric into an XML string.
Serialize the OpenAssessment XBlock's rubric into an XML string. This is
designed to serialize the XBlock's rubric specifically for authoring. Since
the authoring view splits the prompt from the rubric, the serialized format
for the rubric does not contain the prompt.
Args:
oa_block (OpenAssessmentBlock): The open assessment block to serialize
...
...
@@ -571,8 +577,8 @@ def serialize_rubric_to_xml_str(oa_block):
"""
rubric_root
=
etree
.
Element
(
'rubric'
)
serialize_rubric
(
rubric_root
,
oa_block
)
return
etree
.
tostring
(
rubric_root
,
pretty_print
=
True
,
encoding
=
'u
tf-8
'
)
serialize_rubric
(
rubric_root
,
oa_block
,
include_prompt
=
False
)
return
etree
.
tostring
(
rubric_root
,
pretty_print
=
True
,
encoding
=
'u
nicode
'
)
def
serialize_examples_to_xml_str
(
assessment
):
...
...
@@ -594,7 +600,7 @@ def serialize_examples_to_xml_str(assessment):
examples
=
[]
examples_root
=
etree
.
Element
(
'examples'
)
serialize_training_examples
(
examples
,
examples_root
)
return
etree
.
tostring
(
examples_root
,
pretty_print
=
True
,
encoding
=
'u
tf-8
'
)
return
etree
.
tostring
(
examples_root
,
pretty_print
=
True
,
encoding
=
'u
nicode
'
)
def
serialize_assessments_to_xml_str
(
oa_block
):
...
...
@@ -607,7 +613,7 @@ def serialize_assessments_to_xml_str(oa_block):
"""
assessments_root
=
etree
.
Element
(
'assessments'
)
serialize_assessments
(
assessments_root
,
oa_block
)
return
etree
.
tostring
(
assessments_root
,
pretty_print
=
True
,
encoding
=
'u
tf-8
'
)
return
etree
.
tostring
(
assessments_root
,
pretty_print
=
True
,
encoding
=
'u
nicode
'
)
def
parse_from_xml
(
root
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment