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
1060ce49
Commit
1060ce49
authored
Feb 26, 2013
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modified OptionResponseTest to use XML factory
parent
ee22a50d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
17 deletions
+48
-17
common/lib/capa/capa/tests/response_xml_factory.py
+34
-2
common/lib/capa/capa/tests/test_responsetypes.py
+14
-15
No files found.
common/lib/capa/capa/tests/response_xml_factory.py
View file @
1060ce49
...
...
@@ -335,11 +335,43 @@ class TrueFalseResponseXMLFactory(ResponseXMLFactory):
return
ResponseXMLFactory
.
choicegroup_input_xml
(
**
kwargs
)
class
OptionResponseXMLFactory
(
ResponseXMLFactory
):
""" Factory for producing <optionresponse> XML"""
def
create_response_element
(
self
,
**
kwargs
):
raise
NotImplemented
""" Create the <optionresponse> element"""
return
etree
.
Element
(
"optionresponse"
)
def
create_input_element
(
self
,
**
kwargs
):
raise
NotImplemented
""" Create the <optioninput> element.
Uses **kwargs:
*options*: a list of possible options the user can choose from [REQUIRED]
You must specify at least 2 options.
*correct_option*: the correct choice from the list of options [REQUIRED]
"""
options_list
=
kwargs
.
get
(
'options'
,
None
)
correct_option
=
kwargs
.
get
(
'correct_option'
,
None
)
assert
(
options_list
and
correct_option
)
assert
(
len
(
options_list
)
>
1
)
assert
(
correct_option
in
options_list
)
# Create the <optioninput> element
optioninput_element
=
etree
.
Element
(
"optioninput"
)
# Set the "options" attribute
# Format: "('first', 'second', 'third')"
options_attr_string
=
","
.
join
([
"'
%
s'"
%
str
(
o
)
for
o
in
options_list
])
options_attr_string
=
"(
%
s)"
%
options_attr_string
optioninput_element
.
set
(
'options'
,
options_attr_string
)
# Set the "correct" attribute
optioninput_element
.
set
(
'correct'
,
str
(
correct_option
))
return
optioninput_element
class
StringResponseXMLFactory
(
ResponseXMLFactory
):
def
create_response_element
(
self
,
**
kwargs
):
...
...
common/lib/capa/capa/tests/test_responsetypes.py
View file @
1060ce49
...
...
@@ -250,22 +250,21 @@ class SymbolicResponseTest(unittest.TestCase):
self
.
assertEquals
(
test_lcp
.
grade_answers
(
wrong_answers
)
.
get_correctness
(
'1_2_1'
),
'incorrect'
)
class
OptionResponseTest
(
unittest
.
TestCase
):
'''
Run this with
class
OptionResponseTest
(
ResponseTest
):
from
response_xml_factory
import
OptionResponseXMLFactory
xml_factory_class
=
OptionResponseXMLFactory
python manage.py test courseware.OptionResponseTest
'''
def
test_or_grade
(
self
):
optionresponse_file
=
os
.
path
.
dirname
(
__file__
)
+
"/test_files/optionresponse.xml"
test_lcp
=
lcp
.
LoncapaProblem
(
open
(
optionresponse_file
)
.
read
(),
'1'
,
system
=
test_system
)
correct_answers
=
{
'1_2_1'
:
'True'
,
'1_2_2'
:
'False'
}
test_answers
=
{
'1_2_1'
:
'True'
,
'1_2_2'
:
'True'
,
}
self
.
assertEquals
(
test_lcp
.
grade_answers
(
test_answers
)
.
get_correctness
(
'1_2_1'
),
'correct'
)
self
.
assertEquals
(
test_lcp
.
grade_answers
(
test_answers
)
.
get_correctness
(
'1_2_2'
),
'incorrect'
)
def
test_grade
(
self
):
problem
=
self
.
build_problem
(
options
=
[
"first"
,
"second"
,
"third"
],
correct_option
=
"second"
)
# Assert that we get the expected grades
self
.
assert_grade
(
problem
,
"first"
,
"incorrect"
)
self
.
assert_grade
(
problem
,
"second"
,
"correct"
)
self
.
assert_grade
(
problem
,
"third"
,
"incorrect"
)
# Options not in the list should be marked incorrect
self
.
assert_grade
(
problem
,
"invalid_option"
,
"incorrect"
)
class
FormulaResponseWithHintTest
(
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