From 640b7fe6b5649b3da794f8907513598fcc770e46 Mon Sep 17 00:00:00 2001 From: Vik Paruchuri Date: Thu, 12 Sep 2013 15:17:04 -0400 Subject: [PATCH] Fix problem with peer grading list not rendering, test --- .../peer_grading_service.py | 12 ++++----- .../xmodule/xmodule/peer_grading_module.py | 26 ++++++++++++------- .../xmodule/tests/test_peer_grading.py | 26 +++++++++++++++++++ 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/common/lib/xmodule/xmodule/open_ended_grading_classes/peer_grading_service.py b/common/lib/xmodule/xmodule/open_ended_grading_classes/peer_grading_service.py index 0e5c9cdda1..ecac9a8a00 100644 --- a/common/lib/xmodule/xmodule/open_ended_grading_classes/peer_grading_service.py +++ b/common/lib/xmodule/xmodule/open_ended_grading_classes/peer_grading_service.py @@ -94,9 +94,9 @@ class MockPeerGradingService(object): 'success': True, 'submission_id': 1, 'submission_key': "", - 'student_response': 'fake student response', - 'prompt': 'fake submission prompt', - 'rubric': 'fake rubric', + 'student_response': 'Sample student response.', + 'prompt': 'Sample submission prompt.', + 'rubric': 'Placeholder text for the full rubric.', 'max_score': 4 } @@ -110,9 +110,9 @@ class MockPeerGradingService(object): return {'success': True, 'submission_id': 1, 'submission_key': '', - 'student_response': 'fake student response', - 'prompt': 'fake submission prompt', - 'rubric': 'fake rubric', + 'student_response': 'Sample student response.', + 'prompt': 'Sample submission prompt.', + 'rubric': 'Placeholder text for the full rubric.', 'max_score': 4} def save_calibration_essay(self, **kwargs): diff --git a/common/lib/xmodule/xmodule/peer_grading_module.py b/common/lib/xmodule/xmodule/peer_grading_module.py index 3a4bbdb9f6..a40929a258 100644 --- a/common/lib/xmodule/xmodule/peer_grading_module.py +++ b/common/lib/xmodule/xmodule/peer_grading_module.py @@ -8,7 +8,7 @@ from pkg_resources import resource_string from .capa_module import ComplexEncoder from .x_module import XModule from xmodule.raw_module import RawDescriptor -from xmodule.modulestore.exceptions import ItemNotFoundError +from xmodule.modulestore.exceptions import ItemNotFoundError, NoPathToItem from .timeinfo import TimeInfo from xblock.fields import Dict, String, Scope, Boolean, Float from xmodule.fields import Date, Timedelta @@ -108,6 +108,10 @@ class PeerGradingModule(PeerGradingFields, XModule): log.error("Linked location {0} for peer grading module {1} does not exist".format( self.link_to_location, self.location)) raise + except NoPathToItem: + log.error("Linked location {0} for peer grading module {1} cannot be linked to.".format( + self.link_to_location, self.location)) + raise due_date = self.linked_problem.due if due_date: self.due = due_date @@ -514,14 +518,18 @@ class PeerGradingModule(PeerGradingFields, XModule): def _find_corresponding_module_for_location(location): - ''' - find the peer grading module that links to the given location - ''' + """ + Find the peer grading module that links to the given location. + """ try: - return modulestore().get_instance(self.system.course_id, location) - except Exception: - # the linked problem doesn't exist - log.error("Problem {0} does not exist in this course".format(location)) + return self.descriptor.system.load_item(location) + except ItemNotFoundError: + # The linked problem doesn't exist. + log.error("Problem {0} does not exist in this course.".format(location)) + raise + except NoPathToItem: + # The linked problem doesn't exist. + log.error("Cannot find a path to problem {0} in this course.".format(location)) raise good_problem_list = [] @@ -529,7 +537,7 @@ class PeerGradingModule(PeerGradingFields, XModule): problem_location = problem['location'] try: descriptor = _find_corresponding_module_for_location(problem_location) - except Exception: + except (NoPathToItem, ItemNotFoundError): continue if descriptor: problem['due'] = descriptor.due diff --git a/common/lib/xmodule/xmodule/tests/test_peer_grading.py b/common/lib/xmodule/xmodule/tests/test_peer_grading.py index 240fef4e87..a81050b306 100644 --- a/common/lib/xmodule/xmodule/tests/test_peer_grading.py +++ b/common/lib/xmodule/xmodule/tests/test_peer_grading.py @@ -2,6 +2,8 @@ import unittest from xmodule.modulestore import Location from .import get_test_system from test_util_open_ended import MockQueryDict, DummyModulestore +from xmodule.open_ended_grading_classes.peer_grading_service import MockPeerGradingService +import json import logging @@ -136,6 +138,13 @@ class PeerGradingModuleTest(unittest.TestCase, DummyModulestore): """ self.peer_grading.get_instance_state() +class MockPeerGradingServiceProblemList(MockPeerGradingService): + def get_problem_list(self, course_id, grader_id): + return {'success': True, + 'problem_list': [ + {"num_graded": 3, "num_pending": 681, "num_required": 3, "location": "i4x://edX/open_ended/combinedopenended/SampleQuestion", "problem_name": "Peer-Graded Essay"}, + ]} + class PeerGradingModuleScoredTest(unittest.TestCase, DummyModulestore): """ Test peer grading xmodule at the unit level. More detailed tests are difficult, as the module relies on an @@ -155,3 +164,20 @@ class PeerGradingModuleScoredTest(unittest.TestCase, DummyModulestore): def test_metadata_load(self): peer_grading = self.get_module_from_location(self.problem_location, COURSE) self.assertEqual(peer_grading.closed(), False) + + def test_problem_list(self): + """ + Test to see if a peer grading problem list can be correctly initialized. + """ + + # Initialize peer grading module. + peer_grading = self.get_module_from_location(self.problem_location, COURSE) + + # Ensure that it cannot find any peer grading. + html = peer_grading.peer_grading() + self.assertNotRegexpMatches(html, "Peer-Graded") + + #Swap for our mock class, which will find peer grading. + peer_grading.peer_gs = MockPeerGradingServiceProblemList() + html = peer_grading.peer_grading() + self.assertRegexpMatches(html, "Peer-Graded") \ No newline at end of file