From bb521a20b7f33743bd52a512573a29d0580aaf74 Mon Sep 17 00:00:00 2001 From: Diana Huang Date: Fri, 25 Jan 2013 10:19:09 -0500 Subject: [PATCH] fix a bug caught with testing and update some tests (the last couple are still broken, though) --- .../lib/xmodule/xmodule/open_ended_module.py | 6 +- .../xmodule/tests/test_combined_open_ended.py | 69 ++++++++++++++++++- 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/common/lib/xmodule/xmodule/open_ended_module.py b/common/lib/xmodule/xmodule/open_ended_module.py index 0eaad34bad..0b7523f984 100644 --- a/common/lib/xmodule/xmodule/open_ended_module.py +++ b/common/lib/xmodule/xmodule/open_ended_module.py @@ -257,7 +257,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild): """ new_score_msg = self._parse_score_msg(score_msg, system) if not new_score_msg['valid']: - score_msg['feedback'] = 'Invalid grader reply. Please contact the course staff.' + new_score_msg['feedback'] = 'Invalid grader reply. Please contact the course staff.' self.record_latest_score(new_score_msg['score']) self.record_latest_post_assessment(score_msg) @@ -404,6 +404,10 @@ class OpenEndedModule(openendedchild.OpenEndedChild): 'score': Numeric value (floating point is okay) to assign to answer 'msg': grader_msg 'feedback' : feedback from grader + 'grader_type': what type of grader resulted in this score + 'grader_id': id of the grader + 'submission_id' : id of the submission + 'success': whether or not this submission was successful } Returns (valid_score_msg, correct, score, msg): diff --git a/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py b/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py index 7ae17f6a4f..18176d0e12 100644 --- a/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py +++ b/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py @@ -1,11 +1,13 @@ import json -from mock import Mock, MagicMock +from mock import Mock, MagicMock, ANY import unittest from xmodule.openendedchild import OpenEndedChild from xmodule.open_ended_module import OpenEndedModule from xmodule.modulestore import Location from lxml import etree +import capa.xqueue_interface as xqueue_interface +from datetime import datetime from . import test_system @@ -165,15 +167,78 @@ class OpenEndedModuleTest(unittest.TestCase): 'submission_id': '1', 'grader_id': '1', 'score': 3} + qtime = datetime.strftime(datetime.now(), xqueue_interface.dateformat) + student_info = {'anonymous_student_id': test_system.anonymous_student_id, + 'submission_time': qtime} + contents = { + 'feedback': get['feedback'], + 'submission_id': int(get['submission_id']), + 'grader_id': int(get['grader_id']), + 'score': get['score'], + 'student_info': json.dumps(student_info) + } result = self.openendedmodule.message_post(get, test_system) self.assertTrue(result['success']) + # make sure it's actually sending something to the queue + self.mock_xqueue.send_to_queue.assert_called_with(body = json.dumps(contents), header=ANY) + state = json.loads(self.openendedmodule.get_instance_state()) self.assertIsNotNone(state['state'], OpenEndedModule.DONE) def test_send_to_grader(self): - result = self.openendedmodule.send_to_grader("This is a student submission", test_system) + submission = "This is a student submission" + qtime = datetime.strftime(datetime.now(), xqueue_interface.dateformat) + student_info = {'anonymous_student_id': test_system.anonymous_student_id, + 'submission_time': qtime} + contents = self.openendedmodule.payload.copy() + contents.update({ + 'student_info': json.dumps(student_info), + 'student_response': submission, + 'max_score': self.max_score + }) + result = self.openendedmodule.send_to_grader(submission, test_system) self.assertTrue(result) + self.mock_xqueue.send_to_queue.assert_called_with(body = json.dumps(contents), header=ANY) + + def update_score_single(self): + self.openendedmodule.new_history_entry("New Entry") + score_msg = { + 'correct': True, + 'score': 4, + 'msg' : 'Grader Message', + 'feedback': "Grader Feedback" + } + get = {'queuekey': "abcd", + 'xqueue_body': score_msg} + self.openendedmodule.update_score(get, test_system) + + def update_score_single(self): + self.openendedmodule.new_history_entry("New Entry") + feedback = { + "success": True, + "feedback": "Grader Feedback" + } + score_msg = { + 'correct': True, + 'score': 4, + 'msg' : 'Grader Message', + 'feedback': feedback, + 'grader_type': 'IN', + 'grader_id': '1', + 'submission_id': '1', + 'success': True + } + get = {'queuekey': "abcd", + 'xqueue_body': json.dumps(score_msg)} + self.openendedmodule.update_score(get, test_system) + def test_update_score(self): + self.update_score_single() + score = self.openendedmodule.latest_score() + self.assertEqual(score, 4) + + def test_latest_post_assessment(self): + self.update_score_single()