Merge pull request #24540 from edx/aj/bug-fix-capa-ec

bug: fix an edge case in capa problem tolerance
This commit is contained in:
Awais Jibran
2020-07-20 16:28:27 +05:00
committed by GitHub
3 changed files with 20 additions and 8 deletions

View File

@@ -1551,7 +1551,7 @@ class NumericalResponse(LoncapaResponse):
id=xml.get('id')
)
if tolerance_xml: # If it isn't an empty list...
self.tolerance = contextualize_text(tolerance_xml[0], context)
self.tolerance = contextualize_text(tolerance_xml[0].strip(), context)
def get_staff_ans(self, answer):
"""
@@ -3057,7 +3057,7 @@ class FormulaResponse(LoncapaResponse):
id=xml.get('id')
)
if tolerance_xml: # If it isn't an empty list...
self.tolerance = contextualize_text(tolerance_xml[0], context)
self.tolerance = contextualize_text(tolerance_xml[0].strip(), context)
types = xml.get('type')
if types is None:

View File

@@ -1515,6 +1515,15 @@ class NumericalResponseTest(ResponseTest): # pylint: disable=missing-class-docs
incorrect_responses = ["", "3.01", "-1.01"]
self.assert_multiple_grade(problem, correct_responses, incorrect_responses)
def test_grade_percent_tolerance_with_spaces(self):
"""
Tests that system does not throw an error when tolerance data contains spaces before or after.
"""
problem = self.build_problem(answer=4, tolerance="10% ")
correct_responses = ["4.0", "4.00", "4.39", "3.61"]
incorrect_responses = ["", "4.41", "3.59", "0"]
self.assert_multiple_grade(problem, correct_responses, incorrect_responses)
def test_floats(self):
"""
Default tolerance for all responsetypes is 1e-3%.

View File

@@ -1214,12 +1214,15 @@ class CapaMixin(ScorableXBlockMixin, CapaFields):
# Too late. Cannot submit
if self.closed():
problem_location = text_type(self.location)
if 'HarvardX+MCB80.1x+3T2019' in problem_location:
log.info(
'Problem %s closed, close date: %s, attempts: %s/%s, is_past_due: %s',
problem_location, self.close_date, self.attempts, self.max_attempts, self.is_past_due()
)
log.error(
'ProblemClosedError: Problem %s, close date: %s, due:%s, attempts: %s/%s, is_past_due: %s',
text_type(self.location),
self.close_date,
self.due,
self.is_past_due(),
self.attempts,
self.max_attempts,
)
event_info['failure'] = 'closed'
self.track_function_unmask('problem_check_fail', event_info)
raise NotFoundError(_("Problem is closed."))