def handle_callback_and_get_display_name_from_event(self, mock_tracker, problem_display_name=None): """ Creates a fake module, invokes the callback and extracts the display name from the emitted problem_check event. """ descriptor_kwargs = { 'category': 'problem', 'data': self.problem_xml } if problem_display_name: descriptor_kwargs['display_name'] = problem_display_name descriptor = ItemFactory.create(**descriptor_kwargs) render.handle_xblock_callback( self.request, self.course.id, quote_slashes(str(descriptor.location)), 'xmodule_handler', 'problem_check', ) self.assertEquals(len(mock_tracker.send.mock_calls), 1) mock_call = mock_tracker.send.mock_calls[0] event = mock_call[1][0] self.assertEquals(event['event_type'], 'problem_check') return event['context']['module']['display_name']
def test_invalid_location(self): request = self.request_factory.post("dummy_url", data={"position": 1}) request.user = self.mock_user with self.assertRaises(Http404): render.handle_xblock_callback( request, self.course_key.to_deprecated_string(), "invalid Location", "dummy_handler" "dummy_dispatch" )
def test_invalid_location(self): request = self.request_factory.post('dummy_url', data={'position': 1}) request.user = self.mock_user with self.assertRaises(Http404): render.handle_xblock_callback(request, 'dummy/course/id', 'invalid Location', 'dummy_handler' 'dummy_dispatch')
def handle_callback_and_get_display_name_from_event( self, mock_tracker, problem_display_name=None): """ Creates a fake module, invokes the callback and extracts the display name from the emitted problem_check event. """ descriptor_kwargs = {'category': 'problem', 'data': self.problem_xml} if problem_display_name: descriptor_kwargs['display_name'] = problem_display_name descriptor = ItemFactory.create(**descriptor_kwargs) render.handle_xblock_callback( self.request, self.course.id.to_deprecated_string(), quote_slashes(descriptor.location.to_deprecated_string()), 'xmodule_handler', 'problem_check', ) self.assertEquals(len(mock_tracker.send.mock_calls), 1) mock_call = mock_tracker.send.mock_calls[0] event = mock_call[1][0] self.assertEquals(event['event_type'], 'problem_check') return event['context']['module']['display_name']
def test_invalid_location(self): with self.assertRaises(Http404): render.handle_xblock_callback( None, 'dummy/course/id', 'invalid Location', 'dummy_handler' 'dummy_dispatch' )
def test_invalid_location(self): request = self.request_factory.post('dummy_url', data={'position': 1}) request.user = self.mock_user with self.assertRaises(Http404): render.handle_xblock_callback( request, 'dummy/course/id', 'invalid Location', 'dummy_handler' 'dummy_dispatch' )
def test_bad_xmodule_dispatch(self): request = self.request_factory.post('dummy_url') request.user = self.mock_user with self.assertRaises(Http404): render.handle_xblock_callback( request, self.course_key.to_deprecated_string(), quote_slashes(self.location.to_deprecated_string()), 'xmodule_handler', 'bad_dispatch', )
def test_bad_course_id(self): request = self.request_factory.post('dummy_url') request.user = self.mock_user with self.assertRaises(Http404): render.handle_xblock_callback( request, 'bad_course_id', quote_slashes(str(self.location)), 'xmodule_handler', 'goto_position', )
def test_bad_course_id(self): request = self.request_factory.post('dummy_url') request.user = self.mock_user with self.assertRaises(Http404): render.handle_xblock_callback( request, 'bad_course_id', quote_slashes(self.location.to_deprecated_string()), 'xmodule_handler', 'goto_position', )
def test_bad_xmodule_dispatch(self): request = self.request_factory.post('dummy_url') request.user = self.mock_user with self.assertRaises(Http404): render.handle_xblock_callback( request, self.course_id, quote_slashes(str(self.location)), 'xmodule_handler', 'bad_dispatch', )
def test_bad_location(self): request = self.request_factory.post('dummy_url') request.user = self.mock_user with self.assertRaises(Http404): render.handle_xblock_callback( request, self.course_key.to_deprecated_string(), quote_slashes(self.course_key.make_usage_key('chapter', 'bad_location').to_deprecated_string()), 'xmodule_handler', 'goto_position', )
def test_missing_handler(self): request = self.request_factory.post('dummy_url') request.user = self.mock_user with self.assertRaises(Http404): render.handle_xblock_callback( request, self.course_id, quote_slashes(str(self.location)), 'bad_handler', 'bad_dispatch', )
def test_missing_handler(self): request = self.request_factory.post("dummy_url") request.user = self.mock_user with self.assertRaises(Http404): render.handle_xblock_callback( request, self.course_key.to_deprecated_string(), quote_slashes(self.location.to_deprecated_string()), "bad_handler", "bad_dispatch", )
def test_missing_handler(self): request = self.request_factory.post('dummy_url') request.user = self.mock_user with self.assertRaises(Http404): render.handle_xblock_callback( request, self.course_key.to_deprecated_string(), quote_slashes(self.location.to_deprecated_string()), 'bad_handler', 'bad_dispatch', )
def test_bad_location(self): request = self.request_factory.post("dummy_url") request.user = self.mock_user with self.assertRaises(Http404): render.handle_xblock_callback( request, self.course_key.to_deprecated_string(), quote_slashes(self.course_key.make_usage_key("chapter", "bad_location").to_deprecated_string()), "xmodule_handler", "goto_position", )
def test_bad_course_id(self): request = self.request_factory.post("dummy_url") request.user = self.mock_user with self.assertRaises(Http404): render.handle_xblock_callback( request, "bad_course_id", quote_slashes(self.location.to_deprecated_string()), "xmodule_handler", "goto_position", )
def test_bad_location(self): request = self.request_factory.post('dummy_url') request.user = self.mock_user with self.assertRaises(Http404): render.handle_xblock_callback( request, self.course_id, quote_slashes(str(Location('i4x', 'edX', 'toy', 'chapter', 'bad_location'))), 'xmodule_handler', 'goto_position', )
def test_xmodule_dispatch(self): request = self.request_factory.post("dummy_url", data={"position": 1}) request.user = self.mock_user response = render.handle_xblock_callback( request, self.course_key.to_deprecated_string(), quote_slashes(self.location.to_deprecated_string()), "xmodule_handler", "goto_position", ) self.assertIsInstance(response, HttpResponse)
def test_xmodule_dispatch(self): request = self.request_factory.post('dummy_url', data={'position': 1}) request.user = self.mock_user response = render.handle_xblock_callback( request, self.course_key.to_deprecated_string(), quote_slashes(self.location.to_deprecated_string()), 'xmodule_handler', 'goto_position', ) self.assertIsInstance(response, HttpResponse)
def test_xmodule_dispatch(self): request = self.request_factory.post('dummy_url', data={'position': 1}) request.user = self.mock_user response = render.handle_xblock_callback( request, self.course_id, quote_slashes(str(self.location)), 'xmodule_handler', 'goto_position', ) self.assertIsInstance(response, HttpResponse)
def handle_callback_and_get_display_name_from_event(self, mock_tracker, problem_display_name=None): """ Creates a fake module, invokes the callback and extracts the display name from the emitted problem_check event. """ descriptor_kwargs = {"category": "problem", "data": self.problem_xml} if problem_display_name: descriptor_kwargs["display_name"] = problem_display_name descriptor = ItemFactory.create(**descriptor_kwargs) render.handle_xblock_callback( self.request, self.course.id.to_deprecated_string(), quote_slashes(descriptor.location.to_deprecated_string()), "xmodule_handler", "problem_check", ) self.assertEquals(len(mock_tracker.send.mock_calls), 1) mock_call = mock_tracker.send.mock_calls[0] event = mock_call[1][0] self.assertEquals(event["event_type"], "problem_check") return event["context"]["module"]["display_name"]
def test_too_large_file(self): inputfile = self._mock_file(size=1 + settings.STUDENT_FILEUPLOAD_MAX_SIZE) request = self.request_factory.post('dummy_url', data={'file_id': inputfile}) request.user = self.mock_user self.assertEquals( render.handle_xblock_callback(request, 'dummy/course/id', quote_slashes(str(self.location)), 'dummy_handler').content, json.dumps({ 'success': 'Submission aborted! Your file "%s" is too large (max size: %d MB)' % (inputfile.name, settings.STUDENT_FILEUPLOAD_MAX_SIZE / (1000**2)) }))
def test_too_many_files(self): request = self.request_factory.post( 'dummy_url', data={ 'file_id': (self._mock_file(), ) * (settings.MAX_FILEUPLOADS_PER_INPUT + 1) }) request.user = self.mock_user self.assertEquals( render.handle_xblock_callback(request, 'dummy/course/id', quote_slashes(str(self.location)), 'dummy_handler').content, json.dumps({ 'success': 'Submission aborted! Maximum %d files may be submitted at once' % settings.MAX_FILEUPLOADS_PER_INPUT }))
def test_too_many_files(self): request = self.request_factory.post( 'dummy_url', data={'file_id': (self._mock_file(), ) * (settings.MAX_FILEUPLOADS_PER_INPUT + 1)} ) request.user = self.mock_user self.assertEquals( render.handle_xblock_callback( request, 'dummy/course/id', quote_slashes(str(self.location)), 'dummy_handler' ).content, json.dumps({ 'success': 'Submission aborted! Maximum %d files may be submitted at once' % settings.MAX_FILEUPLOADS_PER_INPUT }) )
def test_too_large_file(self): inputfile = self._mock_file(size=1 + settings.STUDENT_FILEUPLOAD_MAX_SIZE) request = self.request_factory.post("dummy_url", data={"file_id": inputfile}) request.user = self.mock_user self.assertEquals( render.handle_xblock_callback( request, self.course_key.to_deprecated_string(), quote_slashes(self.location.to_deprecated_string()), "dummy_handler", ).content, json.dumps( { "success": 'Submission aborted! Your file "%s" is too large (max size: %d MB)' % (inputfile.name, settings.STUDENT_FILEUPLOAD_MAX_SIZE / (1000 ** 2)) } ), )
def test_too_large_file(self): inputfile = self._mock_file(size=1 + settings.STUDENT_FILEUPLOAD_MAX_SIZE) request = self.request_factory.post( 'dummy_url', data={'file_id': inputfile} ) request.user = self.mock_user self.assertEquals( render.handle_xblock_callback( request, 'dummy/course/id', quote_slashes(str(self.location)), 'dummy_handler' ).content, json.dumps({ 'success': 'Submission aborted! Your file "%s" is too large (max size: %d MB)' % (inputfile.name, settings.STUDENT_FILEUPLOAD_MAX_SIZE / (1000 ** 2)) }) )
def test_too_many_files(self): request = self.request_factory.post( "dummy_url", data={"file_id": (self._mock_file(),) * (settings.MAX_FILEUPLOADS_PER_INPUT + 1)} ) request.user = self.mock_user self.assertEquals( render.handle_xblock_callback( request, self.course_key.to_deprecated_string(), quote_slashes(self.location.to_deprecated_string()), "dummy_handler", ).content, json.dumps( { "success": "Submission aborted! Maximum %d files may be submitted at once" % settings.MAX_FILEUPLOADS_PER_INPUT } ), )
def test_entrance_exam_xblock_response(self): """ Tests entrance exam xblock has `entrance_exam_passed` key in json response. """ request_factory = RequestFactory() data = {'input_{}_2_1'.format(unicode(self.problem_1.location.html_id())): 'choice_2'} request = request_factory.post( 'problem_check', data=data ) request.user = self.user response = handle_xblock_callback( request, unicode(self.course.id), unicode(self.problem_1.location), 'xmodule_handler', 'problem_check', ) self.assertEqual(response.status_code, 200) self.assertIn('entrance_exam_passed', response.content)