From 210cdf870eb5e2d8d27c10c5676cf87968fbc97f Mon Sep 17 00:00:00 2001 From: Diana Huang Date: Thu, 24 Jan 2013 09:41:24 -0500 Subject: [PATCH] Updates to the mock peer grading service and new tests. --- .../peer_grading_service.py | 15 ++++- lms/djangoapps/open_ended_grading/tests.py | 62 ++++++++++++++++++- 2 files changed, 73 insertions(+), 4 deletions(-) diff --git a/lms/djangoapps/open_ended_grading/peer_grading_service.py b/lms/djangoapps/open_ended_grading/peer_grading_service.py index 8e0f8cbbaa..0ae4cc4534 100644 --- a/lms/djangoapps/open_ended_grading/peer_grading_service.py +++ b/lms/djangoapps/open_ended_grading/peer_grading_service.py @@ -29,6 +29,15 @@ This is a mock peer grading service that can be used for unit tests without making actual service calls to the grading controller """ class MockPeerGradingService(object): + # TODO: get this rubric parsed and working + rubric = """ + + Description + + + + """ + def get_next_submission(self, problem_location, grader_id): return json.dumps({'success': True, 'submission_id':1, @@ -56,15 +65,15 @@ class MockPeerGradingService(object): def save_calibration_essay(self, problem_location, grader_id, calibration_essay_id, submission_key, score, feedback): - return {'success': True, 'actual_score': 2} + return json.dumps({'success': True, 'actual_score': 2}) def get_problem_list(self, course_id, grader_id): return json.dumps({'success': True, 'problem_list': [ json.dumps({'location': 'i4x://MITx/3.091x/problem/open_ended_demo1', - 'problem_name': "Problem 1", 'num_graded': 3, 'num_pending': 5}), + 'problem_name': "Problem 1", 'num_graded': 3, 'num_pending': 5, 'num_required': 7}), json.dumps({'location': 'i4x://MITx/3.091x/problem/open_ended_demo2', - 'problem_name': "Problem 2", 'num_graded': 1, 'num_pending': 5}) + 'problem_name': "Problem 2", 'num_graded': 1, 'num_pending': 5, 'num_required': 8}) ]}) class PeerGradingService(GradingService): diff --git a/lms/djangoapps/open_ended_grading/tests.py b/lms/djangoapps/open_ended_grading/tests.py index bd2b3c6695..d1670a1b26 100644 --- a/lms/djangoapps/open_ended_grading/tests.py +++ b/lms/djangoapps/open_ended_grading/tests.py @@ -18,6 +18,8 @@ from nose import SkipTest from mock import patch, Mock import json +import logging +log = logging.getLogger(__name__) from override_settings import override_settings @@ -182,7 +184,7 @@ class TestPeerGradingService(ct.PageLoader): self.assertFalse(d['success']) self.assertTrue(d['error'].find('Missing required keys:') > -1) - def test_is_calibrated(self): + def test_is_calibrated_success(self): self.login(self.student, self.password) url = reverse('peer_grading_is_student_calibrated', kwargs={'course_id': self.course_id}) data = {'location': self.location} @@ -191,3 +193,61 @@ class TestPeerGradingService(ct.PageLoader): self.assertTrue(d['success']) self.assertTrue('calibrated' in d) + def test_is_calibrated_failure(self): + self.login(self.student, self.password) + url = reverse('peer_grading_is_student_calibrated', kwargs={'course_id': self.course_id}) + data = {} + r = self.check_for_post_code(200, url, data) + d = json.loads(r.content) + self.assertFalse(d['success']) + self.assertFalse('calibrated' in d) + + def test_show_calibration_essay_success(self): + self.login(self.student, self.password) + + url = reverse('peer_grading_show_calibration_essay', kwargs={'course_id': self.course_id}) + data = {'location': self.location} + + r = self.check_for_post_code(200, url, data) + d = json.loads(r.content) + self.assertTrue(d['success']) + self.assertIsNotNone(d['submission_id']) + self.assertIsNotNone(d['prompt']) + self.assertIsNotNone(d['submission_key']) + self.assertIsNotNone(d['max_score']) + + def test_show_calibration_essay_missing_key(self): + self.login(self.student, self.password) + + url = reverse('peer_grading_show_calibration_essay', kwargs={'course_id': self.course_id}) + data = {} + + r = self.check_for_post_code(200, url, data) + d = json.loads(r.content) + + self.assertFalse(d['success']) + self.assertEqual(d['error'], "Missing required keys: location") + + def test_save_calibration_essay_success(self): + self.login(self.student, self.password) + url = reverse('peer_grading_save_calibration_essay', kwargs={'course_id': self.course_id}) + data = {'location': self.location, + 'submission_id': '1', + 'submission_key': 'fake key', + 'score': '2', + 'feedback': 'This is feedback'} + r = self.check_for_post_code(200, url, data) + d = json.loads(r.content) + self.assertTrue(d['success']) + self.assertTrue('actual_score' in d) + + def test_save_calibration_essay_missing_keys(self): + self.login(self.student, self.password) + url = reverse('peer_grading_save_calibration_essay', kwargs={'course_id': self.course_id}) + data = {} + r = self.check_for_post_code(200, url, data) + d = json.loads(r.content) + self.assertFalse(d['success']) + self.assertTrue(d['error'].find('Missing required keys:') > -1) + self.assertFalse('actual_score' in d) +