Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[24.0] Move tool shed specific driver function to tool_shed.test #18296

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 10 additions & 31 deletions lib/galaxy_test/driver/driver_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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


Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
28 changes: 27 additions & 1 deletion lib/tool_shed/test/base/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -36,6 +38,29 @@
<data_managers>
</data_managers>
"""
# 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):
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/tool_shed/test/base/test_db_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading