Skip to content

Commit

Permalink
Fix API tests failing when usegalaxy.org is down
Browse files Browse the repository at this point in the history
`site_down` was broken when a `requests.get()` raises a timeout exception
(should have returned `True`), so I've inverted the logic to check if
the site is up, which is more natural.

Added a proper test for uploading an invalid URL, renamed the one which was
actually testing a 404 HTTP error.
  • Loading branch information
nsoranzo committed Jan 5, 2021
1 parent 2c9e89a commit 1509cca
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
8 changes: 7 additions & 1 deletion lib/galaxy_test/api/test_tools_upload.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json

import pytest

from galaxy.tool_util.verify.test_data import TestDataResolver
from galaxy_test.base.constants import (
ONE_TO_SIX_ON_WINDOWS,
Expand Down Expand Up @@ -754,8 +756,12 @@ def test_upload_force_composite(self):
assert extra_file["path"] == "composite"
assert extra_file["class"] == "File"

@skip_if_site_down("https://usegalaxy.org")
def test_upload_from_invalid_url(self):
with pytest.raises(AssertionError):
self._upload('https://foo.invalid', assert_ok=False)

@skip_if_site_down("https://usegalaxy.org")
def test_upload_from_404_url(self):
history_id, new_dataset = self._upload('https://usegalaxy.org/bla123', assert_ok=False)
dataset_details = self.dataset_populator.get_history_dataset_details(history_id, dataset_id=new_dataset["id"], assert_ok=False)
assert dataset_details['state'] == 'error', "expected dataset state to be 'error', but got '%s'" % dataset_details['state']
Expand Down
17 changes: 9 additions & 8 deletions lib/galaxy_test/base/populators.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,20 @@ def wrapped_method(api_test_case, *args, **kwargs):
return method_wrapper


def skip_if_site_down(url):
def is_site_up(url):
try:
response = requests.get(url, timeout=10)
return response.status_code == 200
except Exception:
return False

def site_down():
try:
response = requests.get(url, timeout=10)
return response.status_code != 200
except Exception:
return False

def skip_if_site_down(url):

def method_wrapper(method):
@wraps(method)
def wrapped_method(api_test_case, *args, **kwargs):
_raise_skip_if(site_down(), "Test depends on [%s] being up and it appears to be down." % url)
_raise_skip_if(not is_site_up(url), f"Test depends on [{url}] being up and it appears to be down.")
method(api_test_case, *args, **kwargs)

return wrapped_method
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy_test/selenium/test_workflow_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def test_non_data_connections(self):
# Also the connector should disappear
tool_input.wait_for_absent_or_hidden()

# Now make it connected again and watch the requestss
# Now make it connected again and watch the requests
connect_icon.wait_for_and_click()

tool_input.wait_for_visible()
Expand Down

0 comments on commit 1509cca

Please sign in to comment.