Repository: Cloud-CV/EvalAI

Issue:
FIX: Limit number of concurrent submissions for a participant.
Fixes #1618 


Discussion:
@deshraj I did it!
@isht3 the code looks good. What all remains is test case. 
@isht3 I am merging this for now. Please remember that I expect test cases for this in a separate PR though. 

Resolving patch:
diff --git a/apps/jobs/views.py b/apps/jobs/views.py
--- a/apps/jobs/views.py
+++ b/apps/jobs/views.py
@@ -114,7 +114,7 @@ def challenge_submission(request, challenge_id, challenge_phase_id):
             message = 'You have {} submissions that are being processed. \
                        Please wait for them to finish and then try again.'
             response_data = {'error': message.format(submissions_in_progress)}
-            return Response(response_data, status=status.HTTP_400_BAD_REQUEST)
+            return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE)
 
         serializer = SubmissionSerializer(data=request.data,
                                           context={'participant_team': participant_team,
@@ -128,7 +128,7 @@ def challenge_submission(request, challenge_id, challenge_phase_id):
             # publish message in the queue
             publish_submission_message(challenge_id, challenge_phase_id, submission.id)
             return Response(response_data, status=status.HTTP_201_CREATED)
-        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
+        return Response(serializer.errors, status=status.HTTP_406_NOT_ACCEPTABLE)
 
 
 @throttle_classes([UserRateThrottle])


Test patch:
diff --git a/tests/unit/jobs/test_views.py b/tests/unit/jobs/test_views.py
--- a/tests/unit/jobs/test_views.py
+++ b/tests/unit/jobs/test_views.py
@@ -214,7 +214,7 @@ def test_challenge_submission_when_status_and_file_is_not_submitted(self):
 
         response = self.client.post(self.url, {})
         self.assertEqual(response.data, expected)
-        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
+        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
 
     def test_challenge_submission_when_form_encoding_is_wrong(self):
         self.url = reverse_lazy('jobs:challenge_submission',
@@ -231,7 +231,7 @@ def test_challenge_submission_when_form_encoding_is_wrong(self):
         response = self.client.post(
             self.url, {'status': 'submitting', 'input_file': self.input_file})
         self.assertEqual(response.data, expected)
-        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
+        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
 
     def test_challenge_submission_when_status_is_not_correct(self):
         self.url = reverse_lazy('jobs:challenge_submission',
@@ -248,7 +248,7 @@ def test_challenge_submission_when_status_is_not_correct(self):
         response = self.client.post(
             self.url, {'status': 'XYZ', 'input_file': self.input_file}, format="multipart")
         self.assertEqual(response.data, expected)
-        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
+        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
 
     def test_challenge_submission_for_successful_submission(self):
         self.url = reverse_lazy('jobs:challenge_submission',