def test_post_submission_for_student_on_accessing(self): course = get_course_with_access(self.student_on_accessing, 'load', self.course_id) dry_run_result = post_submission_for_student(self.student_on_accessing, course, self.problem_location, self.open_ended_task_number, dry_run=True) self.assertFalse(dry_run_result) with patch('capa.xqueue_interface.XQueueInterface.send_to_queue') as mock_send_to_queue: mock_send_to_queue.return_value = (0, "Successfully queued") module = get_module_for_student(self.student_on_accessing, self.problem_location) task = module.child_module.get_task_number(self.open_ended_task_number) student_response = "Here is an answer." student_anonymous_id = anonymous_id_for_user(self.student_on_accessing, None) submission_time = datetime.strftime(datetime.now(UTC), xqueue_interface.dateformat) result = post_submission_for_student(self.student_on_accessing, course, self.problem_location, self.open_ended_task_number, dry_run=False) self.assertTrue(result) mock_send_to_queue_body_arg = json.loads(mock_send_to_queue.call_args[1]['body']) self.assertEqual(mock_send_to_queue_body_arg['max_score'], 2) self.assertEqual(mock_send_to_queue_body_arg['student_response'], student_response) body_arg_student_info = json.loads(mock_send_to_queue_body_arg['student_info']) self.assertEqual(body_arg_student_info['anonymous_student_id'], student_anonymous_id) self.assertGreaterEqual(body_arg_student_info['submission_time'], submission_time)
def test_post_submission_for_student_on_accessing(self): course = get_course_with_access(self.student_on_accessing, self.course_id, "load") dry_run_result = post_submission_for_student( self.student_on_accessing, course, self.problem_location, self.open_ended_task_number, dry_run=True ) self.assertFalse(dry_run_result) with patch("capa.xqueue_interface.XQueueInterface.send_to_queue") as mock_send_to_queue: mock_send_to_queue.return_value = (0, "Successfully queued") module = get_module_for_student(self.student_on_accessing, course, self.problem_location) task = module.child_module.get_task_number(self.open_ended_task_number) qtime = datetime.strftime(datetime.now(UTC), xqueue_interface.dateformat) student_info = { "anonymous_student_id": anonymous_id_for_user(self.student_on_accessing, ""), "submission_time": qtime, } contents = task.payload.copy() contents.update( {"max_score": 2, "student_info": json.dumps(student_info), "student_response": "Here is an answer."} ) result = post_submission_for_student( self.student_on_accessing, course, self.problem_location, self.open_ended_task_number, dry_run=False ) self.assertTrue(result) mock_send_to_queue.assert_called_with(body=json.dumps(contents), header=ANY)
def test_post_submission_for_student_on_accessing(self): course = get_course_with_access(self.student_on_accessing, self.course_id, 'load') dry_run_result = post_submission_for_student(self.student_on_accessing, course, self.problem_location, self.open_ended_task_number, dry_run=True) self.assertFalse(dry_run_result) with patch('capa.xqueue_interface.XQueueInterface.send_to_queue') as mock_send_to_queue: mock_send_to_queue.return_value = (0, "Successfully queued") module = get_module_for_student(self.student_on_accessing, course, self.problem_location) task = module.child_module.get_task_number(self.open_ended_task_number) qtime = datetime.strftime(datetime.now(UTC), xqueue_interface.dateformat) student_info = {'anonymous_student_id': anonymous_id_for_user(self.student_on_accessing, ''), 'submission_time': qtime} contents = task.payload.copy() contents.update({ 'max_score': 2, 'student_info': json.dumps(student_info), 'student_response': "Here is an answer.", }) result = post_submission_for_student(self.student_on_accessing, course, self.problem_location, self.open_ended_task_number, dry_run=False) self.assertTrue(result) mock_send_to_queue.assert_called_with(body=json.dumps(contents), header=ANY)
def test_post_submission_for_student_on_initial(self): course = get_course_with_access(self.student_on_initial, 'load', self.course_id) dry_run_result = post_submission_for_student(self.student_on_initial, course, self.problem_location, self.open_ended_task_number, dry_run=True) self.assertFalse(dry_run_result) result = post_submission_for_student(self.student_on_initial, course, self.problem_location, self.open_ended_task_number, dry_run=False) self.assertFalse(result)
def test_post_submission_for_student_invalid_task(self): course = get_course_with_access(self.student_on_accessing, 'load', self.course_id) result = post_submission_for_student(self.student_on_accessing, course, self.problem_location, self.self_assessment_task_number, dry_run=False) self.assertFalse(result) out_of_bounds_task_number = 3 result = post_submission_for_student(self.student_on_accessing, course, self.problem_location, out_of_bounds_task_number, dry_run=False) self.assertFalse(result)