Commit 8f95ae7a by Will Daly

Fix warning for submission in Studio preview

parent 7a4bb68b
......@@ -61,7 +61,9 @@ class SubmissionMixin(object):
# Short-circuit if no user is defined (as in Studio Preview mode)
# Since students can't submit, they will never be able to progress in the workflow
if student_item_dict['student_id'] is None:
# Studio Preview provides an anonymous student ID, so we need to check the scope ids directly
# to check that we are in preview mode.
if self.scope_ids.user_id is None:
return False, 'ENOPREVIEW', self.submit_errors['ENOPREVIEW']
workflow = self.get_workflow_info()
......
......@@ -3,7 +3,7 @@ Test submission to the OpenAssessment XBlock.
"""
import json
from mock import patch
from mock import patch, Mock
from submissions import api as sub_api
from submissions.api import SubmissionRequestError, SubmissionInternalError
from openassessment.xblock.submission_mixin import SubmissionMixin
......@@ -50,7 +50,16 @@ class SubmissionTest(XBlockHandlerTestCase):
# In Studio preview mode, the runtime sets the user ID to None
@scenario('data/basic_scenario.xml', user_id=None)
def test_cannot_submit_in_preview_mode(self, xblock,):
# The Studio runtime apparently provides an anonymous student ID,
# even though we're running in Preview mode. We should check the scope id
# to determine whether we're in Preview mode or not.
xblock.xmodule_runtime = Mock(
course_id='test_course',
anonymous_student_id='test_student'
)
resp = self.request(xblock, 'submit', self.SUBMISSION, response_format='json')
self.assertFalse(resp[0])
self.assertEqual(resp[1], "ENOPREVIEW")
self.assertEqual(resp[2], "To submit a response, view this component in Preview or Live mode.")
\ No newline at end of file
self.assertEqual(resp[2], "To submit a response, view this component in Preview or Live mode.")
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