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
a4dfc0f4
Commit
a4dfc0f4
authored
Feb 26, 2013
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests for TrueFalseResponse. Cleaned up tests by
creating common base class.
parent
c225af4e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
40 deletions
+68
-40
common/lib/capa/capa/tests/response_xml_factory.py
+68
-40
common/lib/capa/capa/tests/test_responsetypes.py
+0
-0
No files found.
common/lib/capa/capa/tests/response_xml_factory.py
View file @
a4dfc0f4
...
@@ -108,6 +108,54 @@ class ResponseXMLFactory(object):
...
@@ -108,6 +108,54 @@ class ResponseXMLFactory(object):
return
input_element
return
input_element
@staticmethod
def
choicegroup_input_xml
(
**
kwargs
):
""" Create a <choicegroup> XML element
Uses **kwargs:
*choice_type*: Can be "checkbox", "radio", or "multiple"
*choices*: List of True/False values indicating whether
a particular choice is correct or not.
Users must choose *all* correct options in order
to be marked correct.
DEFAULT: [True]
*choice_names": List of strings identifying the choices.
If specified, you must ensure that
len(choice_names) == len(choices)
"""
# Names of group elements
group_element_names
=
{
'checkbox'
:
'checkboxgroup'
,
'radio'
:
'radiogroup'
,
'multiple'
:
'choicegroup'
}
# Retrieve **kwargs
choices
=
kwargs
.
get
(
'choices'
,
[
True
])
choice_type
=
kwargs
.
get
(
'choice_type'
,
'multiple'
)
choice_names
=
kwargs
.
get
(
'choice_names'
,
[
None
]
*
len
(
choices
))
# Create the <choicegroup>, <checkboxgroup>, or <radiogroup> element
assert
(
choice_type
in
group_element_names
)
group_element
=
etree
.
Element
(
group_element_names
[
choice_type
])
# Create the <choice> elements
for
(
correct_val
,
name
)
in
zip
(
choices
,
choice_names
):
choice_element
=
etree
.
SubElement
(
group_element
,
"choice"
)
choice_element
.
set
(
"correct"
,
"true"
if
correct_val
else
"false"
)
# Add some text describing the choice
etree
.
SubElement
(
choice_element
,
"startouttext"
)
etree
.
text
=
"Choice description"
etree
.
SubElement
(
choice_element
,
"endouttext"
)
# Add a name identifying the choice, if one exists
if
name
:
choice_element
.
set
(
"name"
,
str
(
name
))
return
group_element
class
NumericalResponseXMLFactory
(
ResponseXMLFactory
):
class
NumericalResponseXMLFactory
(
ResponseXMLFactory
):
""" Factory for producing <numericalresponse> XML trees """
""" Factory for producing <numericalresponse> XML trees """
...
@@ -237,39 +285,9 @@ class ChoiceResponseXMLFactory(ResponseXMLFactory):
...
@@ -237,39 +285,9 @@ class ChoiceResponseXMLFactory(ResponseXMLFactory):
return
etree
.
Element
(
"choiceresponse"
)
return
etree
.
Element
(
"choiceresponse"
)
def
create_input_element
(
self
,
**
kwargs
):
def
create_input_element
(
self
,
**
kwargs
):
""" Create a <checkboxgroup> element.
""" Create a <checkboxgroup> element."""
return
ResponseXMLFactory
.
choicegroup_input_xml
(
**
kwargs
)
Uses *kwargs*:
*allow_multiple*: If True, use checkboxes;
otherwise, use radio buttons
DEFAULT: True
*choices*: List of True/False values indicating whether
a particular choice is correct or not.
Users must choose *all* correct options in order
to be marked correct.
DEFAULT: [True]
"""
# Retrieve **kwargs
allow_multiple
=
kwargs
.
get
(
'allow_multiple'
,
True
)
choices
=
kwargs
.
get
(
'choices'
,
[
True
])
# Create the <checkboxgroup> or <radiogroup> element
group_element
=
etree
.
Element
(
"checkboxgroup"
if
allow_multiple
else
"radiogroup"
)
# Create the <choice> elements
for
correct_val
in
choices
:
choice_element
=
etree
.
SubElement
(
group_element
,
"choice"
)
choice_element
.
set
(
"correct"
,
"true"
if
correct_val
else
"false"
)
# Add some text describing the choice
etree
.
SubElement
(
choice_element
,
"startouttext"
)
etree
.
text
=
"Choice description"
etree
.
SubElement
(
choice_element
,
"endouttext"
)
return
group_element
class
FormulaResponseXMLFactory
(
ResponseXMLFactory
):
class
FormulaResponseXMLFactory
(
ResponseXMLFactory
):
def
create_response_element
(
self
,
**
kwargs
):
def
create_response_element
(
self
,
**
kwargs
):
...
@@ -293,34 +311,44 @@ class JavascriptResponseXMLFactory(ResponseXMLFactory):
...
@@ -293,34 +311,44 @@ class JavascriptResponseXMLFactory(ResponseXMLFactory):
raise
NotImplemented
raise
NotImplemented
class
MultipleChoiceResponseXMLFactory
(
ResponseXMLFactory
):
class
MultipleChoiceResponseXMLFactory
(
ResponseXMLFactory
):
""" Factory for producing <multiplechoiceresponse> XML """
def
create_response_element
(
self
,
**
kwargs
):
def
create_response_element
(
self
,
**
kwargs
):
raise
NotImplemented
""" Create the <multiplechoiceresponse> element"""
return
etree
.
Element
(
'multiplechoiceresponse'
)
def
create_input_element
(
self
,
**
kwargs
):
def
create_input_element
(
self
,
**
kwargs
):
raise
NotImplemented
""" Create the <choicegroup> element"""
kwargs
[
'choice_type'
]
=
'multiple'
return
ResponseXMLFactory
.
choicegroup_input_xml
(
**
kwargs
)
class
TrueFalseResponseXMLFactory
(
ResponseXMLFactory
):
""" Factory for producing <truefalseresponse> XML """
class
OptionResponseXMLFactory
(
ResponseXMLFactory
):
def
create_response_element
(
self
,
**
kwargs
):
def
create_response_element
(
self
,
**
kwargs
):
raise
NotImplemented
""" Create the <truefalseresponse> element"""
return
etree
.
Element
(
'truefalseresponse'
)
def
create_input_element
(
self
,
**
kwargs
):
def
create_input_element
(
self
,
**
kwargs
):
raise
NotImplemented
""" Create the <choicegroup> element"""
kwargs
[
'choice_type'
]
=
'multiple'
return
ResponseXMLFactory
.
choicegroup_input_xml
(
**
kwargs
)
class
String
ResponseXMLFactory
(
ResponseXMLFactory
):
class
Option
ResponseXMLFactory
(
ResponseXMLFactory
):
def
create_response_element
(
self
,
**
kwargs
):
def
create_response_element
(
self
,
**
kwargs
):
raise
NotImplemented
raise
NotImplemented
def
create_input_element
(
self
,
**
kwargs
):
def
create_input_element
(
self
,
**
kwargs
):
raise
NotImplemented
raise
NotImplemented
class
S
ymbolic
ResponseXMLFactory
(
ResponseXMLFactory
):
class
S
tring
ResponseXMLFactory
(
ResponseXMLFactory
):
def
create_response_element
(
self
,
**
kwargs
):
def
create_response_element
(
self
,
**
kwargs
):
raise
NotImplemented
raise
NotImplemented
def
create_input_element
(
self
,
**
kwargs
):
def
create_input_element
(
self
,
**
kwargs
):
raise
NotImplemented
raise
NotImplemented
class
TrueFalse
ResponseXMLFactory
(
ResponseXMLFactory
):
class
Symbolic
ResponseXMLFactory
(
ResponseXMLFactory
):
def
create_response_element
(
self
,
**
kwargs
):
def
create_response_element
(
self
,
**
kwargs
):
raise
NotImplemented
raise
NotImplemented
...
...
common/lib/capa/capa/tests/test_responsetypes.py
View file @
a4dfc0f4
This diff is collapsed.
Click to expand it.
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