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
9360c3fa
Commit
9360c3fa
authored
Feb 26, 2013
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added test for StringResponse hints
parent
4ed229e8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
0 deletions
+50
-0
common/lib/capa/capa/tests/response_xml_factory.py
+21
-0
common/lib/capa/capa/tests/test_responsetypes.py
+29
-0
No files found.
common/lib/capa/capa/tests/response_xml_factory.py
View file @
9360c3fa
...
...
@@ -382,12 +382,19 @@ class StringResponseXMLFactory(ResponseXMLFactory):
Uses **kwargs:
*answer*: The correct answer (a string) [REQUIRED]
*case_sensitive*: Whether the response is case-sensitive (True/False)
[DEFAULT: True]
*hints*: List of (hint_prompt, hint_name, hint_text) tuples
Where *hint_prompt* is the string for which we show the hint,
*hint_name* is an internal identifier for the hint,
and *hint_text* is the text we show for the hint.
"""
# Retrieve the **kwargs
answer
=
kwargs
.
get
(
"answer"
,
None
)
case_sensitive
=
kwargs
.
get
(
"case_sensitive"
,
True
)
hint_list
=
kwargs
.
get
(
'hints'
,
None
)
assert
(
answer
)
# Create the <stringresponse> element
...
...
@@ -399,6 +406,20 @@ class StringResponseXMLFactory(ResponseXMLFactory):
# Set the case sensitivity
response_element
.
set
(
"type"
,
"cs"
if
case_sensitive
else
"ci"
)
# Add the hints if specified
if
hint_list
:
hintgroup_element
=
etree
.
SubElement
(
response_element
,
"hintgroup"
)
for
(
hint_prompt
,
hint_name
,
hint_text
)
in
hint_list
:
stringhint_element
=
etree
.
SubElement
(
hintgroup_element
,
"stringhint"
)
stringhint_element
.
set
(
"answer"
,
str
(
hint_prompt
))
stringhint_element
.
set
(
"name"
,
str
(
hint_name
))
hintpart_element
=
etree
.
SubElement
(
hintgroup_element
,
"hintpart"
)
hintpart_element
.
set
(
"on"
,
str
(
hint_name
))
hint_text_element
=
etree
.
SubElement
(
hintpart_element
,
"text"
)
hint_text_element
.
text
=
str
(
hint_text
)
return
response_element
def
create_input_element
(
self
,
**
kwargs
):
...
...
common/lib/capa/capa/tests/test_responsetypes.py
View file @
9360c3fa
...
...
@@ -309,6 +309,35 @@ class StringResponseWithHintTest(ResponseTest):
# Other strings are not allowed
self
.
assert_grade
(
problem
,
"Other String"
,
"incorrect"
)
def
test_hints
(
self
):
hints
=
[(
"wisconsin"
,
"wisc"
,
"The state capital of Wisconsin is Madison"
),
(
"minnesota"
,
"minn"
,
"The state capital of Minnesota is St. Paul"
)]
problem
=
self
.
build_problem
(
answer
=
"Michigan"
,
case_sensitive
=
False
,
hints
=
hints
)
# We should get a hint for Wisconsin
input_dict
=
{
'1_2_1'
:
'Wisconsin'
}
correct_map
=
problem
.
grade_answers
(
input_dict
)
self
.
assertEquals
(
correct_map
.
get_hint
(
'1_2_1'
),
"The state capital of Wisconsin is Madison"
)
# We should get a hint for Minnesota
input_dict
=
{
'1_2_1'
:
'Minnesota'
}
correct_map
=
problem
.
grade_answers
(
input_dict
)
self
.
assertEquals
(
correct_map
.
get_hint
(
'1_2_1'
),
"The state capital of Minnesota is St. Paul"
)
# We should NOT get a hint for Michigan (the correct answer)
input_dict
=
{
'1_2_1'
:
'Michigan'
}
correct_map
=
problem
.
grade_answers
(
input_dict
)
self
.
assertEquals
(
correct_map
.
get_hint
(
'1_2_1'
),
""
)
# We should NOT get a hint for any other string
input_dict
=
{
'1_2_1'
:
'California'
}
correct_map
=
problem
.
grade_answers
(
input_dict
)
self
.
assertEquals
(
correct_map
.
get_hint
(
'1_2_1'
),
""
)
class
CodeResponseTest
(
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