示例#1
0
 def test_wrong_start_exam(self):
     factory = APIRequestFactory()
     with patch('api.views_ui.start_exam_request') as edx_request:
         edx_request.return_value = MockResponse(
             status_code=status.HTTP_400_BAD_REQUEST
         )
         request = factory.get(
             '/api/start_exam/%s' % self.exam.exam_code)
         force_authenticate(request, user=self.user)
         response = views_ui.start_exam(request,
                                        attempt_code=self.exam.exam_code)
         response.render()
         self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
         data = json.loads(response.content)
         self.assertIn('error', data)
示例#2
0
 def test_start_exam(self):
     factory = APIRequestFactory()
     with patch('api.views_ui.start_exam_request') as edx_request, \
             patch('api.views_ui.send_ws_msg') as send_ws:
         edx_request.return_value = MockResponse()
         send_ws.return_value = None
         request = factory.get(
             '/api/start_exam/%s' % self.exam.exam_code)
         force_authenticate(request, user=self.user)
         response = views_ui.start_exam(request,
                                        attempt_code=self.exam.exam_code)
         response.render()
         self.assertEqual(response.status_code, status.HTTP_200_OK)
         data = json.loads(response.content)
         self.assertIn('hash', data)
         self.assertIn('status', data)