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
52c2f3ae
Commit
52c2f3ae
authored
Apr 17, 2013
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tested additional values of rerandomize (true/false/per_student)
Pylint fixes
parent
754d1eb7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
43 deletions
+93
-43
common/lib/capa/capa/tests/test_input_templates.py
+14
-21
common/lib/xmodule/xmodule/tests/test_capa_module.py
+79
-22
No files found.
common/lib/capa/capa/tests/test_input_templates.py
View file @
52c2f3ae
"""Tests for the logic in input type mako templates."""
#pylint: disable=R0904
import
unittest
import
capa
...
...
@@ -11,26 +10,22 @@ from mako.template import Template as MakoTemplate
class
TemplateTestCase
(
unittest
.
TestCase
):
"""Utilitites for testing templates"""
# Allow us to pass an extra arg to setUp to configure
# the test case. Also allow setUp as a valid method name.
#pylint: disable=W0221
#pylint: disable=C0103
def
setUp
(
self
,
template_name
):
"""Load the template
`template_name` is the file name of the template
to be loaded from capa/templates.
The template name should include the .html extension:
for example: choicegroup.html
"""
# Subclasses override this to specify the file name of the template
# to be loaded from capa/templates.
# The template name should include the .html extension:
# for example: choicegroup.html
TEMPLATE_NAME
=
None
def
setUp
(
self
):
"""Load the template"""
capa_path
=
capa
.
__path__
[
0
]
self
.
template_path
=
os
.
path
.
join
(
capa_path
,
'templates'
,
template_name
)
self
.
template_path
=
os
.
path
.
join
(
capa_path
,
'templates'
,
self
.
TEMPLATE_NAME
)
template_file
=
open
(
self
.
template_path
)
self
.
template
=
MakoTemplate
(
template_file
.
read
())
template_file
.
close
()
# Allow us to pass **context_dict to render_unicode()
#pylint: disable=W0142
def
render_to_xml
(
self
,
context_dict
):
"""Render the template using the `context_dict` dict.
...
...
@@ -65,10 +60,8 @@ class TemplateTestCase(unittest.TestCase):
class
TestChoiceGroupTemplate
(
TemplateTestCase
):
"""Test mako template for `<choicegroup>` input"""
# Allow us to pass an extra arg to setUp to configure
# the test case. Also allow setUp as a valid method name.
#pylint: disable=W0221
#pylint: disable=C0103
TEMPLATE_NAME
=
'choicegroup.html'
def
setUp
(
self
):
choices
=
[(
'1'
,
'choice 1'
),
(
'2'
,
'choice 2'
),
(
'3'
,
'choice 3'
)]
self
.
context
=
{
'id'
:
'1'
,
...
...
@@ -77,7 +70,7 @@ class TestChoiceGroupTemplate(TemplateTestCase):
'input_type'
:
'checkbox'
,
'name_array_suffix'
:
'1'
,
'value'
:
'3'
}
super
(
TestChoiceGroupTemplate
,
self
)
.
setUp
(
'choicegroup.html'
)
super
(
TestChoiceGroupTemplate
,
self
)
.
setUp
()
def
test_problem_marked_correct
(
self
):
"""Test conditions under which the entire problem
...
...
common/lib/xmodule/xmodule/tests/test_capa_module.py
View file @
52c2f3ae
"""Tests of the Capa XModule"""
#pylint: disable=C0111
#pylint: disable=R0904
#pylint: disable=C0103
#pylint: disable=C0302
import
datetime
import
json
from
mock
import
Mock
,
MagicMock
,
patch
from
pprint
import
pprint
from
mock
import
Mock
,
patch
import
unittest
import
random
import
xmodule
import
capa
from
capa.responsetypes
import
StudentInputError
,
\
LoncapaProblemError
,
ResponseError
from
xmodule.capa_module
import
CapaModule
from
xmodule.modulestore
import
Location
from
lxml
import
etree
from
django.http
import
QueryDict
...
...
@@ -384,7 +386,7 @@ class CapaModuleTest(unittest.TestCase):
# what the input is, by patching CorrectMap.is_correct()
# Also simulate rendering the HTML
# TODO: pep8 thinks the following line has invalid syntax
with
patch
(
'capa.correctmap.CorrectMap.is_correct'
)
as
mock_is_correct
,
\
with
patch
(
'capa.correctmap.CorrectMap.is_correct'
)
as
mock_is_correct
,
\
patch
(
'xmodule.capa_module.CapaModule.get_problem_html'
)
as
mock_html
:
mock_is_correct
.
return_value
=
True
mock_html
.
return_value
=
"Test HTML"
...
...
@@ -435,8 +437,11 @@ class CapaModuleTest(unittest.TestCase):
self
.
assertEqual
(
module
.
attempts
,
3
)
def
test_check_problem_resubmitted_with_randomize
(
self
):
rerandomize_values
=
[
'always'
,
'true'
]
for
rerandomize
in
rerandomize_values
:
# Randomize turned on
module
=
CapaFactory
.
create
(
rerandomize
=
'always'
,
attempts
=
0
)
module
=
CapaFactory
.
create
(
rerandomize
=
rerandomize
,
attempts
=
0
)
# Simulate that the problem is completed
module
.
done
=
True
...
...
@@ -450,8 +455,11 @@ class CapaModuleTest(unittest.TestCase):
self
.
assertEqual
(
module
.
attempts
,
0
)
def
test_check_problem_resubmitted_no_randomize
(
self
):
rerandomize_values
=
[
'never'
,
'false'
,
'per_student'
]
for
rerandomize
in
rerandomize_values
:
# Randomize turned off
module
=
CapaFactory
.
create
(
rerandomize
=
'never'
,
attempts
=
0
,
done
=
True
)
module
=
CapaFactory
.
create
(
rerandomize
=
rerandomize
,
attempts
=
0
,
done
=
True
)
# Expect that we can submit successfully
get_request_dict
=
{
CapaFactory
.
input_key
():
'3.14'
}
...
...
@@ -615,7 +623,12 @@ class CapaModuleTest(unittest.TestCase):
self
.
assertTrue
(
'success'
in
result
and
not
result
[
'success'
])
def
test_save_problem_submitted_with_randomize
(
self
):
module
=
CapaFactory
.
create
(
rerandomize
=
'always'
,
done
=
True
)
# Capa XModule treats 'always' and 'true' equivalently
rerandomize_values
=
[
'always'
,
'true'
]
for
rerandomize
in
rerandomize_values
:
module
=
CapaFactory
.
create
(
rerandomize
=
rerandomize
,
done
=
True
)
# Try to save
get_request_dict
=
{
CapaFactory
.
input_key
():
'3.14'
}
...
...
@@ -625,7 +638,12 @@ class CapaModuleTest(unittest.TestCase):
self
.
assertTrue
(
'success'
in
result
and
not
result
[
'success'
])
def
test_save_problem_submitted_no_randomize
(
self
):
module
=
CapaFactory
.
create
(
rerandomize
=
'never'
,
done
=
True
)
# Capa XModule treats 'false' and 'per_student' equivalently
rerandomize_values
=
[
'never'
,
'false'
,
'per_student'
]
for
rerandomize
in
rerandomize_values
:
module
=
CapaFactory
.
create
(
rerandomize
=
rerandomize
,
done
=
True
)
# Try to save
get_request_dict
=
{
CapaFactory
.
input_key
():
'3.14'
}
...
...
@@ -681,21 +699,30 @@ class CapaModuleTest(unittest.TestCase):
# If user submitted a problem but hasn't reset,
# do NOT show the check button
# Note: we can only reset when rerandomize="always"
# Note: we can only reset when rerandomize="always"
or "true"
module
=
CapaFactory
.
create
(
rerandomize
=
"always"
,
done
=
True
)
self
.
assertFalse
(
module
.
should_show_check_button
())
module
=
CapaFactory
.
create
(
rerandomize
=
"true"
,
done
=
True
)
self
.
assertFalse
(
module
.
should_show_check_button
())
# Otherwise, DO show the check button
module
=
CapaFactory
.
create
()
self
.
assertTrue
(
module
.
should_show_check_button
())
# If the user has submitted the problem
# and we do NOT have a reset button, then we can show the check button
# Setting rerandomize to "never" ensures that the reset button
# Setting rerandomize to "never"
or "false"
ensures that the reset button
# is not shown
module
=
CapaFactory
.
create
(
rerandomize
=
"never"
,
done
=
True
)
self
.
assertTrue
(
module
.
should_show_check_button
())
module
=
CapaFactory
.
create
(
rerandomize
=
"false"
,
done
=
True
)
self
.
assertTrue
(
module
.
should_show_check_button
())
module
=
CapaFactory
.
create
(
rerandomize
=
"per_student"
,
done
=
True
)
self
.
assertTrue
(
module
.
should_show_check_button
())
def
test_should_show_reset_button
(
self
):
attempts
=
random
.
randint
(
1
,
10
)
...
...
@@ -712,6 +739,14 @@ class CapaModuleTest(unittest.TestCase):
module
=
CapaFactory
.
create
(
rerandomize
=
"never"
,
done
=
True
)
self
.
assertFalse
(
module
.
should_show_reset_button
())
# If we're NOT randomizing, then do NOT show the reset button
module
=
CapaFactory
.
create
(
rerandomize
=
"per_student"
,
done
=
True
)
self
.
assertFalse
(
module
.
should_show_reset_button
())
# If we're NOT randomizing, then do NOT show the reset button
module
=
CapaFactory
.
create
(
rerandomize
=
"false"
,
done
=
True
)
self
.
assertFalse
(
module
.
should_show_reset_button
())
# If the user hasn't submitted an answer yet,
# then do NOT show the reset button
module
=
CapaFactory
.
create
(
done
=
False
)
...
...
@@ -742,13 +777,19 @@ class CapaModuleTest(unittest.TestCase):
module
=
CapaFactory
.
create
(
rerandomize
=
"always"
,
done
=
True
)
self
.
assertFalse
(
module
.
should_show_save_button
())
module
=
CapaFactory
.
create
(
rerandomize
=
"true"
,
done
=
True
)
self
.
assertFalse
(
module
.
should_show_save_button
())
# If the user has unlimited attempts and we are not randomizing,
# then do NOT show a save button
# because they can keep using "Check"
module
=
CapaFactory
.
create
(
max_attempts
=
None
,
rerandomize
=
"never"
,
done
=
False
)
self
.
assertFalse
(
module
.
should_show_save_button
())
module
=
CapaFactory
.
create
(
max_attempts
=
None
,
rerandomize
=
"never"
,
done
=
True
)
module
=
CapaFactory
.
create
(
max_attempts
=
None
,
rerandomize
=
"false"
,
done
=
True
)
self
.
assertFalse
(
module
.
should_show_save_button
())
module
=
CapaFactory
.
create
(
max_attempts
=
None
,
rerandomize
=
"per_student"
,
done
=
True
)
self
.
assertFalse
(
module
.
should_show_save_button
())
# Otherwise, DO show the save button
...
...
@@ -759,6 +800,12 @@ class CapaModuleTest(unittest.TestCase):
module
=
CapaFactory
.
create
(
rerandomize
=
"never"
,
max_attempts
=
2
,
done
=
True
)
self
.
assertTrue
(
module
.
should_show_save_button
())
module
=
CapaFactory
.
create
(
rerandomize
=
"false"
,
max_attempts
=
2
,
done
=
True
)
self
.
assertTrue
(
module
.
should_show_save_button
())
module
=
CapaFactory
.
create
(
rerandomize
=
"per_student"
,
max_attempts
=
2
,
done
=
True
)
self
.
assertTrue
(
module
.
should_show_save_button
())
# If survey question for capa (max_attempts = 0),
# DO show the save button
module
=
CapaFactory
.
create
(
max_attempts
=
0
,
done
=
False
)
...
...
@@ -788,9 +835,15 @@ class CapaModuleTest(unittest.TestCase):
done
=
True
)
self
.
assertTrue
(
module
.
should_show_save_button
())
module
=
CapaFactory
.
create
(
force_save_button
=
"true"
,
rerandomize
=
"true"
,
done
=
True
)
self
.
assertTrue
(
module
.
should_show_save_button
())
def
test_no_max_attempts
(
self
):
module
=
CapaFactory
.
create
(
max_attempts
=
''
)
html
=
module
.
get_problem_html
()
self
.
assertTrue
(
html
is
not
None
)
# assert that we got here without exploding
def
test_get_problem_html
(
self
):
...
...
@@ -875,6 +928,8 @@ class CapaModuleTest(unittest.TestCase):
# Try to render the module with DEBUG turned off
html
=
module
.
get_problem_html
()
self
.
assertTrue
(
html
is
not
None
)
# Check the rendering context
render_args
,
_
=
module
.
system
.
render_template
.
call_args
context
=
render_args
[
1
]
...
...
@@ -886,7 +941,9 @@ class CapaModuleTest(unittest.TestCase):
def
test_random_seed_no_change
(
self
):
# Run the test for each possible rerandomize value
for
rerandomize
in
[
'never'
,
'per_student'
,
'always'
,
'onreset'
]:
for
rerandomize
in
[
'false'
,
'never'
,
'per_student'
,
'always'
,
'true'
,
'onreset'
]:
module
=
CapaFactory
.
create
(
rerandomize
=
rerandomize
)
# Get the seed
...
...
@@ -896,8 +953,9 @@ class CapaModuleTest(unittest.TestCase):
# If we're not rerandomizing, the seed is always set
# to the same value (1)
if
rerandomize
==
'never'
:
self
.
assertEqual
(
seed
,
1
)
if
rerandomize
in
[
'never'
]:
self
.
assertEqual
(
seed
,
1
,
msg
=
"Seed should always be 1 when rerandomize='
%
s'"
%
rerandomize
)
# Check the problem
get_request_dict
=
{
CapaFactory
.
input_key
():
'3.14'
}
...
...
@@ -947,7 +1005,8 @@ class CapaModuleTest(unittest.TestCase):
return
success
# Run the test for each possible rerandomize value
for
rerandomize
in
[
'never'
,
'per_student'
,
'always'
,
'onreset'
]:
for
rerandomize
in
[
'never'
,
'false'
,
'per_student'
,
'always'
,
'true'
,
'onreset'
]:
module
=
CapaFactory
.
create
(
rerandomize
=
rerandomize
)
# Get the seed
...
...
@@ -959,7 +1018,7 @@ class CapaModuleTest(unittest.TestCase):
# is set to 'never' -- it should still be 1
# The seed also stays the same if we're randomizing
# 'per_student': the same student should see the same problem
if
rerandomize
in
[
'never'
,
'per_student'
]:
if
rerandomize
in
[
'never'
,
'
false'
,
'
per_student'
]:
self
.
assertEqual
(
seed
,
_reset_and_get_seed
(
module
))
# Otherwise, we expect the seed to change
...
...
@@ -969,10 +1028,8 @@ class CapaModuleTest(unittest.TestCase):
# Since there's a small chance we might get the
# same seed again, give it 5 chances
# to generate a different seed
success
=
_retry_and_check
(
5
,
lambda
:
_reset_and_get_seed
(
module
)
!=
seed
)
success
=
_retry_and_check
(
5
,
lambda
:
_reset_and_get_seed
(
module
)
!=
seed
)
# TODO: change this comparison to module.seed is not None?
self
.
assertTrue
(
module
.
seed
!=
None
)
self
.
assertTrue
(
module
.
seed
is
not
None
)
msg
=
'Could not get a new seed from reset after 5 tries'
self
.
assertTrue
(
success
,
msg
)
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