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
6e4c418a
Commit
6e4c418a
authored
Feb 27, 2013
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated JavscriptResponse to use XML factory
parent
3f81fe01
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
10 deletions
+62
-10
common/lib/capa/capa/tests/response_xml_factory.py
+48
-2
common/lib/capa/capa/tests/test_responsetypes.py
+14
-8
No files found.
common/lib/capa/capa/tests/response_xml_factory.py
View file @
6e4c418a
...
...
@@ -451,11 +451,57 @@ class ImageResponseXMLFactory(ResponseXMLFactory):
return
input_element
class
JavascriptResponseXMLFactory
(
ResponseXMLFactory
):
""" Factory for producing <javascriptresponse> XML """
def
create_response_element
(
self
,
**
kwargs
):
raise
NotImplemented
""" Create the <javascriptresponse> element.
Uses **kwargs:
*generator_src*: Name of the JS file to generate the problem.
*grader_src*: Name of the JS file to grade the problem.
*display_class*: Name of the class used to display the problem
*display_src*: Name of the JS file used to display the problem
*param_dict*: Dictionary of parameters to pass to the JS
"""
# Get **kwargs
generator_src
=
kwargs
.
get
(
"generator_src"
,
None
)
grader_src
=
kwargs
.
get
(
"grader_src"
,
None
)
display_class
=
kwargs
.
get
(
"display_class"
,
None
)
display_src
=
kwargs
.
get
(
"display_src"
,
None
)
param_dict
=
kwargs
.
get
(
"param_dict"
,
{})
# Both display_src and display_class given,
# or neither given
assert
((
display_src
and
display_class
)
or
(
not
display_src
and
not
display_class
))
# Create the <javascriptresponse> element
response_element
=
etree
.
Element
(
"javascriptresponse"
)
if
generator_src
:
generator_element
=
etree
.
SubElement
(
response_element
,
"generator"
)
generator_element
.
set
(
"src"
,
str
(
generator_src
))
if
grader_src
:
grader_element
=
etree
.
SubElement
(
response_element
,
"grader"
)
grader_element
.
set
(
"src"
,
str
(
grader_src
))
if
display_class
and
display_src
:
display_element
=
etree
.
SubElement
(
response_element
,
"display"
)
display_element
.
set
(
"class"
,
str
(
display_class
))
display_element
.
set
(
"src"
,
str
(
display_src
))
for
(
param_name
,
param_val
)
in
param_dict
.
items
():
responseparam_element
=
etree
.
SubElement
(
response_element
,
"responseparam"
)
responseparam_element
.
set
(
"name"
,
str
(
param_name
))
responseparam_element
.
set
(
"value"
,
str
(
param_val
))
return
response_element
def
create_input_element
(
self
,
**
kwargs
):
raise
NotImplemented
""" Create the <javascriptinput> element """
return
etree
.
Element
(
"javascriptinput"
)
class
MultipleChoiceResponseXMLFactory
(
ResponseXMLFactory
):
""" Factory for producing <multiplechoiceresponse> XML """
...
...
common/lib/capa/capa/tests/test_responsetypes.py
View file @
6e4c418a
...
...
@@ -574,18 +574,24 @@ class ChoiceResponseTest(ResponseTest):
self
.
assert_grade
(
problem
,
'choice_3'
,
'incorrect'
)
class
JavascriptResponseTest
(
unittest
.
TestCase
):
class
JavascriptResponseTest
(
ResponseTest
):
from
response_xml_factory
import
JavascriptResponseXMLFactory
xml_factory_class
=
JavascriptResponseXMLFactory
def
test_jr_grade
(
self
):
problem_file
=
os
.
path
.
dirname
(
__file__
)
+
"/test_files/javascriptresponse.xml"
def
test_grade
(
self
):
problem
=
self
.
build_problem
(
generator_src
=
"test_problem_generator.js"
,
grader_src
=
"test_problem_grader.js"
,
display_class
=
"TestProblemDisplay"
,
display_src
=
"test_problem_display.js"
,
param_dict
=
{
'value'
:
'4'
})
# Compile coffee files into javascript used by the response
coffee_file_path
=
os
.
path
.
dirname
(
__file__
)
+
"/test_files/js/*.coffee"
os
.
system
(
"coffee -c
%
s"
%
(
coffee_file_path
))
test_lcp
=
lcp
.
LoncapaProblem
(
open
(
problem_file
)
.
read
(),
'1'
,
system
=
test_system
)
correct_answers
=
{
'1_2_1'
:
json
.
dumps
({
0
:
4
})}
incorrect_answers
=
{
'1_2_1'
:
json
.
dumps
({
0
:
5
})}
self
.
assertEquals
(
test_lcp
.
grade_answers
(
incorrect_answers
)
.
get_correctness
(
'1_2_1'
),
'incorrect'
)
self
.
assertEquals
(
test_lcp
.
grade_answers
(
correct_answers
)
.
get_correctness
(
'1_2_1'
),
'correct'
)
# Test that we get graded correctly
self
.
assert_grade
(
problem
,
json
.
dumps
({
0
:
4
}),
"correct"
)
self
.
assert_grade
(
problem
,
json
.
dumps
({
0
:
5
}),
"incorrect"
)
class
NumericalResponseTest
(
ResponseTest
):
from
response_xml_factory
import
NumericalResponseXMLFactory
...
...
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