Skip to content

Commit

Permalink
fix and test for fix (#115)
Browse files Browse the repository at this point in the history
* fix and test for fix

* check cached server

* lint -improved exception
  • Loading branch information
paulzierep authored Jun 13, 2024
1 parent 67adcf5 commit e2ffaf0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
15 changes: 11 additions & 4 deletions bin/extract_galaxy_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
35 changes: 35 additions & 0 deletions bin/tests/test_get_public_server.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit e2ffaf0

Please sign in to comment.