Computed answers are run through safe_exec.
This commit is contained in:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user