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
025b074b
Commit
025b074b
authored
Jan 20, 2013
by
Victor Shnayder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add simple test for showanswer, fix test_system
parent
e41172d5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
3 deletions
+59
-3
common/lib/xmodule/xmodule/tests/__init__.py
+1
-1
common/lib/xmodule/xmodule/tests/test_capa_module.py
+58
-2
No files found.
common/lib/xmodule/xmodule/tests/__init__.py
View file @
025b074b
...
...
@@ -26,7 +26,7 @@ test_system = ModuleSystem(
# "render" to just the context...
render_template
=
lambda
template
,
context
:
str
(
context
),
replace_urls
=
Mock
(),
user
=
Mock
(),
user
=
Mock
(
is_staff
=
False
),
filestore
=
Mock
(),
debug
=
True
,
xqueue
=
{
'interface'
:
None
,
'callback_url'
:
'/'
,
'default_queuename'
:
'testqueue'
,
'waittime'
:
10
},
...
...
common/lib/xmodule/xmodule/tests/test_capa_module.py
View file @
025b074b
import
json
from
mock
import
Mock
from
pprint
import
pprint
import
unittest
from
xmodule.capa_module
import
CapaModule
from
xmodule.modulestore
import
Location
from
lxml
import
etree
...
...
@@ -31,13 +33,59 @@ class CapaFactory(object):
return
CapaFactory
.
num
@staticmethod
def
create
():
def
create
(
graceperiod
=
None
,
due
=
None
,
max_attempts
=
None
,
showanswer
=
None
,
rerandomize
=
None
,
force_save_button
=
None
,
attempts
=
None
,
problem_state
=
None
,
):
"""
All parameters are optional, and are added to the created problem if specified.
Arguments:
graceperiod:
due:
max_attempts:
showanswer:
force_save_button:
rerandomize: all strings, as specified in the policy for the problem
problem_state: a dict to to be serialized into the instance_state of the
module.
attempts: also added to instance state. Should be a number.
"""
definition
=
{
'data'
:
CapaFactory
.
sample_problem_xml
,}
location
=
Location
([
"i4x"
,
"edX"
,
"capa_test"
,
"problem"
,
"SampleProblem{0}"
.
format
(
CapaFactory
.
next_num
())])
metadata
=
{}
if
graceperiod
is
not
None
:
metadata
[
'graceperiod'
]
=
graceperiod
if
due
is
not
None
:
metadata
[
'due'
]
=
due
if
max_attempts
is
not
None
:
metadata
[
'attempts'
]
=
max_attempts
if
showanswer
is
not
None
:
metadata
[
'showanswer'
]
=
showanswer
if
force_save_button
is
not
None
:
metadata
[
'force_save_button'
]
=
force_save_button
if
rerandomize
is
not
None
:
metadata
[
'rerandomize'
]
=
rerandomize
descriptor
=
Mock
(
weight
=
"1"
)
instance_state
=
None
instance_state_dict
=
{}
if
problem_state
is
not
None
:
instance_state_dict
=
problem_state
if
attempts
is
not
None
:
instance_state_dict
[
'attempts'
]
=
attempts
if
len
(
instance_state_dict
)
>
0
:
instance_state
=
json
.
dumps
(
instance_state_dict
)
else
:
instance_state
=
None
module
=
CapaModule
(
test_system
,
location
,
definition
,
descriptor
,
...
...
@@ -58,3 +106,11 @@ class CapaModuleTest(unittest.TestCase):
self
.
assertNotEqual
(
module
.
url_name
,
other_module
.
url_name
,
"Factory should be creating unique names for each problem"
)
def
test_showanswer
(
self
):
"""
Make sure the show answer logic does the right thing.
"""
# default, no due date, showanswer 'closed'
problem
=
CapaFactory
.
create
()
pprint
(
problem
.
__dict__
)
self
.
assertFalse
(
problem
.
answer_available
())
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