From dce5bbc03912f74eef3e9550c7a722062dc2c076 Mon Sep 17 00:00:00 2001 From: Ayub-Khan Date: Tue, 29 Dec 2015 19:20:18 +0500 Subject: [PATCH] fix TNL-767 When students click "check" without submitting an answer, our basic problem types respond in inconsistent ways. --- common/lib/capa/capa/responsetypes.py | 4 ++++ common/lib/capa/capa/tests/test_responsetypes.py | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py index 14f5069a0b..1debcad404 100644 --- a/common/lib/capa/capa/responsetypes.py +++ b/common/lib/capa/capa/responsetypes.py @@ -2134,6 +2134,10 @@ class StringResponse(LoncapaResponse): Note: for old code, which supports _or_ separator, we add some backward compatibility handling. Should be removed soon. When to remove it, is up to Lyla Fisher. """ + # if given answer is empty. + if not given: + return False + _ = self.capa_system.i18n.ugettext # backward compatibility, should be removed in future. if self.backward: diff --git a/common/lib/capa/capa/tests/test_responsetypes.py b/common/lib/capa/capa/tests/test_responsetypes.py index a3a91e440f..b2aba17957 100644 --- a/common/lib/capa/capa/tests/test_responsetypes.py +++ b/common/lib/capa/capa/tests/test_responsetypes.py @@ -946,6 +946,13 @@ class StringResponseTest(ResponseTest): # pylint: disable=missing-docstring hint = correct_map.get_hint('1_2_1') self.assertEqual(hint, self._get_random_number_result(problem.seed)) + def test_empty_answer_graded_as_incorrect(self): + """ + Tests that problem should be graded incorrect if blank space is chosen as answer + """ + problem = self.build_problem(answer=" ", case_sensitive=False, regexp=True) + self.assert_grade(problem, u" ", "incorrect") + class CodeResponseTest(ResponseTest): # pylint: disable=missing-docstring xml_factory_class = CodeResponseXMLFactory