def test_modx_dispatch(self):
     self.assertRaises(Http404, render.modx_dispatch, 'dummy', 'dummy',
                       'invalid Location', 'dummy')
     mock_request = MagicMock()
     mock_request.FILES.keys.return_value = ['file_id']
     mock_request.FILES.getlist.return_value = [
         'file'] * (settings.MAX_FILEUPLOADS_PER_INPUT + 1)
     self.assertEquals(
         render.modx_dispatch(
             mock_request, 'dummy', self.location, 'dummy').content,
         json.dumps({'success': 'Submission aborted! Maximum %d files may be submitted at once' %
                     settings.MAX_FILEUPLOADS_PER_INPUT}))
     mock_request_2 = MagicMock()
     mock_request_2.FILES.keys.return_value = ['file_id']
     inputfile = Stub()
     inputfile.size = 1 + settings.STUDENT_FILEUPLOAD_MAX_SIZE
     inputfile.name = 'name'
     filelist = [inputfile]
     mock_request_2.FILES.getlist.return_value = filelist
     self.assertEquals(
         render.modx_dispatch(mock_request_2, 'dummy', self.location,
                              'dummy').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))}))
     mock_request_3 = MagicMock()
     mock_request_3.POST.copy.return_value = {'position': 1}
     mock_request_3.FILES = False
     mock_request_3.user = UserFactory()
     inputfile_2 = Stub()
     inputfile_2.size = 1
     inputfile_2.name = 'name'
     self.assertIsInstance(
         render.modx_dispatch(mock_request_3, 'goto_position',
                              self.location, self.course_id), HttpResponse)
     self.assertRaises(
         Http404,
         render.modx_dispatch,
         mock_request_3,
         'goto_position',
         self.location,
         'bad_course_id'
     )
     self.assertRaises(
         Http404,
         render.modx_dispatch,
         mock_request_3,
         'goto_position',
         ['i4x', 'edX', 'toy', 'chapter', 'bad_location'],
         self.course_id
     )
     self.assertRaises(
         Http404,
         render.modx_dispatch,
         mock_request_3,
         'bad_dispatch',
         self.location,
         self.course_id
     )
 def test_modx_dispatch(self):
     self.assertRaises(Http404, render.modx_dispatch, "dummy", "dummy", "invalid Location", "dummy")
     mock_request = MagicMock()
     mock_request.FILES.keys.return_value = ["file_id"]
     mock_request.FILES.getlist.return_value = ["file"] * (settings.MAX_FILEUPLOADS_PER_INPUT + 1)
     self.assertEquals(
         render.modx_dispatch(mock_request, "dummy", self.location, "dummy").content,
         json.dumps(
             {
                 "success": "Submission aborted! Maximum %d files may be submitted at once"
                 % settings.MAX_FILEUPLOADS_PER_INPUT
             }
         ),
     )
     mock_request_2 = MagicMock()
     mock_request_2.FILES.keys.return_value = ["file_id"]
     inputfile = Stub()
     inputfile.size = 1 + settings.STUDENT_FILEUPLOAD_MAX_SIZE
     inputfile.name = "name"
     filelist = [inputfile]
     mock_request_2.FILES.getlist.return_value = filelist
     self.assertEquals(
         render.modx_dispatch(mock_request_2, "dummy", self.location, "dummy").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))
             }
         ),
     )
     mock_request_3 = MagicMock()
     mock_request_3.POST.copy.return_value = {"position": 1}
     mock_request_3.FILES = False
     mock_request_3.user = self.mock_user
     inputfile_2 = Stub()
     inputfile_2.size = 1
     inputfile_2.name = "name"
     self.assertIsInstance(
         render.modx_dispatch(mock_request_3, "goto_position", self.location, self.course_id), HttpResponse
     )
     self.assertRaises(
         Http404, render.modx_dispatch, mock_request_3, "goto_position", self.location, "bad_course_id"
     )
     self.assertRaises(
         Http404,
         render.modx_dispatch,
         mock_request_3,
         "goto_position",
         ["i4x", "edX", "toy", "chapter", "bad_location"],
         self.course_id,
     )
     self.assertRaises(Http404, render.modx_dispatch, mock_request_3, "bad_dispatch", self.location, self.course_id)