Skip to content

Commit

Permalink
Fix error responses in submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
guyandtheworld committed Jul 6, 2018
1 parent dd97e07 commit 78e4f46
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
12 changes: 9 additions & 3 deletions evalai/utils/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def make_submission(challenge_id, phase_id, file):
except requests.exceptions.HTTPError as err:
if (response.status_code in EVALAI_ERROR_CODES):
validate_token(response.json())
echo(style("Error: {}".format(response.json()["error"]), fg="red", bold=True))
echo(style("\nError: {}".format(response.json()["error"]), fg="red", bold=True))
echo(style("\nUse `evalai challenges` to fetch the active challenges.", fg="red", bold=True))
echo(style("\nUse `evalai challenge CHALLENGE phases` to fetch the active phases.\n", fg="red", bold=True))
else:
echo(err)
sys.exit(1)
Expand Down Expand Up @@ -86,7 +88,9 @@ def display_my_submission_details(challenge_id, phase_id):
except requests.exceptions.HTTPError as err:
if (response.status_code in EVALAI_ERROR_CODES):
validate_token(response.json())
echo(style("Error: {}".format(response.json()["error"]), fg="red", bold=True))
echo(style("\nError: {}".format(response.json()["error"]), fg="red", bold=True))
echo(style("\nUse `evalai challenges` to fetch the active challenges.", fg="red", bold=True))
echo(style("\nUse `evalai challenge CHALLENGE phases` to fetch the active phases.\n", fg="red", bold=True))
else:
echo(err)
sys.exit(1)
Expand Down Expand Up @@ -131,7 +135,9 @@ def display_submission_details(submission_id):
except requests.exceptions.HTTPError as err:
if (response.status_code in EVALAI_ERROR_CODES):
validate_token(response.json())
echo(style("Error: {}".format(response.json()["error"]), fg="red", bold=True))
echo(style("\nError: {}".format(response.json()["error"]), fg="red", bold=True))
echo(style("\nUse `evalai challenge CHALLENGE phase PHASE submissions` "
"to view your submission.\n", fg="red", bold=True))
else:
echo(err)
sys.exit(1)
Expand Down
21 changes: 14 additions & 7 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,10 @@ def setup(self):
def test_display_submission_details_for_object_does_not_exist(self):
runner = CliRunner()
result = runner.invoke(submission, ['9'])
response = result.output.rstrip()
assert response == self.expected
response = result.output.strip()
expected = "{}\n\n{}".format(self.expected, "Use `evalai challenge CHALLENGE "
"phase PHASE submissions` to view your submission.")
assert response == expected

@responses.activate
def test_make_submission_for_object_does_not_exist(self):
Expand All @@ -223,8 +225,11 @@ def test_make_submission_for_object_does_not_exist(self):
f.write('1 2 3 4 5 6')

result = runner.invoke(challenge, ['1', 'phase', '2', 'submit', "test_file.txt"])
response = result.output.rstrip()
assert response == self.expected
response = result.output.strip()
expected = "{}\n\n{}".format(self.expected, "Use `evalai challenges` to fetch the active challenges.")
expected = "{}\n\n{}".format(expected, "Use `evalai challenge CHALLENGE phases` "
"to fetch the active phases.")
assert response == expected


class TestTeamsWhenObjectDoesNotExist(BaseTestClass):
Expand Down Expand Up @@ -380,7 +385,7 @@ def setup(self):

# Challenge URLS

responses.add(responses.GET, url.format(API_HOST_URL, URLS.challenge_list.value), body=Exception('...'))
responses.add(responses.GET, url.format(API_HOST_URL, URLS.challenge_list.value), body=RequestException('...'))

responses.add(responses.GET, url.format(API_HOST_URL, URLS.past_challenge_list.value), body=Exception('...'))

Expand Down Expand Up @@ -434,7 +439,8 @@ def setup(self):
def test_display_challenge_list_for_request_exception(self):
runner = CliRunner()
result = runner.invoke(challenges)
assert result.exit_code == -1
response = result.output.strip()
assert response == "..."

@responses.activate
def test_display_past_challenge_list_for_request_exception(self):
Expand All @@ -446,7 +452,8 @@ def test_display_past_challenge_list_for_request_exception(self):
def test_display_ongoing_challenge_list_for_request_exception(self):
runner = CliRunner()
result = runner.invoke(challenges, ['ongoing'])
assert result.exit_code == -1
response = result.output.strip()
assert response == "..."

@responses.activate
def test_display_future_challenge_list_for_request_exception(self):
Expand Down

0 comments on commit 78e4f46

Please sign in to comment.