Commit a6677aa0 by Ned Batchelder

Computed answers are run through safe_exec.

parent 37ca6bf7
......@@ -1087,8 +1087,7 @@ def sympy_check2():
# exec the check function
if isinstance(self.code, basestring):
try:
raise Exception("exec 1")
exec self.code in self.context['global_context'], self.context
safe_exec.safe_exec(self.code, self.context)
correct = self.context['correct']
messages = self.context['messages']
overall_message = self.context['overall_message']
......
......@@ -92,6 +92,20 @@ print(num)
</text>
</problem>
<problem url_name="computed_answer">
<customresponse>
<textline size="5" correct_answer="Xyzzy"/>
<answer type="loncapa/python">
if submission[0] == "Xyzzy":
correct = ['correct']
else:
correct = ['incorrect']
</answer>
</customresponse>
</problem>
</vertical>
</chapter>
</course>
......@@ -1023,3 +1023,8 @@ class TestSchematicResponse(TestSubmittingProblems):
resp = self.submit_question_answer('cfn_problem', {'2_1': "xyzzy!"})
respdata = json.loads(resp.content)
self.assertEqual(respdata['success'], 'incorrect')
def test_computed_answer(self):
resp = self.submit_question_answer('computed_answer', {'2_1': "Xyzzy"})
respdata = json.loads(resp.content)
self.assertEqual(respdata['success'], 'correct')
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