diff --git a/common/lib/xmodule/xmodule/peer_grading_module.py b/common/lib/xmodule/xmodule/peer_grading_module.py
index 3a4bbdb9f657..36025e91f865 100644
--- a/common/lib/xmodule/xmodule/peer_grading_module.py
+++ b/common/lib/xmodule/xmodule/peer_grading_module.py
@@ -72,6 +72,12 @@ class PeerGradingFields(object):
scope=Scope.content
)
+class InvalidLinkLocation(Exception):
+ """
+ Exception for the case in which a peer grading module tries to link to an invalid location.
+ """
+ pass
+
class PeerGradingModule(PeerGradingFields, XModule):
"""
@@ -103,7 +109,13 @@ def __init__(self, *args, **kwargs):
if self.use_for_single_location:
try:
- self.linked_problem = self.system.get_module(self.link_to_location)
+ linked_descriptors = self.descriptor.get_required_module_descriptors()
+ if len(linked_descriptors) == 0:
+ error_msg = "Peer grading module {0} is trying to use single problem mode without "
+ "a location specified.".format(self.location)
+ log.error(error_msg)
+ raise InvalidLinkLocation(error_msg)
+ self.linked_problem = self.system.get_module(linked_descriptors[0])
except ItemNotFoundError:
log.error("Linked location {0} for peer grading module {1} does not exist".format(
self.link_to_location, self.location))
diff --git a/common/lib/xmodule/xmodule/tests/test_peer_grading.py b/common/lib/xmodule/xmodule/tests/test_peer_grading.py
index 240fef4e876a..04c968d04b11 100644
--- a/common/lib/xmodule/xmodule/tests/test_peer_grading.py
+++ b/common/lib/xmodule/xmodule/tests/test_peer_grading.py
@@ -2,6 +2,10 @@
from xmodule.modulestore import Location
from .import get_test_system
from test_util_open_ended import MockQueryDict, DummyModulestore
+from mock import Mock
+from xmodule.peer_grading_module import PeerGradingModule
+from xblock.field_data import DictFieldData
+from xblock.fields import ScopeIds
import logging
@@ -155,3 +159,53 @@ def setUp(self):
def test_metadata_load(self):
peer_grading = self.get_module_from_location(self.problem_location, COURSE)
self.assertEqual(peer_grading.closed(), False)
+
+class PeerGradingModuleLinkedTest(unittest.TestCase, DummyModulestore):
+ """
+ Test peer grading that is linked to an open ended module.
+ """
+ problem_location = Location(["i4x", "edX", "open_ended", "peergrading",
+ "PeerGradingLinked"])
+ coe_location = Location(["i4x", "edX", "open_ended", "combinedopenended",
+ "SampleQuestion"])
+
+ def setUp(self):
+ """
+ Create a peer grading module from a test system.
+ """
+ self.test_system = get_test_system()
+ self.test_system.open_ended_grading_interface = None
+ self.setup_modulestore(COURSE)
+
+ def test_linked_problem(self):
+ """
+ Check to see if a peer grading module with a linked problem loads properly.
+ """
+
+ # Mock the linked problem descriptor.
+ linked_descriptor = Mock()
+ linked_descriptor.location = self.coe_location
+
+ # Mock the peer grading descriptor.
+ pg_descriptor = Mock()
+ pg_descriptor.location = self.problem_location
+ pg_descriptor.get_required_module_descriptors = lambda: [linked_descriptor, ]
+
+ # Setup the proper field data for the peer grading module.
+ field_data = DictFieldData({
+ 'data': '',
+ 'location': self.problem_location,
+ 'use_for_single_location': True,
+ 'link_to_location': self.coe_location,
+ })
+
+ # Initialize the peer grading module.
+ peer_grading = PeerGradingModule(
+ pg_descriptor,
+ self.test_system,
+ field_data,
+ ScopeIds(None, None, self.problem_location, self.problem_location)
+ )
+
+ # Ensure that it is properly setup.
+ self.assertTrue(peer_grading.use_for_single_location)
diff --git a/common/test/data/open_ended/course/2012_Fall.xml b/common/test/data/open_ended/course/2012_Fall.xml
index 609d12f94c2f..232de855cce7 100644
--- a/common/test/data/open_ended/course/2012_Fall.xml
+++ b/common/test/data/open_ended/course/2012_Fall.xml
@@ -4,5 +4,6 @@
+
diff --git a/common/test/data/open_ended/peergrading/PeerGradingLinked.xml b/common/test/data/open_ended/peergrading/PeerGradingLinked.xml
new file mode 100644
index 000000000000..b2380b1e1b45
--- /dev/null
+++ b/common/test/data/open_ended/peergrading/PeerGradingLinked.xml
@@ -0,0 +1 @@
+
\ No newline at end of file