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
c8bc46b6
Commit
c8bc46b6
authored
Oct 24, 2012
by
Victor Shnayder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert FileSubmission input to be a class.
- add test
parent
c2682273
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
28 deletions
+79
-28
common/lib/capa/capa/inputtypes.py
+35
-27
common/lib/capa/capa/tests/test_inputtypes.py
+44
-1
No files found.
common/lib/capa/capa/inputtypes.py
View file @
c8bc46b6
...
...
@@ -448,36 +448,44 @@ class TextLine(InputTypeBase):
register_input_class
(
TextLine
)
#-----------------------------------------------------------------------------
def
filesubmission
(
element
,
value
,
status
,
render_template
,
msg
=
''
):
'''
Upload a single file (e.g. for programming assignments)
'''
eid
=
element
.
get
(
'id'
)
escapedict
=
{
'"'
:
'"'
}
allowed_files
=
json
.
dumps
(
element
.
get
(
'allowed_files'
,
''
)
.
split
())
allowed_files
=
saxutils
.
escape
(
allowed_files
,
escapedict
)
required_files
=
json
.
dumps
(
element
.
get
(
'required_files'
,
''
)
.
split
())
required_files
=
saxutils
.
escape
(
required_files
,
escapedict
)
# Check if problem has been queued
queue_len
=
0
# Flag indicating that the problem has been queued, 'msg' is length of queue
if
status
==
'incomplete'
:
status
=
'queued'
queue_len
=
msg
msg
=
'Submitted to grader.'
class
FileSubmission
(
InputTypeBase
):
"""
Upload some files (e.g. for programming assignments)
"""
context
=
{
'id'
:
eid
,
'state'
:
status
,
'msg'
:
msg
,
'value'
:
value
,
'queue_len'
:
queue_len
,
'allowed_files'
:
allowed_files
,
'required_files'
:
required_files
,}
html
=
render_template
(
"filesubmission.html"
,
context
)
return
etree
.
XML
(
html
)
template
=
"filesubmission.html"
tags
=
[
'filesubmission'
]
def
__init__
(
self
,
system
,
xml
,
state
):
super
(
FileSubmission
,
self
)
.
__init__
(
system
,
xml
,
state
)
escapedict
=
{
'"'
:
'"'
}
self
.
allowed_files
=
json
.
dumps
(
xml
.
get
(
'allowed_files'
,
''
)
.
split
())
self
.
allowed_files
=
saxutils
.
escape
(
self
.
allowed_files
,
escapedict
)
self
.
required_files
=
json
.
dumps
(
xml
.
get
(
'required_files'
,
''
)
.
split
())
self
.
required_files
=
saxutils
.
escape
(
self
.
required_files
,
escapedict
)
# Check if problem has been queued
queue_len
=
0
# Flag indicating that the problem has been queued, 'msg' is length of queue
if
self
.
status
==
'incomplete'
:
self
.
status
=
'queued'
self
.
queue_len
=
self
.
msg
self
.
msg
=
'Submitted to grader.'
def
_get_render_context
(
self
):
context
=
{
'id'
:
self
.
id
,
'state'
:
self
.
status
,
'msg'
:
self
.
msg
,
'value'
:
self
.
value
,
'queue_len'
:
self
.
queue_len
,
'allowed_files'
:
self
.
allowed_files
,
'required_files'
:
self
.
required_files
,}
return
context
_reg
(
files
ubmission
)
register_input_class
(
FileS
ubmission
)
#-----------------------------------------------------------------------------
...
...
common/lib/capa/capa/tests/test_inputtypes.py
View file @
c8bc46b6
...
...
@@ -24,6 +24,9 @@ def tst_render_template(template, context):
system
=
Mock
(
render_template
=
tst_render_template
)
def
quote_attr
(
s
):
return
saxutils
.
quoteattr
(
s
)[
1
:
-
1
]
# don't want the outer quotes
class
OptionInputTest
(
unittest
.
TestCase
):
'''
Make sure option inputs work
...
...
@@ -150,7 +153,7 @@ class JavascriptInputTest(unittest.TestCase):
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
ps
=
quote_attr
(
problem_state
),
dc
=
display_class
,
df
=
display_file
)
element
=
etree
.
fromstring
(
xml_str
)
...
...
@@ -226,3 +229,43 @@ class TextLineTest(unittest.TestCase):
'preprocessor'
:
{
'class_name'
:
preprocessorClass
,
'script_src'
:
script
}}
self
.
assertEqual
(
context
,
expected
)
class
FileSubmissionTest
(
unittest
.
TestCase
):
'''
Check that file submission inputs work
'''
def
test_rendering
(
self
):
allowed_files
=
"runme.py nooooo.rb ohai.java"
required_files
=
"cookies.py"
xml_str
=
"""<filesubmission id="prob_1_2"
allowed_files="{af}"
required_files="{rf}"
/>"""
.
format
(
af
=
allowed_files
,
rf
=
required_files
,)
element
=
etree
.
fromstring
(
xml_str
)
escapedict
=
{
'"'
:
'"'
}
esc
=
lambda
s
:
saxutils
.
escape
(
s
,
escapedict
)
state
=
{
'value'
:
'BumbleBee.py'
,
'status'
:
'incomplete'
,
'feedback'
:
{
'message'
:
'3'
},
}
the_input
=
inputtypes
.
get_class_for_tag
(
'filesubmission'
)(
system
,
element
,
state
)
context
=
the_input
.
_get_render_context
()
expected
=
{
'id'
:
'prob_1_2'
,
'state'
:
'queued'
,
'msg'
:
'Submitted to grader.'
,
'value'
:
'BumbleBee.py'
,
'queue_len'
:
'3'
,
'allowed_files'
:
esc
(
'["runme.py", "nooooo.rb", "ohai.java"]'
),
'required_files'
:
esc
(
'["cookies.py"]'
)}
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