Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion common/lib/xmodule/xmodule/peer_grading_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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))
Expand Down
54 changes: 54 additions & 0 deletions common/lib/xmodule/xmodule/tests/test_peer_grading.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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': '<peergrading/>',
'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)
1 change: 1 addition & 0 deletions common/test/data/open_ended/course/2012_Fall.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<combinedopenended url_name="SampleQuestion1Attempt"/>
<peergrading url_name="PeerGradingSample"/>
<peergrading url_name="PeerGradingScored"/>
<peergrading url_name="PeerGradingLinked"/>
</chapter>
</course>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<peergrading is_graded="True" max_grade="1" use_for_single_location="True" link_to_location="i4x://edX/open_ended/combinedopenended/SampleQuestion"/>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where this is used. In the test_linked_problem, it doesn't look like it refers to this. Is this providing additional testing by its mere presence?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The location is referenced in test_peer_grading.py, although the problem itself is not loaded. I figure that it might be good to place the problem in the course for future "what is this location?" questions, but it can be removed if needed. Strictly an ease of organization question.