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
d0a9b231
Commit
d0a9b231
authored
Oct 24, 2012
by
Victor Shnayder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Turn javascriptinput into a class, add tests
parent
009d6c2e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
25 deletions
+70
-25
common/lib/capa/capa/inputtypes.py
+31
-24
common/lib/capa/capa/tests/test_inputtypes.py
+39
-1
No files found.
common/lib/capa/capa/inputtypes.py
View file @
d0a9b231
...
...
@@ -318,7 +318,7 @@ def extract_choices(element):
choices
.
append
((
choice
.
get
(
"name"
),
choice_text
))
return
choices
register_input_class
(
ChoiceGroup
)
...
...
@@ -326,37 +326,44 @@ register_input_class(ChoiceGroup)
#-----------------------------------------------------------------------------
def
javascriptinput
(
element
,
value
,
status
,
render_template
,
msg
=
'null'
):
'''
class
JavascriptInput
(
InputTypeBase
):
"""
Hidden field for javascript to communicate via; also loads the required
scripts for rendering the problem and passes data to the problem.
'''
eid
=
element
.
get
(
'id'
)
params
=
element
.
get
(
'params'
)
problem_state
=
element
.
get
(
'problem_state'
)
display_class
=
element
.
get
(
'display_class'
)
display_file
=
element
.
get
(
'display_file'
)
"""
# Need to provide a value that JSON can parse if there is no
# student-supplied value yet.
if
value
==
""
:
value
=
'null'
template
=
"javascriptinput.html"
tags
=
[
'javascriptinput'
]
escapedict
=
{
'"'
:
'"'
}
value
=
saxutils
.
escape
(
value
,
escapedict
)
msg
=
saxutils
.
escape
(
msg
,
escapedict
)
context
=
{
'id'
:
eid
,
'params'
:
params
,
'display_file'
:
display_file
,
'display_class'
:
display_class
,
'problem_state'
:
problem_state
,
def
__init__
(
self
,
system
,
xml
,
state
):
super
(
JavascriptInput
,
self
)
.
__init__
(
system
,
xml
,
state
)
# Need to provide a value that JSON can parse if there is no
# student-supplied value yet.
if
self
.
value
==
""
:
self
.
value
=
'null'
self
.
params
=
self
.
xml
.
get
(
'params'
)
self
.
problem_state
=
self
.
xml
.
get
(
'problem_state'
)
self
.
display_class
=
self
.
xml
.
get
(
'display_class'
)
self
.
display_file
=
self
.
xml
.
get
(
'display_file'
)
def
_get_render_context
(
self
):
escapedict
=
{
'"'
:
'"'
}
value
=
saxutils
.
escape
(
self
.
value
,
escapedict
)
msg
=
saxutils
.
escape
(
self
.
msg
,
escapedict
)
context
=
{
'id'
:
self
.
id
,
'params'
:
self
.
params
,
'display_file'
:
self
.
display_file
,
'display_class'
:
self
.
display_class
,
'problem_state'
:
self
.
problem_state
,
'value'
:
value
,
'evaluation'
:
msg
,
}
html
=
render_template
(
"javascriptinput.html"
,
context
)
return
etree
.
XML
(
html
)
return
context
_reg
(
javascripti
nput
)
register_input_class
(
JavascriptI
nput
)
def
textline
(
element
,
value
,
status
,
render_template
,
msg
=
""
):
...
...
common/lib/capa/capa/tests/test_inputtypes.py
View file @
d0a9b231
...
...
@@ -8,6 +8,7 @@ from mock import Mock
from
nose.plugins.skip
import
SkipTest
import
os
import
unittest
import
xml.sax.saxutils
as
saxutils
from
.
import
test_system
from
capa
import
inputtypes
...
...
@@ -128,6 +129,43 @@ class ChoiceGroupTest(unittest.TestCase):
def
test_radiogroup
(
self
):
self
.
check_group
(
'radiogroup'
,
'radio'
,
'[]'
)
def
test_checkboxgroup
(
self
):
self
.
check_group
(
'checkboxgroup'
,
'checkbox'
,
'[]'
)
class
JavascriptInputTest
(
unittest
.
TestCase
):
'''
The javascript input is a pretty straightforward pass-thru, but test it anyway
'''
def
test_rendering
(
self
):
params
=
"(1,2,3)"
problem_state
=
"abc12',12&hi<there>"
display_class
=
"a_class"
display_file
=
"my_files/hi.js"
xml_str
=
"""<javascriptinput id="prob_1_2" params="{params}" problem_state="{ps}"
display_class="{dc}" display_file="{df}"/>"""
.
format
(
params
=
params
,
ps
=
saxutils
.
quoteattr
(
problem_state
)[
1
:
-
1
],
# don't want the outer quotes
dc
=
display_class
,
df
=
display_file
)
element
=
etree
.
fromstring
(
xml_str
)
state
=
{
'value'
:
'3'
,}
the_input
=
inputtypes
.
get_class_for_tag
(
'javascriptinput'
)(
system
,
element
,
state
)
context
=
the_input
.
_get_render_context
()
expected
=
{
'id'
:
'prob_1_2'
,
'params'
:
params
,
'display_file'
:
display_file
,
'display_class'
:
display_class
,
'problem_state'
:
problem_state
,
'value'
:
'3'
,
'evaluation'
:
''
,}
self
.
assertEqual
(
context
,
expected
)
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