-
Notifications
You must be signed in to change notification settings - Fork 63
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 #119: Add command & feature for Creating challenge. #149
base: master
Are you sure you want to change the base?
Changes from all commits
2974564
976caf9
5fabc5e
291f32a
720fec6
bf121ba
38b5ddf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import json | ||
import os | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @KhalidRmb can you arrange the imports in lexicographic order |
||
import responses | ||
|
||
from beautifultable import BeautifulTable | ||
|
@@ -971,3 +972,58 @@ def test_display_challenge_phase_split_list_with_string_argument(self): | |
result = runner.invoke(challenge, ["two", "participate", "3"]) | ||
response = result.output | ||
assert response == output | ||
|
||
|
||
class TestCreateChallenge(BaseTestClass): | ||
def setup(self): | ||
self.message = json.loads(challenge_response.create_challenge_result) | ||
|
||
url = "{}{}" | ||
responses.add( | ||
responses.POST, | ||
url.format(API_HOST_URL, URLS.create_challenge.value).format("4"), | ||
json=self.message, | ||
status=201, | ||
) | ||
|
||
@responses.activate | ||
def test_create_challenge_when_file_is_not_valid(self): | ||
expected = ( | ||
"Usage: challenges create [OPTIONS] TEAM\n" | ||
'\nError: Invalid value for "--file": Could not open file: file: No such file or directory\n' | ||
) | ||
runner = CliRunner() | ||
result = runner.invoke( | ||
challenges, ["create", "--file", "file", "4"] | ||
) | ||
response = result.output | ||
assert response == expected | ||
|
||
@responses.activate | ||
def test_create_challenge_when_file_and_id_are_valid(self): | ||
expected = 'Challenge Challenge Title has been created successfully and sent for review to EvalAI Admin.' | ||
|
||
runner = CliRunner() | ||
|
||
my_path = os.path.abspath(os.path.dirname(__file__)) | ||
file = os.path.join(my_path, "data") | ||
|
||
result = runner.invoke( | ||
challenges, ["create", "--file", "{}/test_zip_file.zip".format(file), "4"] | ||
) | ||
assert result.output.strip() == expected | ||
|
||
@responses.activate | ||
def test_create_challenge_when_id_is_not_valid(self): | ||
expected = ("Could not establish a connection to EvalAI." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @KhalidRmb not sure if this is the correct message for invalid challenge id, user should know the mistake is in challenge id. @RishabhJain2018 your input? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think he is referring to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am referring to the host team ID here. For a host id invalid message to be displayed, the API must send a message back saying why creation failed. Based on that we must modify the cli code. @RishabhJain2018 @Ram81 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I was referring to |
||
" Please check the Host URL.") | ||
|
||
runner = CliRunner() | ||
|
||
my_path = os.path.abspath(os.path.dirname(__file__)) | ||
file = os.path.join(my_path, "data") | ||
|
||
result = runner.invoke( | ||
challenges, ["create", "--file", "{}/test_zip_file.zip".format(file), "111"] | ||
) | ||
assert result.output.strip() == expected |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import json | ||
import os | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
import responses | ||
|
||
from click.testing import CliRunner | ||
|
@@ -320,6 +321,44 @@ def test_display_leaderboard_for_http_error_404(self): | |
assert response == expected | ||
|
||
|
||
class TestCreateChallengeWhenZipFileDoesNotExist(BaseTestClass): | ||
def setup(self): | ||
|
||
response_data = """ | ||
{ | ||
"error": "The zip file contents cannot be extracted. Please check the format!" | ||
} | ||
""" | ||
error_data = json.loads(response_data) | ||
url = "{}{}" | ||
responses.add( | ||
responses.POST, | ||
url.format(API_HOST_URL, URLS.create_challenge.value).format("4"), | ||
json=error_data, | ||
status=406, | ||
) | ||
|
||
@responses.activate | ||
def test_create_challenge_when_zip_file_does_not_exist(self): | ||
|
||
expected = ("\nError: The zip file contents cannot be extracted. Please check the format!\n" | ||
"\nUse `evalai challenges` to fetch the active challenges.\n" | ||
"\nUse `evalai challenge CHALLENGE phases` to fetch the " | ||
"active phases.\n\n" | ||
) | ||
runner = CliRunner() | ||
|
||
with runner.isolated_filesystem(): | ||
with open("test_file.txt", "w") as f: | ||
f.write("1 2 3 4 5 6") | ||
|
||
result = runner.invoke( | ||
challenges, ["create", "--file", "test_file.txt", "4"], | ||
) | ||
|
||
assert result.output == expected | ||
|
||
|
||
class TestSubmissionDetailsWhenObjectDoesNotExist(BaseTestClass): | ||
def setup(self): | ||
|
||
|
@@ -594,6 +633,12 @@ def setup(self): | |
|
||
# Challenge URLS | ||
|
||
responses.add( | ||
responses.POST, | ||
url.format(API_HOST_URL, URLS.create_challenge.value), | ||
body=RequestException("..."), | ||
) | ||
|
||
responses.add( | ||
responses.GET, | ||
url.format(API_HOST_URL, URLS.challenge_list.value), | ||
|
@@ -721,6 +766,14 @@ def setup(self): | |
body=RequestException("..."), | ||
) | ||
|
||
@responses.activate | ||
def test_create_challenge_for_request_exception(self): | ||
runner = CliRunner() | ||
my_path = os.path.abspath(os.path.dirname(__file__)) | ||
file = os.path.join(my_path, "data") | ||
result = runner.invoke(challenges, ["create", "--file", "{}/test_zip_file.zip".format(file), "4"]) | ||
assert result.exit_code == 1 | ||
|
||
@responses.activate | ||
def test_display_challenge_list_for_request_exception(self): | ||
runner = CliRunner() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KhalidRmb can we change this to a message like
invalid host team id
if the issue is with team id otherwise the request error messageThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will require modification in the API, since there's no code to send an apt response for invalid host id here: https://github.com/Cloud-CV/EvalAI/blob/d5f28ae941dae1e50e623a7b880fefbacea3ef4b/apps/challenges/views.py#L606
Based on it, we can modify the cli code.