From 1509cca3ef2224bfbd846fbcbda7e27c37554daa Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Tue, 5 Jan 2021 16:07:01 +0000 Subject: [PATCH] Fix API tests failing when usegalaxy.org is down `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. --- lib/galaxy_test/api/test_tools_upload.py | 8 +++++++- lib/galaxy_test/base/populators.py | 17 +++++++++-------- .../selenium/test_workflow_editor.py | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/galaxy_test/api/test_tools_upload.py b/lib/galaxy_test/api/test_tools_upload.py index 5a4c443428ee..af035505f090 100644 --- a/lib/galaxy_test/api/test_tools_upload.py +++ b/lib/galaxy_test/api/test_tools_upload.py @@ -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, @@ -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'] diff --git a/lib/galaxy_test/base/populators.py b/lib/galaxy_test/base/populators.py index 404edb28c349..b3dba9338a20 100644 --- a/lib/galaxy_test/base/populators.py +++ b/lib/galaxy_test/base/populators.py @@ -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 diff --git a/lib/galaxy_test/selenium/test_workflow_editor.py b/lib/galaxy_test/selenium/test_workflow_editor.py index d410d98b3efe..b7b9247bcdf9 100644 --- a/lib/galaxy_test/selenium/test_workflow_editor.py +++ b/lib/galaxy_test/selenium/test_workflow_editor.py @@ -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()