Move construction of test driver app objects into driver_util.

This de-duplicates some of the Galaxy stuff and makes the tool shed stuff look very uniform.
This commit is contained in:
John Chilton
2016-03-29 08:04:25 -04:00
parent ec0a123849
commit ecbb732665
3 changed files with 48 additions and 44 deletions
+1 -13
View File
@@ -19,9 +19,6 @@ log = driver_util.build_logger()
from base.api_util import get_master_api_key, get_user_api_key
from base.test_logging import logging_config_file
from functional import database_contexts
from galaxy.app import UniverseApplication
from galaxy.util.properties import load_app_properties
from galaxy.web import buildapp
default_galaxy_test_host = "localhost"
@@ -109,16 +106,7 @@ def main():
if datatypes_conf_override:
kwargs[ 'datatypes_config_file' ] = datatypes_conf_override
# Set the global_conf[ '__file__' ] option to the location of the temporary .ini file, which gets passed to set_metadata.sh.
kwargs[ 'global_conf' ] = driver_util.get_webapp_global_conf()
kwargs[ 'global_conf' ][ '__file__' ] = "config/galaxy.ini.sample"
kwargs = load_app_properties(
kwds=kwargs
)
# Build the Universe Application
app = UniverseApplication( **kwargs )
database_contexts.galaxy_context = app.model.context
log.info( "Embedded Universe application started" )
app = driver_util.build_galaxy_app(kwargs)
# ---- Run webserver ------------------------------------------------------
server = None
+42
View File
@@ -25,7 +25,12 @@ from .tool_shed_util import parse_tool_panel_config
from .nose_util import run
from .instrument import StructuredTestDataPlugin
from functional import database_contexts
from galaxy.app import UniverseApplication as GalaxyUniverseApplication
from galaxy.webapps.tool_shed.app import UniverseApplication as ToolshedUniverseApplication
from galaxy.util import asbool
from galaxy.util.properties import load_app_properties
galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir))
GALAXY_TEST_DIRECTORY = os.path.join(galaxy_root, "test")
@@ -361,6 +366,43 @@ def setup_shed_tools_for_test(app, galaxy_tool_shed_test_file, testing_migrated_
app.toolbox = tools.ToolBox(tool_configs, app.config.tool_path, app)
def build_galaxy_app(simple_kwargs):
"""Build a Galaxy app object from a simple keyword arguments.
Construct paste style complex dictionary and use load_app_properties so
Galaxy override variables are respected. Also setup "global" references
to sqlalchemy database context for Galaxy and install databases.
"""
log.info("Galaxy database connection:", simple_kwargs["database_connection"])
simple_kwargs['global_conf'] = get_webapp_global_conf()
simple_kwargs['global_conf']['__file__'] = "config/galaxy.ini.sample"
simple_kwargs = load_app_properties(
kwds=simple_kwargs
)
# Build the Universe Application
app = GalaxyUniverseApplication( **simple_kwargs )
log.info( "Embedded Galaxy application started" )
database_contexts.galaxy_context = app.model.context
database_contexts.install_context = app.install_model.context
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:", simple_kwargs["database_connection"])
# TODO: Simplify global_conf to match Galaxy above...
simple_kwargs['__file__'] = 'tool_shed_wsgi.ini.sample'
simple_kwargs['global_conf'] = get_webapp_global_conf()
app = ToolshedUniverseApplication( **simple_kwargs )
database_contexts.tool_shed_context = app.model.context
log.info( "Embedded Toolshed application started" )
return app
__all__ = [
"cleanup_directory",
"configure_environment",
+5 -31
View File
@@ -21,13 +21,7 @@ tool_shed_test_tmp_dir = driver_util.setup_tool_shed_tmp_dir()
# This is for the tool shed application.
from galaxy.webapps.tool_shed import buildapp as toolshedbuildapp
from galaxy.webapps.tool_shed.app import UniverseApplication as ToolshedUniverseApplication
# This is for the galaxy application.
from galaxy.app import UniverseApplication as GalaxyUniverseApplication
from galaxy.web import buildapp as galaxybuildapp
from galaxy.util.properties import load_app_properties
from functional import database_contexts
default_tool_shed_test_host = "localhost"
default_galaxy_test_host = 'localhost'
@@ -89,14 +83,11 @@ def main():
os.environ[ 'TEST_HG_WEB_CONFIG_DIR' ] = hgweb_config_dir
print "Directory location for hgweb.config:", hgweb_config_dir
toolshed_database_conf = driver_util.database_conf(shed_db_path, prefix="TOOL_SHED")
tool_shed_global_conf = driver_util.get_webapp_global_conf()
tool_shed_global_conf[ '__file__' ] = 'tool_shed_wsgi.ini.sample'
kwargs = dict( admin_users='test@bx.psu.edu',
allow_user_creation=True,
allow_user_deletion=True,
datatype_converters_config_file='datatype_converters_conf.xml.sample',
file_path=shed_file_path,
global_conf=tool_shed_global_conf,
hgweb_config_dir=hgweb_config_dir,
job_queue_workers=5,
id_secret='changethisinproductiontoo',
@@ -111,25 +102,19 @@ def main():
tool_data_table_config_path=galaxy_tool_data_table_conf_file,
use_heartbeat=False )
kwargs.update(toolshed_database_conf)
print "Tool shed database connection:", toolshed_database_conf["database_connection"]
# Generate the tool_data_table_conf.xml file.
file( galaxy_tool_data_table_conf_file, 'w' ).write( tool_data_table_conf_xml_template )
# Generate the shed_tool_data_table_conf.xml file.
file( shed_tool_data_table_conf_file, 'w' ).write( tool_data_table_conf_xml_template )
os.environ[ 'TOOL_SHED_TEST_TOOL_DATA_TABLE_CONF' ] = shed_tool_data_table_conf_file
# ---- Build Tool Shed Application --------------------------------------------------
toolshedapp = None
kwargs[ 'global_conf' ] = tool_shed_global_conf
toolshedapp = ToolshedUniverseApplication( **kwargs )
database_contexts.tool_shed_context = toolshedapp.model.context
log.info( "Embedded Toolshed application started" )
toolshedapp = driver_util.build_shed_app(kwargs)
# ---- Run tool shed webserver ------------------------------------------------------
# TODO: Needed for hg middleware ('lib/galaxy/webapps/tool_shed/framework/middleware/hg.py')
tool_shed_global_conf[ 'database_connection' ] = kwargs["database_connection"]
toolshedwebapp = toolshedbuildapp.app_factory( tool_shed_global_conf,
kwargs['global_conf']['database_connection'] = kwargs["database_connection"]
toolshedwebapp = toolshedbuildapp.app_factory( kwargs['global_conf'],
use_translogger=False,
static_enabled=True,
app=toolshedapp )
@@ -170,25 +155,14 @@ def main():
tool_data_table_config_path=galaxy_tool_data_table_conf_file )
kwargs.update(driver_util.setup_galaxy_config(galaxy_db_path, use_test_file_dir=False, default_install_db_merged=False))
print "Galaxy database connection:", kwargs["database_connection"]
# Set the global_conf[ '__file__' ] option to the location of the temporary .ini file, which gets passed to set_metadata.sh.
kwargs[ 'global_conf' ] = driver_util.get_webapp_global_conf()
kwargs[ 'global_conf' ][ '__file__' ] = "config/galaxy.ini.sample"
kwargs = load_app_properties(
kwds=kwargs
)
# Build the Universe Application
galaxyapp = GalaxyUniverseApplication( **kwargs )
log.info( "Embedded Galaxy application started" )
# ---- Run galaxy webserver ------------------------------------------------------
galaxy_server = None
galaxyapp = driver_util.build_galaxy_app(kwargs)
galaxywebapp = galaxybuildapp.app_factory( kwargs['global_conf'],
use_translogger=False,
static_enabled=True,
app=galaxyapp )
database_contexts.galaxy_context = galaxyapp.model.context
database_contexts.install_context = galaxyapp.install_model.context
galaxy_server, galaxy_test_port = driver_util.serve_webapp(
galaxywebapp, host=galaxy_test_host, port=galaxy_test_port
)