From e2ffaf014cad6eb0a86db29b3145aa69bb5b9318 Mon Sep 17 00:00:00 2001 From: paulzierep Date: Thu, 13 Jun 2024 09:22:08 +0200 Subject: [PATCH] fix and test for fix (#115) * fix and test for fix * check cached server * lint -improved exception --- bin/extract_galaxy_tools.py | 15 +++++++++---- bin/tests/test_get_public_server.py | 35 +++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 bin/tests/test_get_public_server.py diff --git a/bin/extract_galaxy_tools.py b/bin/extract_galaxy_tools.py index b0e42de0..aa71d70a 100644 --- a/bin/extract_galaxy_tools.py +++ b/bin/extract_galaxy_tools.py @@ -484,10 +484,17 @@ def get_all_installed_tool_ids_on_server(galaxy_url: str) -> List[str]: """ galaxy_url = galaxy_url.rstrip("/") base_url = f"{galaxy_url}/api" - r = requests.get(f"{base_url}/tools", params={"in_panel": False}) - r.raise_for_status() - tool_dict_list = r.json() - return [tool_dict["id"] for tool_dict in tool_dict_list] + + try: + r = requests.get(f"{base_url}/tools", params={"in_panel": False}) + r.raise_for_status() + tool_dict_list = r.json() + tools = [tool_dict["id"] for tool_dict in tool_dict_list] + return tools + except Exception as ex: + print(f"Server query failed with: \n {ex}") + print(f"Could not query tools on server {galaxy_url}, all tools from this server will be set to 0!") + return [] def check_tools_on_servers(tool_ids: List[str], galaxy_server_url: str) -> int: diff --git a/bin/tests/test_get_public_server.py b/bin/tests/test_get_public_server.py new file mode 100644 index 00000000..a78f3225 --- /dev/null +++ b/bin/tests/test_get_public_server.py @@ -0,0 +1,35 @@ +###################################### +# Initial start for function based unit tests +# need to set this up using a proper testing framework +###################################### + +import os +import sys + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from extract_galaxy_tools import ( + check_tools_on_servers, + USEGALAXY_SERVER_URLS, +) + +server_url = USEGALAXY_SERVER_URLS["UseGalaxy.eu"] +tool_ids = ["abricate"] + +count = check_tools_on_servers(tool_ids, server_url) +print(count) + +tool_ids = ["bla"] +count = check_tools_on_servers(tool_ids, server_url) +print(count) + +server_url = "https://jolo.eu" +tool_ids = ["bla"] +count = check_tools_on_servers(tool_ids, server_url) +print(count) + +# test the cache ! +server_url = "https://jolo.eu" +tool_ids = ["bla", "blub"] +count = check_tools_on_servers(tool_ids, server_url) +print(count)