diff --git a/evalai/utils/submissions.py b/evalai/utils/submissions.py index 19d9fc3e4..6cf4857cc 100644 --- a/evalai/utils/submissions.py +++ b/evalai/utils/submissions.py @@ -48,6 +48,14 @@ def make_submission(challenge_id, phase_id, file, submission_metadata={}): bold=True, ) ) + elif response.status_code == 403: + echo( + style( + "\n" + response.json()["error"] + "\n", + bold=True, + fg="red", + ) + ) else: echo(err) if "input_file" in response.json(): diff --git a/tests/data/submission_response.py b/tests/data/submission_response.py index e9ee30474..cb034e9b9 100644 --- a/tests/data/submission_response.py +++ b/tests/data/submission_response.py @@ -158,3 +158,9 @@ submission_result_file = """ [{"Total": 60, "Metric1": 61, "Metric2": 62, "Metric3": 63}] """ + +user_doesnt_participate_challenge_error = """ +{ + "error": "You haven't participated in the challenge" +} +""" diff --git a/tests/test_requests.py b/tests/test_requests.py index 6baa9101d..f20d639b5 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -11,7 +11,7 @@ from evalai.utils.config import API_HOST_URL from .base import BaseTestClass -from tests.data import challenge_response, teams_response +from tests.data import challenge_response, submission_response, teams_response class TestHTTPErrorRequests(BaseTestClass): @@ -344,6 +344,33 @@ def test_display_leaderboard_for_http_error_404(self): assert response == expected +class TestMakeSubmissionWhenUserDidntParticipate(BaseTestClass): + def setup(self): + + error_data = json.loads(submission_response.user_doesnt_participate_challenge_error) + url = "{}{}" + responses.add( + responses.POST, + url.format(API_HOST_URL, URLS.make_submission.value).format("1", "2"), + json=error_data, + status=403, + ) + + @responses.activate + def test_make_submission_when_submitting_to_challenges_user_doesnt_participate(self): + runner = CliRunner() + with runner.isolated_filesystem(): + with open("test_file.txt", "w") as f: + f.write("Test File") + result = runner.invoke(challenge, ["1", "phase", "2", "submit", "--file", "test_file.txt"], input="N") + response = result.output.rstrip() + expected = ( + "Do you want to include the Submission Details? [y/N]: N\n\n" + "You haven't participated in the challenge" + ) + assert response == expected + + class TestSubmissionDetailsWhenObjectDoesNotExist(BaseTestClass): def setup(self):