diff --git a/lib/galaxy_test/driver/driver_util.py b/lib/galaxy_test/driver/driver_util.py index 88e956da5cfc..6fbfcee86d70 100644 --- a/lib/galaxy_test/driver/driver_util.py +++ b/lib/galaxy_test/driver/driver_util.py @@ -50,8 +50,6 @@ DEFAULT_WEB_HOST, target_url_parts, ) -from tool_shed.webapp.app import UniverseApplication as ToolshedUniverseApplication -from tool_shed.webapp.fast_app import initialize_fast_app as init_tool_shed_fast_app from .test_logging import logging_config_file galaxy_root = galaxy_directory() @@ -71,9 +69,8 @@ log = logging.getLogger("test_driver") -# Global variables to pass database contexts around - only needed for older +# Global variable to pass database contexts around - only needed for older # Tool Shed twill tests that didn't utilize the API for such interactions. -tool_shed_context = None install_context = None @@ -583,26 +580,6 @@ def build_galaxy_app(simple_kwargs) -> GalaxyUniverseApplication: return app -def build_shed_app(simple_kwargs): - """Build a Galaxy app object from a simple keyword arguments. - - Construct paste style complex dictionary. Also setup "global" reference - to sqlalchemy database context for tool shed database. - """ - log.info("Tool shed database connection: %s", simple_kwargs["database_connection"]) - # TODO: Simplify global_conf to match Galaxy above... - simple_kwargs["__file__"] = "tool_shed_wsgi.yml.sample" - simple_kwargs["global_conf"] = get_webapp_global_conf() - - app = ToolshedUniverseApplication(**simple_kwargs) - log.info("Embedded Toolshed application started") - - global tool_shed_context - tool_shed_context = app.model.context - - return app - - def explicitly_configured_host_and_port(prefix, config_object): host_env_key = f"{prefix}_TEST_HOST" port_env_key = f"{prefix}_TEST_PORT" @@ -758,7 +735,14 @@ def launch_gravity(port, gxit_port=None, galaxy_config=None): ) -def launch_server(app_factory, webapp_factory, prefix=DEFAULT_CONFIG_PREFIX, galaxy_config=None, config_object=None): +def launch_server( + app_factory, + webapp_factory, + prefix=DEFAULT_CONFIG_PREFIX, + galaxy_config=None, + config_object=None, + init_fast_app=init_galaxy_fast_app, +): name = prefix.lower() host, port = explicitly_configured_host_and_port(prefix, config_object) port = attempt_ports(port) @@ -792,12 +776,7 @@ def launch_server(app_factory, webapp_factory, prefix=DEFAULT_CONFIG_PREFIX, gal static_enabled=True, register_shutdown_at_exit=False, ) - if name == "galaxy": - asgi_app = init_galaxy_fast_app(wsgi_webapp, app) - elif name == "tool_shed": - asgi_app = init_tool_shed_fast_app(wsgi_webapp, app) - else: - raise NotImplementedError(f"Launching {name} not implemented") + asgi_app = init_fast_app(wsgi_webapp, app) server, port, thread = uvicorn_serve(asgi_app, host=host, port=port) set_and_wait_for_http_target(prefix, host, port, url_prefix=url_prefix) diff --git a/lib/tool_shed/test/base/driver.py b/lib/tool_shed/test/base/driver.py index b342a749f591..a4fa67efdfb5 100644 --- a/lib/tool_shed/test/base/driver.py +++ b/lib/tool_shed/test/base/driver.py @@ -11,6 +11,8 @@ from galaxy_test.driver import driver_util from tool_shed.test.base.api_util import get_admin_api_key from tool_shed.webapp import buildapp as toolshedbuildapp +from tool_shed.webapp.app import UniverseApplication as ToolshedUniverseApplication +from tool_shed.webapp.fast_app import initialize_fast_app as init_tool_shed_fast_app log = driver_util.build_logger() @@ -36,6 +38,29 @@ """ +# Global variable to pass database contexts around - only needed for older +# Tool Shed twill tests that didn't utilize the API for such interactions. +tool_shed_context = None + + +def build_shed_app(simple_kwargs): + """Build a Galaxy app object from a simple keyword arguments. + + Construct paste style complex dictionary. Also setup "global" reference + to sqlalchemy database context for tool shed database. + """ + log.info("Tool shed database connection: %s", simple_kwargs["database_connection"]) + # TODO: Simplify global_conf to match Galaxy above... + simple_kwargs["__file__"] = "tool_shed_wsgi.yml.sample" + simple_kwargs["global_conf"] = driver_util.get_webapp_global_conf() + + app = ToolshedUniverseApplication(**simple_kwargs) + log.info("Embedded Toolshed application started") + + global tool_shed_context + tool_shed_context = app.model.context + + return app class ToolShedTestDriver(driver_util.TestDriver): @@ -117,10 +142,11 @@ def _setup_local(self): # ---- Run tool shed webserver ------------------------------------------------------ # TODO: Needed for hg middleware ('lib/galaxy/webapps/tool_shed/framework/middleware/hg.py') tool_shed_server_wrapper = driver_util.launch_server( - app_factory=lambda: driver_util.build_shed_app(kwargs), + app_factory=lambda: build_shed_app(kwargs), webapp_factory=toolshedbuildapp.app_factory, galaxy_config=kwargs, prefix="TOOL_SHED", + init_fast_app=init_tool_shed_fast_app, ) self.server_wrappers.append(tool_shed_server_wrapper) tool_shed_test_host = tool_shed_server_wrapper.host diff --git a/lib/tool_shed/test/base/test_db_util.py b/lib/tool_shed/test/base/test_db_util.py index 03b1bbcc7550..f957cfe0ea2c 100644 --- a/lib/tool_shed/test/base/test_db_util.py +++ b/lib/tool_shed/test/base/test_db_util.py @@ -18,7 +18,7 @@ def sa_session(): - from galaxy_test.driver.driver_util import tool_shed_context as sa_session + from .driver import tool_shed_context as sa_session return sa_session