Commit 4a086606 by John Eskew

Move peer_api import down into method for Django 1.11

parent b0cc7c69
...@@ -8,7 +8,6 @@ import logging ...@@ -8,7 +8,6 @@ import logging
from webob import Response from webob import Response
from xblock.core import XBlock from xblock.core import XBlock
from openassessment.assessment.api import peer as peer_api
from openassessment.assessment.errors import (PeerAssessmentInternalError, PeerAssessmentRequestError, from openassessment.assessment.errors import (PeerAssessmentInternalError, PeerAssessmentRequestError,
PeerAssessmentWorkflowError) PeerAssessmentWorkflowError)
from openassessment.workflow.errors import AssessmentWorkflowError from openassessment.workflow.errors import AssessmentWorkflowError
...@@ -56,6 +55,8 @@ class PeerAssessmentMixin(object): ...@@ -56,6 +55,8 @@ class PeerAssessmentMixin(object):
and "msg" (unicode) containing additional information if an error occurs. and "msg" (unicode) containing additional information if an error occurs.
""" """
# Import is placed here to avoid model import at project startup.
from openassessment.assessment.api import peer as peer_api
if self.submission_uuid is None: if self.submission_uuid is None:
return { return {
'success': False, 'msg': self._('You must submit a response before you can perform a peer assessment.') 'success': False, 'msg': self._('You must submit a response before you can perform a peer assessment.')
...@@ -164,6 +165,8 @@ class PeerAssessmentMixin(object): ...@@ -164,6 +165,8 @@ class PeerAssessmentMixin(object):
tuple of (template_path, context_dict) tuple of (template_path, context_dict)
""" """
# Import is placed here to avoid model import at project startup.
from openassessment.assessment.api import peer as peer_api
path = 'openassessmentblock/peer/oa_peer_unavailable.html' path = 'openassessmentblock/peer/oa_peer_unavailable.html'
finished = False finished = False
problem_closed, reason, start_date, due_date = self.is_closed(step="peer-assessment") problem_closed, reason, start_date, due_date = self.is_closed(step="peer-assessment")
...@@ -274,6 +277,8 @@ class PeerAssessmentMixin(object): ...@@ -274,6 +277,8 @@ class PeerAssessmentMixin(object):
dict: The serialized submission model. dict: The serialized submission model.
""" """
# Import is placed here to avoid model import at project startup.
from openassessment.assessment.api import peer as peer_api
peer_submission = False peer_submission = False
try: try:
peer_submission = peer_api.get_submission_to_assess( peer_submission = peer_api.get_submission_to_assess(
......
...@@ -645,7 +645,7 @@ class TestPeerAssessmentRender(XBlockHandlerTestCase): ...@@ -645,7 +645,7 @@ class TestPeerAssessmentRender(XBlockHandlerTestCase):
xblock.get_workflow_info = mock.Mock(return_value=workflow_info) xblock.get_workflow_info = mock.Mock(return_value=workflow_info)
# Simulate that we've either finished or not finished required grading # Simulate that we've either finished or not finished required grading
patched_module = 'openassessment.xblock.peer_assessment_mixin.peer_api' patched_module = 'openassessment.assessment.api.peer'
with mock.patch(patched_module + '.has_finished_required_evaluating') as mock_finished: with mock.patch(patched_module + '.has_finished_required_evaluating') as mock_finished:
mock_finished.return_value = (was_graded_enough, 1) mock_finished.return_value = (was_graded_enough, 1)
path, context = xblock.peer_path_and_context(continue_grading) path, context = xblock.peer_path_and_context(continue_grading)
...@@ -775,13 +775,13 @@ class TestPeerAssessHandler(XBlockHandlerTestCase): ...@@ -775,13 +775,13 @@ class TestPeerAssessHandler(XBlockHandlerTestCase):
expect_failure=True expect_failure=True
) )
@mock.patch('openassessment.xblock.peer_assessment_mixin.peer_api') @mock.patch('openassessment.assessment.api.peer')
@scenario('data/peer_assessment_scenario.xml', user_id='Bob') @scenario('data/peer_assessment_scenario.xml', user_id='Bob')
def test_peer_api_request_error(self, xblock, mock_api): def test_peer_api_request_error(self, xblock, mock_api):
mock_api.create_assessment.side_effect = peer_api.PeerAssessmentRequestError mock_api.create_assessment.side_effect = peer_api.PeerAssessmentRequestError
self._submit_peer_assessment(xblock, u"Sally", u"Bob", self.ASSESSMENT, expect_failure=True) self._submit_peer_assessment(xblock, u"Sally", u"Bob", self.ASSESSMENT, expect_failure=True)
@mock.patch('openassessment.xblock.peer_assessment_mixin.peer_api') @mock.patch('openassessment.assessment.api.peer')
@scenario('data/peer_assessment_scenario.xml', user_id='Bob') @scenario('data/peer_assessment_scenario.xml', user_id='Bob')
def test_peer_api_internal_error(self, xblock, mock_api): def test_peer_api_internal_error(self, xblock, mock_api):
mock_api.create_assessment.side_effect = peer_api.PeerAssessmentInternalError mock_api.create_assessment.side_effect = peer_api.PeerAssessmentInternalError
......
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