Commit 4b4e4f26 by Awais Jibran Committed by GitHub

Merge pull request #16319 from edx/aj/fix-capa-show-answer

Fix Show Answer button display for the value "Answered" in studio
parents 2c80b1b4 fe5a8de5
......@@ -906,7 +906,7 @@ class CapaMixin(ScorableXBlockMixin, CapaFields):
elif self.showanswer == SHOWANSWER.ANSWERED:
# NOTE: this is slightly different from 'attempted' -- resetting the problems
# makes lcp.done False, but leaves attempts unchanged.
return self.lcp.done
return self.is_correct()
elif self.showanswer == SHOWANSWER.CLOSED:
return self.closed()
elif self.showanswer == SHOWANSWER.FINISHED:
......
......@@ -35,7 +35,7 @@ from xblock.scorable import Score
from . import get_test_system
from pytz import UTC
from capa.correctmap import CorrectMap
from ..capa_base_constants import RANDOMIZATION
from ..capa_base_constants import RANDOMIZATION, SHOWANSWER
class CapaFactory(object):
......@@ -458,6 +458,31 @@ class CapaModuleTest(unittest.TestCase):
graceperiod=self.two_day_delta_str)
self.assertTrue(still_in_grace.answer_available())
def test_showanswer_answered(self):
"""
Tests that with showanswer="answered" should show answer after the problem is correctly answered.
It should *NOT* show answer if the answer is incorrect.
"""
# Can not see "Show Answer" when student answer is wrong
answer_wrong = CapaFactory.create(
showanswer=SHOWANSWER.ANSWERED,
max_attempts="1",
attempts="0",
due=self.tomorrow_str,
correct=False
)
self.assertFalse(answer_wrong.answer_available())
# Expect to see "Show Answer" when answer is correct
answer_correct = CapaFactory.create(
showanswer=SHOWANSWER.ANSWERED,
max_attempts="1",
attempts="0",
due=self.tomorrow_str,
correct=True
)
self.assertTrue(answer_correct.answer_available())
@ddt.data('', 'other-value')
def test_show_correctness_other(self, show_correctness):
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment