From a428c0816815300e5da2eeeaab03e354f9cc516c Mon Sep 17 00:00:00 2001 From: Awais Jibran Date: Tue, 24 Oct 2017 15:32:45 +0500 Subject: [PATCH] Fix Show Answer button display for the value "Answered" in studio In docs it is explained that we should show "Show Answer" button for "Answered" value when the user has correctly submitted the answer. The current behavior is such, even if the learner has answered the question wrong, the "Show Answer" button would be available. EDUCATOR-1563 --- common/lib/xmodule/xmodule/capa_base.py | 2 +- .../xmodule/xmodule/tests/test_capa_module.py | 23 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/common/lib/xmodule/xmodule/capa_base.py b/common/lib/xmodule/xmodule/capa_base.py index bbd3c47cb0..0a95bbff74 100644 --- a/common/lib/xmodule/xmodule/capa_base.py +++ b/common/lib/xmodule/xmodule/capa_base.py @@ -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: diff --git a/common/lib/xmodule/xmodule/tests/test_capa_module.py b/common/lib/xmodule/xmodule/tests/test_capa_module.py index 1ee76b179e..ec4e58ff82 100644 --- a/common/lib/xmodule/xmodule/tests/test_capa_module.py +++ b/common/lib/xmodule/xmodule/tests/test_capa_module.py @@ -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,27 @@ class CapaModuleTest(unittest.TestCase): graceperiod=self.two_day_delta_str) self.assertTrue(still_in_grace.answer_available()) + def test_showanswer_answered(self): + answer_wrong = CapaFactory.create( + showanswer=SHOWANSWER.ANSWERED, + max_attempts="1", + attempts="0", + due=self.tomorrow_str, + correct=False + ) + self.assertFalse(answer_wrong.answer_available()) + + + 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): """