Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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-platform
Commits
d85cdcac
Commit
d85cdcac
authored
Sep 05, 2016
by
muhammad-ammar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update question tag extraction logic
parent
c5de73a7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
5 deletions
+78
-5
common/lib/capa/capa/capa_problem.py
+12
-2
common/lib/capa/capa/tests/test_capa_problem.py
+66
-3
No files found.
common/lib/capa/capa/capa_problem.py
View file @
d85cdcac
...
...
@@ -942,11 +942,21 @@ class LoncapaProblem(object):
# store <label> tag containing question text to delete
# it later otherwise question will be rendered twice
element_to_be_deleted
=
responsetype_label_tag
elif
'label'
not
in
inputfields
[
0
]
.
attrib
:
elif
'label'
in
inputfields
[
0
]
.
attrib
:
# in this case we have old problems with label attribute and p tag having question in it
# we will pick the first sibling of responsetype if its a p tag and match the text with
# the label attribute text. if they are equal then we will use this text as question.
# Get first <p> tag before responsetype, this <p> may contains the question text.
p_tag
=
response
.
xpath
(
'preceding-sibling::*[1][self::p]'
)
if
p_tag
and
p_tag
[
0
]
.
text
==
inputfields
[
0
]
.
attrib
[
'label'
]:
label
=
p_tag
[
0
]
.
text
element_to_be_deleted
=
p_tag
[
0
]
else
:
# In this case the problems don't have tag or label attribute inside the responsetype
# so we will get the first preceding label tag w.r.t to this responsetype.
# This will take care of those multi-question problems that are not using --- in their markdown.
label_tag
=
response
.
xpath
(
'preceding-sibling::
label[1
]'
)
label_tag
=
response
.
xpath
(
'preceding-sibling::
*[1][self::label
]'
)
if
label_tag
:
label
=
label_tag
[
0
]
.
text
element_to_be_deleted
=
label_tag
[
0
]
...
...
common/lib/capa/capa/tests/test_capa_problem.py
View file @
d85cdcac
...
...
@@ -9,6 +9,7 @@ import unittest
from
.
import
new_loncapa_problem
@ddt.ddt
class
CAPAProblemTest
(
unittest
.
TestCase
):
""" CAPA problem related tests"""
...
...
@@ -66,14 +67,14 @@ class CAPAProblemTest(unittest.TestCase):
{
'1_2_1'
:
{
'label'
:
''
,
'label'
:
question
,
'descriptions'
:
{}
}
}
)
self
.
assertEqual
(
len
(
problem
.
tree
.
xpath
(
"//*[normalize-space(text())='{}']"
.
format
(
question
))),
1
0
)
def
test_neither_label_tag_nor_attribute
(
self
):
...
...
@@ -176,7 +177,7 @@ class CAPAProblemTest(unittest.TestCase):
{
'1_2_1'
:
{
'label'
:
''
,
'label'
:
question
,
'descriptions'
:
{}
}
}
...
...
@@ -361,6 +362,68 @@ class CAPAProblemTest(unittest.TestCase):
question
=
problem_html
.
xpath
(
"//*[normalize-space(text())='{}']"
.
format
(
question
))
self
.
assertEqual
(
len
(
question
),
1
)
def
assert_question_tag
(
self
,
question1
,
question2
,
tag
,
label_attr
=
False
):
"""
Verify question tag correctness.
"""
question1_tag
=
'<{tag}>{}</{tag}>'
.
format
(
question1
,
tag
=
tag
)
if
question1
else
''
question2_tag
=
'<{tag}>{}</{tag}>'
.
format
(
question2
,
tag
=
tag
)
if
question2
else
''
question1_label_attr
=
'label="{}"'
.
format
(
question1
)
if
label_attr
else
''
question2_label_attr
=
'label="{}"'
.
format
(
question2
)
if
label_attr
else
''
xml
=
"""
<problem>
{question1_tag}
<choiceresponse>
<checkboxgroup {question1_label_attr}>
<choice correct="true">choice1</choice>
<choice correct="false">choice2</choice>
</checkboxgroup>
</choiceresponse>
{question2_tag}
<multiplechoiceresponse>
<choicegroup type="MultipleChoice" {question2_label_attr}>
<choice correct="false">choice1</choice>
<choice correct="true">choice2</choice>
</choicegroup>
</multiplechoiceresponse>
</problem>
"""
.
format
(
question1_tag
=
question1_tag
,
question2_tag
=
question2_tag
,
question1_label_attr
=
question1_label_attr
,
question2_label_attr
=
question2_label_attr
,
)
problem
=
new_loncapa_problem
(
xml
)
self
.
assertEqual
(
problem
.
problem_data
,
{
'1_2_1'
:
{
'label'
:
question1
,
'descriptions'
:
{}
},
'1_3_1'
:
{
'label'
:
question2
,
'descriptions'
:
{}
}
}
)
self
.
assertEqual
(
len
(
problem
.
tree
.
xpath
(
'//{}'
.
format
(
tag
))),
0
)
@ddt.unpack
@ddt.data
(
{
'question1'
:
'question 1 label'
,
'question2'
:
'question 2 label'
},
{
'question1'
:
''
,
'question2'
:
'question 2 label'
},
{
'question1'
:
'question 1 label'
,
'question2'
:
''
}
)
def
test_correct_question_tag_is_picked
(
self
,
question1
,
question2
):
"""
For a problem with multiple questions verify that correct question tag is picked.
"""
self
.
assert_question_tag
(
question1
,
question2
,
tag
=
'label'
,
label_attr
=
False
)
self
.
assert_question_tag
(
question1
,
question2
,
tag
=
'p'
,
label_attr
=
True
)
@ddt.ddt
class
CAPAMultiInputProblemTest
(
unittest
.
TestCase
):
...
...
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