Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #106: Display error message while submitting when user doesn't participate in a challenge #258

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions evalai/utils/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
6 changes: 6 additions & 0 deletions tests/data/submission_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
"""
29 changes: 28 additions & 1 deletion tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):

Expand Down