def test_run_python(self): rp = RunPython() problem = Problems.objects.all()[0] success = rp.execute(problem, problem.answer) self.failUnlessEqual(success, True) success = rp.execute(problem, 'def fibonnaci(): return 0') self.failIfEqual(success, True)
def run_program(request): user_answer = request.POST['my_buffer'] challenge_id = request.session.get('challenge_id', None) if not challenge_id: return http.HttpResponse('') challenge = Challenge.objects.get(pk=challenge_id) rp = RunPython() success = rp.execute(challenge.problem, user_answer) if success: # TODO: race condition possible challenge.winner = request.user challenge.save() response = {'success':success, 'error':rp.error, 'output':rp.get_user_output_string()} return http.HttpResponse(json.dumps(response))