From cf2262ffdd50207b0a7f845b9a2c9519a47423c1 Mon Sep 17 00:00:00 2001 From: Takitsuse Nagisa Date: Thu, 16 Jan 2020 22:53:17 +0900 Subject: [PATCH 1/4] Display error message --- evalai/utils/submissions.py | 8 ++++++++ 1 file changed, 8 insertions(+) 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(): From 246f024988f7dc5059db124de60cd825aaf8833e Mon Sep 17 00:00:00 2001 From: Takitsuse Nagisa Date: Thu, 16 Jan 2020 23:16:11 +0900 Subject: [PATCH 2/4] Add tests --- tests/data/submission_response.py | 6 ++++++ tests/test_requests.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/tests/data/submission_response.py b/tests/data/submission_response.py index e9ee30474..32aec1b6a 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" +} +""" \ No newline at end of file diff --git a/tests/test_requests.py b/tests/test_requests.py index 6baa9101d..768b1856a 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 TestMakeSubmissionWhenSubmittingToChallengesUserDoesntParticipate(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): From f55219eec730d64b7bbe9cf62aab7a2643b4cf2f Mon Sep 17 00:00:00 2001 From: Takitsuse Nagisa Date: Thu, 16 Jan 2020 23:17:47 +0900 Subject: [PATCH 3/4] Fix flake8 error --- tests/data/submission_response.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/data/submission_response.py b/tests/data/submission_response.py index 32aec1b6a..cb034e9b9 100644 --- a/tests/data/submission_response.py +++ b/tests/data/submission_response.py @@ -163,4 +163,4 @@ { "error": "You haven't participated in the challenge" } -""" \ No newline at end of file +""" From e71ac3c586182dde3719c87a11c28557bee95f80 Mon Sep 17 00:00:00 2001 From: Takitsuse Nagisa Date: Fri, 17 Jan 2020 21:56:45 +0900 Subject: [PATCH 4/4] Rename test class to TestMakeSubmissionWhenUserDidntParticipate --- tests/test_requests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_requests.py b/tests/test_requests.py index 768b1856a..f20d639b5 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -344,7 +344,7 @@ def test_display_leaderboard_for_http_error_404(self): assert response == expected -class TestMakeSubmissionWhenSubmittingToChallengesUserDoesntParticipate(BaseTestClass): +class TestMakeSubmissionWhenUserDidntParticipate(BaseTestClass): def setup(self): error_data = json.loads(submission_response.user_doesnt_participate_challenge_error)