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
42043d2c
Commit
42043d2c
authored
Mar 05, 2013
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests for capa module save_problem()
parent
6ec3b94d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
6 deletions
+56
-6
common/lib/xmodule/xmodule/tests/test_capa_module.py
+56
-6
No files found.
common/lib/xmodule/xmodule/tests/test_capa_module.py
View file @
42043d2c
...
@@ -38,8 +38,12 @@ class CapaFactory(object):
...
@@ -38,8 +38,12 @@ class CapaFactory(object):
@staticmethod
@staticmethod
def
input_key
():
def
input_key
():
""" Return the input key to use when passing GET parameters """
""" Return the input key to use when passing GET parameters """
return
(
"input_"
+
return
(
"input_"
+
CapaFactory
.
answer_key
())
"-"
.
join
([
'i4x'
,
'edX'
,
'capa_test'
,
'problem'
,
@staticmethod
def
answer_key
():
""" Return the key stored in the capa problem answer dict """
return
(
"-"
.
join
([
'i4x'
,
'edX'
,
'capa_test'
,
'problem'
,
'SampleProblem
%
d'
%
CapaFactory
.
num
])
+
'SampleProblem
%
d'
%
CapaFactory
.
num
])
+
"_2_1"
)
"_2_1"
)
...
@@ -555,16 +559,62 @@ class CapaModuleTest(unittest.TestCase):
...
@@ -555,16 +559,62 @@ class CapaModuleTest(unittest.TestCase):
def
test_save_problem
(
self
):
def
test_save_problem
(
self
):
module
=
CapaFactory
.
create
()
module
=
CapaFactory
.
create
()
# Simulate
# Simulate that the problem is not done (not attempted or reset)
module
.
lcp
.
done
=
False
# Save the problem
get_request_dict
=
{
CapaFactory
.
input_key
():
'3.14'
}
result
=
module
.
save_problem
(
get_request_dict
)
# Expect that answers are saved to the problem
expected_answers
=
{
CapaFactory
.
answer_key
():
'3.14'
}
self
.
assertEqual
(
module
.
lcp
.
student_answers
,
expected_answers
)
# Expect that the result is success
self
.
assertTrue
(
'success'
in
result
and
result
[
'success'
])
def
test_save_problem_closed
(
self
):
def
test_save_problem_closed
(
self
):
self
.
fail
()
module
=
CapaFactory
.
create
()
# Simulate that the problem is NOT done (not attempted or reset)
module
.
lcp
.
done
=
False
# Simulate that the problem is closed
with
patch
(
'xmodule.capa_module.CapaModule.closed'
)
as
mock_closed
:
mock_closed
.
return_value
=
True
# Try to save the problem
get_request_dict
=
{
CapaFactory
.
input_key
():
'3.14'
}
result
=
module
.
save_problem
(
get_request_dict
)
# Expect that the result is failure
self
.
assertTrue
(
'success'
in
result
and
not
result
[
'success'
])
def
test_save_problem_submitted_with_randomize
(
self
):
def
test_save_problem_submitted_with_randomize
(
self
):
self
.
fail
()
module
=
CapaFactory
.
create
(
rerandomize
=
'always'
)
# Simulate that the problem is completed
module
.
lcp
.
done
=
True
# Try to save
get_request_dict
=
{
CapaFactory
.
input_key
():
'3.14'
}
result
=
module
.
save_problem
(
get_request_dict
)
# Expect that we cannot save
self
.
assertTrue
(
'success'
in
result
and
not
result
[
'success'
])
def
test_save_problem_submitted_no_randomize
(
self
):
def
test_save_problem_submitted_no_randomize
(
self
):
self
.
fail
()
module
=
CapaFactory
.
create
(
rerandomize
=
'never'
)
# Simulate that the problem is completed
module
.
lcp
.
done
=
True
# Try to save
get_request_dict
=
{
CapaFactory
.
input_key
():
'3.14'
}
result
=
module
.
save_problem
(
get_request_dict
)
# Expect that we succeed
self
.
assertTrue
(
'success'
in
result
and
result
[
'success'
])
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