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
21af0493
Commit
21af0493
authored
Mar 05, 2013
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added unit tests for capa_module reset_problem()
parent
9743f6be
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
3 deletions
+66
-3
common/lib/xmodule/xmodule/capa_module.py
+8
-2
common/lib/xmodule/xmodule/tests/test_capa_module.py
+58
-1
No files found.
common/lib/xmodule/xmodule/capa_module.py
View file @
21af0493
...
@@ -703,7 +703,12 @@ class CapaModule(XModule):
...
@@ -703,7 +703,12 @@ class CapaModule(XModule):
''' Changes problem state to unfinished -- removes student answers,
''' Changes problem state to unfinished -- removes student answers,
and causes problem to rerender itself.
and causes problem to rerender itself.
Returns problem html as { 'html' : html-string }.
Returns a dictionary of the form:
{'success': True/False,
'html': Problem HTML string }
If an error occurs, the dictionary will also have an
'error' key containing an error message.
'''
'''
event_info
=
dict
()
event_info
=
dict
()
event_info
[
'old_state'
]
=
self
.
lcp
.
get_state
()
event_info
[
'old_state'
]
=
self
.
lcp
.
get_state
()
...
@@ -734,7 +739,8 @@ class CapaModule(XModule):
...
@@ -734,7 +739,8 @@ class CapaModule(XModule):
event_info
[
'new_state'
]
=
self
.
lcp
.
get_state
()
event_info
[
'new_state'
]
=
self
.
lcp
.
get_state
()
self
.
system
.
track_function
(
'reset_problem'
,
event_info
)
self
.
system
.
track_function
(
'reset_problem'
,
event_info
)
return
{
'html'
:
self
.
get_problem_html
(
encapsulate
=
False
)}
return
{
'success'
:
True
,
'html'
:
self
.
get_problem_html
(
encapsulate
=
False
)}
class
CapaDescriptor
(
RawDescriptor
):
class
CapaDescriptor
(
RawDescriptor
):
...
...
common/lib/xmodule/xmodule/tests/test_capa_module.py
View file @
21af0493
import
datetime
import
datetime
import
json
import
json
from
mock
import
Mock
,
patch
from
mock
import
Mock
,
MagicMock
,
patch
from
pprint
import
pprint
from
pprint
import
pprint
import
unittest
import
unittest
...
@@ -465,3 +465,60 @@ class CapaModuleTest(unittest.TestCase):
...
@@ -465,3 +465,60 @@ class CapaModuleTest(unittest.TestCase):
# Expect that the number of attempts is NOT incremented
# Expect that the number of attempts is NOT incremented
self
.
assertEqual
(
module
.
attempts
,
1
)
self
.
assertEqual
(
module
.
attempts
,
1
)
def
test_reset_problem
(
self
):
module
=
CapaFactory
.
create
()
# Mock the module's capa problem
# to simulate that the problem is done
mock_problem
=
MagicMock
(
capa
.
capa_problem
.
LoncapaProblem
)
mock_problem
.
done
=
True
module
.
lcp
=
mock_problem
# Stub out HTML rendering
with
patch
(
'xmodule.capa_module.CapaModule.get_problem_html'
)
as
mock_html
:
mock_html
.
return_value
=
"<div>Test HTML</div>"
# Reset the problem
get_request_dict
=
{}
result
=
module
.
reset_problem
(
get_request_dict
)
# Expect that the request was successful
self
.
assertTrue
(
'success'
in
result
and
result
[
'success'
])
# Expect that the problem HTML is retrieved
self
.
assertTrue
(
'html'
in
result
)
self
.
assertEqual
(
result
[
'html'
],
"<div>Test HTML</div>"
)
# Expect that the problem was reset
mock_problem
.
do_reset
.
assert_called_once_with
()
def
test_reset_problem_closed
(
self
):
module
=
CapaFactory
.
create
()
# Simulate that the problem is closed
with
patch
(
'xmodule.capa_module.CapaModule.closed'
)
as
mock_closed
:
mock_closed
.
return_value
=
True
# Try to reset the problem
get_request_dict
=
{}
result
=
module
.
reset_problem
(
get_request_dict
)
# Expect that the problem was NOT reset
self
.
assertTrue
(
'success'
in
result
and
not
result
[
'success'
])
def
test_reset_problem_not_done
(
self
):
module
=
CapaFactory
.
create
()
# Simulate that the problem is NOT done
module
.
lcp
.
done
=
False
# Try to reset the problem
get_request_dict
=
{}
result
=
module
.
reset_problem
(
get_request_dict
)
# Expect that the problem was NOT reset
self
.
assertTrue
(
'success'
in
result
and
not
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