Commit 640b7fe6 by Vik Paruchuri

Fix problem with peer grading list not rendering, test

parent 009017fe
...@@ -94,9 +94,9 @@ class MockPeerGradingService(object): ...@@ -94,9 +94,9 @@ class MockPeerGradingService(object):
'success': True, 'success': True,
'submission_id': 1, 'submission_id': 1,
'submission_key': "", 'submission_key': "",
'student_response': 'fake student response', 'student_response': 'Sample student response.',
'prompt': 'fake submission prompt', 'prompt': 'Sample submission prompt.',
'rubric': 'fake rubric', 'rubric': 'Placeholder text for the full rubric.',
'max_score': 4 'max_score': 4
} }
...@@ -110,9 +110,9 @@ class MockPeerGradingService(object): ...@@ -110,9 +110,9 @@ class MockPeerGradingService(object):
return {'success': True, return {'success': True,
'submission_id': 1, 'submission_id': 1,
'submission_key': '', 'submission_key': '',
'student_response': 'fake student response', 'student_response': 'Sample student response.',
'prompt': 'fake submission prompt', 'prompt': 'Sample submission prompt.',
'rubric': 'fake rubric', 'rubric': 'Placeholder text for the full rubric.',
'max_score': 4} 'max_score': 4}
def save_calibration_essay(self, **kwargs): def save_calibration_essay(self, **kwargs):
......
...@@ -8,7 +8,7 @@ from pkg_resources import resource_string ...@@ -8,7 +8,7 @@ from pkg_resources import resource_string
from .capa_module import ComplexEncoder from .capa_module import ComplexEncoder
from .x_module import XModule from .x_module import XModule
from xmodule.raw_module import RawDescriptor from xmodule.raw_module import RawDescriptor
from xmodule.modulestore.exceptions import ItemNotFoundError from xmodule.modulestore.exceptions import ItemNotFoundError, NoPathToItem
from .timeinfo import TimeInfo from .timeinfo import TimeInfo
from xblock.fields import Dict, String, Scope, Boolean, Float from xblock.fields import Dict, String, Scope, Boolean, Float
from xmodule.fields import Date, Timedelta from xmodule.fields import Date, Timedelta
...@@ -108,6 +108,10 @@ class PeerGradingModule(PeerGradingFields, XModule): ...@@ -108,6 +108,10 @@ class PeerGradingModule(PeerGradingFields, XModule):
log.error("Linked location {0} for peer grading module {1} does not exist".format( log.error("Linked location {0} for peer grading module {1} does not exist".format(
self.link_to_location, self.location)) self.link_to_location, self.location))
raise 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 due_date = self.linked_problem.due
if due_date: if due_date:
self.due = due_date self.due = due_date
...@@ -514,14 +518,18 @@ class PeerGradingModule(PeerGradingFields, XModule): ...@@ -514,14 +518,18 @@ class PeerGradingModule(PeerGradingFields, XModule):
def _find_corresponding_module_for_location(location): 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: try:
return modulestore().get_instance(self.system.course_id, location) return self.descriptor.system.load_item(location)
except Exception: except ItemNotFoundError:
# the linked problem doesn't exist # The linked problem doesn't exist.
log.error("Problem {0} does not exist in this course".format(location)) 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 raise
good_problem_list = [] good_problem_list = []
...@@ -529,7 +537,7 @@ class PeerGradingModule(PeerGradingFields, XModule): ...@@ -529,7 +537,7 @@ class PeerGradingModule(PeerGradingFields, XModule):
problem_location = problem['location'] problem_location = problem['location']
try: try:
descriptor = _find_corresponding_module_for_location(problem_location) descriptor = _find_corresponding_module_for_location(problem_location)
except Exception: except (NoPathToItem, ItemNotFoundError):
continue continue
if descriptor: if descriptor:
problem['due'] = descriptor.due problem['due'] = descriptor.due
......
...@@ -2,6 +2,8 @@ import unittest ...@@ -2,6 +2,8 @@ import unittest
from xmodule.modulestore import Location from xmodule.modulestore import Location
from .import get_test_system from .import get_test_system
from test_util_open_ended import MockQueryDict, DummyModulestore from test_util_open_ended import MockQueryDict, DummyModulestore
from xmodule.open_ended_grading_classes.peer_grading_service import MockPeerGradingService
import json
import logging import logging
...@@ -136,6 +138,13 @@ class PeerGradingModuleTest(unittest.TestCase, DummyModulestore): ...@@ -136,6 +138,13 @@ class PeerGradingModuleTest(unittest.TestCase, DummyModulestore):
""" """
self.peer_grading.get_instance_state() 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): class PeerGradingModuleScoredTest(unittest.TestCase, DummyModulestore):
""" """
Test peer grading xmodule at the unit level. More detailed tests are difficult, as the module relies on an 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): ...@@ -155,3 +164,20 @@ class PeerGradingModuleScoredTest(unittest.TestCase, DummyModulestore):
def test_metadata_load(self): def test_metadata_load(self):
peer_grading = self.get_module_from_location(self.problem_location, COURSE) peer_grading = self.get_module_from_location(self.problem_location, COURSE)
self.assertEqual(peer_grading.closed(), False) 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment