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
4ed229e8
Commit
4ed229e8
authored
Feb 26, 2013
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modified StringResponse test to use XML factory and
to check case-insensitivity.
parent
1060ce49
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
15 deletions
+52
-15
common/lib/capa/capa/tests/response_xml_factory.py
+27
-2
common/lib/capa/capa/tests/test_responsetypes.py
+25
-13
No files found.
common/lib/capa/capa/tests/response_xml_factory.py
View file @
4ed229e8
...
...
@@ -374,11 +374,36 @@ class OptionResponseXMLFactory(ResponseXMLFactory):
class
StringResponseXMLFactory
(
ResponseXMLFactory
):
""" Factory for producing <stringresponse> XML """
def
create_response_element
(
self
,
**
kwargs
):
raise
NotImplemented
""" Create a <stringresponse> XML element.
Uses **kwargs:
*answer*: The correct answer (a string) [REQUIRED]
*case_sensitive*: Whether the response is case-sensitive (True/False)
[DEFAULT: True]
"""
# Retrieve the **kwargs
answer
=
kwargs
.
get
(
"answer"
,
None
)
case_sensitive
=
kwargs
.
get
(
"case_sensitive"
,
True
)
assert
(
answer
)
# Create the <stringresponse> element
response_element
=
etree
.
Element
(
"stringresponse"
)
# Set the answer attribute
response_element
.
set
(
"answer"
,
str
(
answer
))
# Set the case sensitivity
response_element
.
set
(
"type"
,
"cs"
if
case_sensitive
else
"ci"
)
return
response_element
def
create_input_element
(
self
,
**
kwargs
):
raise
NotImplemented
return
ResponseXMLFactory
.
textline_input_xml
(
**
kwargs
)
class
SymbolicResponseXMLFactory
(
ResponseXMLFactory
):
def
create_response_element
(
self
,
**
kwargs
):
...
...
common/lib/capa/capa/tests/test_responsetypes.py
View file @
4ed229e8
...
...
@@ -283,19 +283,31 @@ class FormulaResponseWithHintTest(unittest.TestCase):
self
.
assertTrue
(
'You have inverted'
in
cmap
.
get_hint
(
'1_2_1'
))
class
StringResponseWithHintTest
(
unittest
.
TestCase
):
'''
Test String response problem with a hint
'''
def
test_or_grade
(
self
):
problem_file
=
os
.
path
.
dirname
(
__file__
)
+
"/test_files/stringresponse_with_hint.xml"
test_lcp
=
lcp
.
LoncapaProblem
(
open
(
problem_file
)
.
read
(),
'1'
,
system
=
test_system
)
correct_answers
=
{
'1_2_1'
:
'Michigan'
}
test_answers
=
{
'1_2_1'
:
'Minnesota'
}
self
.
assertEquals
(
test_lcp
.
grade_answers
(
correct_answers
)
.
get_correctness
(
'1_2_1'
),
'correct'
)
cmap
=
test_lcp
.
grade_answers
(
test_answers
)
self
.
assertEquals
(
cmap
.
get_correctness
(
'1_2_1'
),
'incorrect'
)
self
.
assertTrue
(
'St. Paul'
in
cmap
.
get_hint
(
'1_2_1'
))
class
StringResponseWithHintTest
(
ResponseTest
):
from
response_xml_factory
import
StringResponseXMLFactory
xml_factory_class
=
StringResponseXMLFactory
def
test_case_sensitive
(
self
):
problem
=
self
.
build_problem
(
answer
=
"Second"
,
case_sensitive
=
True
)
# Exact string should be correct
self
.
assert_grade
(
problem
,
"Second"
,
"correct"
)
# Other strings and the lowercase version of the string are incorrect
self
.
assert_grade
(
problem
,
"Other String"
,
"incorrect"
)
self
.
assert_grade
(
problem
,
"second"
,
"incorrect"
)
def
test_case_insensitive
(
self
):
problem
=
self
.
build_problem
(
answer
=
"Second"
,
case_sensitive
=
False
)
# Both versions of the string should be allowed, regardless
# of capitalization
self
.
assert_grade
(
problem
,
"Second"
,
"correct"
)
self
.
assert_grade
(
problem
,
"second"
,
"correct"
)
# Other strings are not allowed
self
.
assert_grade
(
problem
,
"Other String"
,
"incorrect"
)
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