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
a9d68c32
Commit
a9d68c32
authored
Oct 12, 2017
by
AsadAzam
Committed by
GitHub
Oct 12, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #16160 from edx/asad/educator-1427-problem-rescore
Fixed score update on rescore
parents
4feb57d0
cde6f4b7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
7 deletions
+44
-7
common/lib/xmodule/xmodule/capa_base.py
+6
-6
common/lib/xmodule/xmodule/tests/test_capa_module.py
+38
-1
No files found.
common/lib/xmodule/xmodule/capa_base.py
View file @
a9d68c32
...
@@ -1126,16 +1126,18 @@ class CapaMixin(ScorableXBlockMixin, CapaFields):
...
@@ -1126,16 +1126,18 @@ class CapaMixin(ScorableXBlockMixin, CapaFields):
return
answers
return
answers
def
publish_grade
(
self
,
only_if_higher
=
None
):
def
publish_grade
(
self
,
score
=
None
,
only_if_higher
=
None
):
"""
"""
Publishes the student's current grade to the system as an event
Publishes the student's current grade to the system as an event
"""
"""
if
not
score
:
score
=
self
.
score
self
.
runtime
.
publish
(
self
.
runtime
.
publish
(
self
,
self
,
'grade'
,
'grade'
,
{
{
'value'
:
s
elf
.
s
core
.
raw_earned
,
'value'
:
score
.
raw_earned
,
'max_value'
:
s
elf
.
s
core
.
raw_possible
,
'max_value'
:
score
.
raw_possible
,
'only_if_higher'
:
only_if_higher
,
'only_if_higher'
:
only_if_higher
,
}
}
)
)
...
@@ -1615,7 +1617,6 @@ class CapaMixin(ScorableXBlockMixin, CapaFields):
...
@@ -1615,7 +1617,6 @@ class CapaMixin(ScorableXBlockMixin, CapaFields):
orig_score
=
self
.
get_score
()
orig_score
=
self
.
get_score
()
event_info
[
'orig_score'
]
=
orig_score
.
raw_earned
event_info
[
'orig_score'
]
=
orig_score
.
raw_earned
event_info
[
'orig_total'
]
=
orig_score
.
raw_possible
event_info
[
'orig_total'
]
=
orig_score
.
raw_possible
try
:
try
:
calculated_score
=
self
.
calculate_score
()
calculated_score
=
self
.
calculate_score
()
...
@@ -1633,8 +1634,7 @@ class CapaMixin(ScorableXBlockMixin, CapaFields):
...
@@ -1633,8 +1634,7 @@ class CapaMixin(ScorableXBlockMixin, CapaFields):
# rescoring should have no effect on attempts, so don't
# rescoring should have no effect on attempts, so don't
# need to increment here, or mark done. Just save.
# need to increment here, or mark done. Just save.
self
.
set_state_from_lcp
()
self
.
set_state_from_lcp
()
self
.
set_score
(
calculated_score
)
self
.
publish_grade
(
score
=
calculated_score
,
only_if_higher
=
only_if_higher
)
self
.
publish_grade
(
only_if_higher
)
event_info
[
'new_score'
]
=
calculated_score
.
raw_earned
event_info
[
'new_score'
]
=
calculated_score
.
raw_earned
event_info
[
'new_total'
]
=
calculated_score
.
raw_possible
event_info
[
'new_total'
]
=
calculated_score
.
raw_possible
...
...
common/lib/xmodule/xmodule/tests/test_capa_module.py
View file @
a9d68c32
...
@@ -1043,7 +1043,7 @@ class CapaModuleTest(unittest.TestCase):
...
@@ -1043,7 +1043,7 @@ class CapaModuleTest(unittest.TestCase):
def
test_rescore_problem_correct
(
self
):
def
test_rescore_problem_correct
(
self
):
module
=
CapaFactory
.
create
(
attempts
=
1
,
done
=
True
)
module
=
CapaFactory
.
create
(
attempts
=
0
,
done
=
True
)
# Simulate that all answers are marked correct, no matter
# Simulate that all answers are marked correct, no matter
# what the input is, by patching LoncapaResponse.evaluate_answers()
# what the input is, by patching LoncapaResponse.evaluate_answers()
...
@@ -1053,6 +1053,12 @@ class CapaModuleTest(unittest.TestCase):
...
@@ -1053,6 +1053,12 @@ class CapaModuleTest(unittest.TestCase):
correctness
=
'correct'
,
correctness
=
'correct'
,
npoints
=
1
,
npoints
=
1
,
)
)
with
patch
(
'capa.correctmap.CorrectMap.is_correct'
)
as
mock_is_correct
:
mock_is_correct
.
return_value
=
True
# Check the problem
get_request_dict
=
{
CapaFactory
.
input_key
():
'1'
}
module
.
submit_problem
(
get_request_dict
)
module
.
rescore
(
only_if_higher
=
False
)
module
.
rescore
(
only_if_higher
=
False
)
# Expect that the problem is marked correct
# Expect that the problem is marked correct
...
@@ -1061,6 +1067,37 @@ class CapaModuleTest(unittest.TestCase):
...
@@ -1061,6 +1067,37 @@ 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_rescore_problem_additional_correct
(
self
):
# make sure it also works when new correct answer has been added
module
=
CapaFactory
.
create
(
attempts
=
0
)
# Simulate that all answers are marked correct, no matter
# what the input is, by patching CorrectMap.is_correct()
with
patch
(
'capa.correctmap.CorrectMap.is_correct'
)
as
mock_is_correct
:
mock_is_correct
.
return_value
=
True
# Check the problem
get_request_dict
=
{
CapaFactory
.
input_key
():
'1'
}
result
=
module
.
submit_problem
(
get_request_dict
)
# Expect that the problem is marked correct
self
.
assertEqual
(
result
[
'success'
],
'correct'
)
# Expect that the number of attempts is incremented
self
.
assertEqual
(
module
.
attempts
,
1
)
self
.
assertEqual
(
module
.
get_score
(),
(
1
,
1
))
# Simulate that after adding a new correct answer the new calculated score is (0,1)
# by patching CapaMixin.calculate_score()
# In case of rescore with only_if_higher=True it should not update score of module
# if previous score was higher
with
patch
(
'xmodule.capa_base.CapaMixin.calculate_score'
)
as
mock_calculate_score
:
mock_calculate_score
.
return_value
=
Score
(
raw_earned
=
0
,
raw_possible
=
1
)
module
.
rescore
(
only_if_higher
=
True
)
self
.
assertEqual
(
module
.
get_score
(),
(
1
,
1
))
# Expect that the number of attempts is not incremented
self
.
assertEqual
(
module
.
attempts
,
1
)
def
test_rescore_problem_incorrect
(
self
):
def
test_rescore_problem_incorrect
(
self
):
# make sure it also works when attempts have been reset,
# make sure it also works when attempts have been reset,
# so add this to the test:
# so add this to the test:
...
...
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