From 29864eeacf949baae6e3ed87b588dd3cf00abbcc Mon Sep 17 00:00:00 2001 From: Hamza Munir Date: Wed, 22 Jun 2016 16:57:04 +0500 Subject: [PATCH 1/2] TNL 4141 Problem was when we added a problem with empty string as an answer it created the problem instead of throwing an excpetion A test added to check that and exception is thrown when a problem is being created with empty string as an answer. A test is removed which used to test that problem should be graded incorrect if blank space is chosen as answer. --- common/lib/capa/capa/responsetypes.py | 5 ++++- common/lib/capa/capa/tests/test_responsetypes.py | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py index b55744baef..b572069000 100644 --- a/common/lib/capa/capa/responsetypes.py +++ b/common/lib/capa/capa/responsetypes.py @@ -189,7 +189,10 @@ class LoncapaResponse(object): raise LoncapaProblemError(msg) for prop in self.required_attributes: - if not xml.get(prop): + prop_value = xml.get(prop) + if prop_value and isinstance(prop_value, str): + prop_value = prop_value.strip() + if not prop_value: msg = "Error in problem specification: %s missing required attribute %s" % ( unicode(self), prop) msg += "\nSee XML source line %s" % getattr( diff --git a/common/lib/capa/capa/tests/test_responsetypes.py b/common/lib/capa/capa/tests/test_responsetypes.py index adbbe88f8c..ec4ba13b6e 100644 --- a/common/lib/capa/capa/tests/test_responsetypes.py +++ b/common/lib/capa/capa/tests/test_responsetypes.py @@ -946,12 +946,12 @@ 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): + def test_empty_answer_problem_creation_not_allowed(self): """ - Tests that problem should be graded incorrect if blank space is chosen as answer + Tests that empty answer string is not allowed to create a problem """ - problem = self.build_problem(answer=" ", case_sensitive=False, regexp=True) - self.assert_grade(problem, u" ", "incorrect") + with self.assertRaises(LoncapaProblemError): + self.build_problem(answer=" ", case_sensitive=False, regexp=True) class CodeResponseTest(ResponseTest): # pylint: disable=missing-docstring From 8f329a70da5fcc790fbacfeaff41b6b2325da021 Mon Sep 17 00:00:00 2001 From: Hamza Munir Date: Mon, 27 Jun 2016 14:41:05 +0500 Subject: [PATCH 2/2] removed the check if it is a string --- common/lib/capa/capa/responsetypes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py index b572069000..51a18ba886 100644 --- a/common/lib/capa/capa/responsetypes.py +++ b/common/lib/capa/capa/responsetypes.py @@ -190,7 +190,7 @@ class LoncapaResponse(object): for prop in self.required_attributes: prop_value = xml.get(prop) - if prop_value and isinstance(prop_value, str): + if prop_value: # Stripping off the empty strings prop_value = prop_value.strip() if not prop_value: msg = "Error in problem specification: %s missing required attribute %s" % (