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
6d9fe76d
Commit
6d9fe76d
authored
Oct 23, 2012
by
Victor Shnayder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip. adding tests, basic refactor
parent
dd6d7e99
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
37 deletions
+49
-37
common/lib/capa/capa/inputtypes.py
+15
-27
common/lib/capa/capa/tests/test_inputtypes.py
+34
-10
No files found.
common/lib/capa/capa/inputtypes.py
View file @
6d9fe76d
...
@@ -195,29 +195,15 @@ class OptionInput(InputTypeBase):
...
@@ -195,29 +195,15 @@ class OptionInput(InputTypeBase):
template
=
"optioninput.html"
template
=
"optioninput.html"
tags
=
[
'optioninput'
]
tags
=
[
'optioninput'
]
def
_get_render_context
(
self
):
def
__init__
(
self
,
system
,
xml
,
state
):
return
_optioninput
(
self
.
xml
,
self
.
value
,
self
.
status
,
self
.
system
.
render_template
,
self
.
msg
)
super
(
OptionInput
,
self
)
.
__init__
(
system
,
xml
,
state
)
def
optioninput
(
element
,
value
,
status
,
render_template
,
msg
=
''
):
context
=
_optioninput
(
element
,
value
,
status
,
render_template
,
msg
)
html
=
render_template
(
"optioninput.html"
,
context
)
return
etree
.
XML
(
html
)
def
_optioninput
(
element
,
value
,
status
,
render_template
,
msg
=
''
):
"""
Select option input type.
Example:
<optioninput options="('Up','Down')" correct="Up"/><text>The location of the sky</text>
# Extract the options...
"""
options
=
self
.
xml
.
get
(
'options'
)
eid
=
element
.
get
(
'id'
)
options
=
element
.
get
(
'options'
)
if
not
options
:
if
not
options
:
raise
Exception
(
raise
Exception
(
"[courseware.capa.inputtypes.optioninput] Missing options specification in "
"[courseware.capa.inputtypes.optioninput] Missing options specification in "
+
etree
.
tostring
(
element
))
+
etree
.
tostring
(
self
.
xml
))
# parse the set of possible options
# parse the set of possible options
oset
=
shlex
.
shlex
(
options
[
1
:
-
1
])
oset
=
shlex
.
shlex
(
options
[
1
:
-
1
])
...
@@ -226,15 +212,18 @@ def _optioninput(element, value, status, render_template, msg=''):
...
@@ -226,15 +212,18 @@ def _optioninput(element, value, status, render_template, msg=''):
oset
=
[
x
[
1
:
-
1
]
for
x
in
list
(
oset
)]
oset
=
[
x
[
1
:
-
1
]
for
x
in
list
(
oset
)]
# make ordered list with (key, value) same
# make ordered list with (key, value) same
osetdict
=
[(
oset
[
x
],
oset
[
x
])
for
x
in
range
(
len
(
oset
))]
self
.
osetdict
=
[(
oset
[
x
],
oset
[
x
])
for
x
in
range
(
len
(
oset
))]
# TODO: allow ordering to be randomized
# TODO: allow ordering to be randomized
context
=
{
'id'
:
eid
,
def
_get_render_context
(
self
):
'value'
:
value
,
'state'
:
status
,
context
=
{
'msg'
:
msg
,
'id'
:
self
.
id
,
'options'
:
osetdict
,
'value'
:
self
.
value
,
'inline'
:
element
.
get
(
'inline'
,
''
),
'state'
:
self
.
status
,
'msg'
:
self
.
msg
,
'options'
:
self
.
osetdict
,
'inline'
:
self
.
xml
.
get
(
'inline'
,
''
),
}
}
return
context
return
context
...
@@ -245,7 +234,6 @@ register_input_class(OptionInput)
...
@@ -245,7 +234,6 @@ register_input_class(OptionInput)
# TODO: consolidate choicegroup, radiogroup, checkboxgroup after discussion of
# TODO: consolidate choicegroup, radiogroup, checkboxgroup after discussion of
# desired semantics.
# desired semantics.
# @register_render_function
def
choicegroup
(
element
,
value
,
status
,
render_template
,
msg
=
''
):
def
choicegroup
(
element
,
value
,
status
,
render_template
,
msg
=
''
):
'''
'''
Radio button inputs: multiple choice or true/false
Radio button inputs: multiple choice or true/false
...
...
common/lib/capa/capa/tests/test_inputtypes.py
View file @
6d9fe76d
...
@@ -27,14 +27,17 @@ class OptionInputTest(unittest.TestCase):
...
@@ -27,14 +27,17 @@ class OptionInputTest(unittest.TestCase):
'''
'''
Make sure option inputs work
Make sure option inputs work
'''
'''
def
test_rendering_new
(
self
):
xml
=
"""<optioninput options="('Up','Down')" id="sky_input" correct="Up"/>"""
element
=
etree
.
fromstring
(
xml
)
value
=
'Down'
def
test_rendering
(
self
):
status
=
'answered'
xml_str
=
"""<optioninput options="('Up','Down')" id="sky_input" correct="Up"/>"""
context
=
inputtypes
.
_optioninput
(
element
,
value
,
status
,
test_system
.
render_template
)
element
=
etree
.
fromstring
(
xml_str
)
print
'context: '
,
context
state
=
{
'value'
:
'Down'
,
'id'
:
'sky_input'
,
'status'
:
'answered'
}
option_input
=
inputtypes
.
OptionInput
(
system
,
element
,
state
)
context
=
option_input
.
_get_render_context
()
expected
=
{
'value'
:
'Down'
,
expected
=
{
'value'
:
'Down'
,
'options'
:
[(
'Up'
,
'Up'
),
(
'Down'
,
'Down'
)],
'options'
:
[(
'Up'
,
'Up'
),
(
'Down'
,
'Down'
)],
...
@@ -45,9 +48,30 @@ class OptionInputTest(unittest.TestCase):
...
@@ -45,9 +48,30 @@ class OptionInputTest(unittest.TestCase):
self
.
assertEqual
(
context
,
expected
)
self
.
assertEqual
(
context
,
expected
)
class
ChoiceGroupTest
(
unittest
.
TestCase
):
def
test_rendering
(
self
):
'''
xml_str
=
"""<optioninput options="('Up','Down')" id="sky_input" correct="Up"/>"""
Test choice groups.
'''
def
test_mult_choice
(
self
):
xml_str
=
"""
<choicegroup>
<choice correct="false" name="foil1">
<startouttext />This is foil One.<endouttext />
</choice>
<choice correct="false" name="foil2">
<startouttext />This is foil Two.<endouttext />
</choice>
<choice correct="true" name="foil3">
<startouttext />This is foil Three.<endouttext />
</choice>
<choice correct="false" name="foil4">
<startouttext />This is foil Four.<endouttext />
</choice>
<choice correct="false" name="foil5">
<startouttext />This is foil Five.<endouttext />
</choice>
</choicegroup>
"""
element
=
etree
.
fromstring
(
xml_str
)
element
=
etree
.
fromstring
(
xml_str
)
state
=
{
'value'
:
'Down'
,
state
=
{
'value'
:
'Down'
,
...
...
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