Skip to content

Commit

Permalink
Integration tests for handler assignment methods
Browse files Browse the repository at this point in the history
  • Loading branch information
natefoo committed Jan 4, 2019
1 parent b069108 commit df7f8b4
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 7 deletions.
6 changes: 5 additions & 1 deletion test/base/integration_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
tessting configuration.
"""
import os
from unittest import skip, TestCase
from unittest import skip, SkipTest, TestCase

from galaxy.tools.deps.commands import which
from galaxy.tools.verify.test_data import TestDataResolver
Expand Down Expand Up @@ -93,6 +93,10 @@ def _configure_app(cls):
```self._app``` can be used to access Galaxy core app.
"""

def _skip_unless_postgres(self):
if not self._app.config.database_connection.startswith("post"):
raise SkipTest("Test only valid for postgres")

@classmethod
def handle_galaxy_config_kwds(cls, galaxy_config_kwds):
"""Extension point for subclasses to modify arguments used to configure Galaxy.
Expand Down
12 changes: 12 additions & 0 deletions test/integration/handler_template_job_conf.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<job_conf>
<plugins>
<plugin id="local" type="runner" load="galaxy.jobs.runners.local:LocalJobRunner" workers="4"/>
</plugins>
<handlers{assign_with}{default}>
{handlers}
</handlers>
<destinations>
<destination id="local" runner="local"/>
</destinations>
</job_conf>
81 changes: 81 additions & 0 deletions test/integration/test_handler_assignment_methods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"""Integration tests for configurable job handler assignment methods."""

import os

from base import integration_util

SCRIPT_DIRECTORY = os.path.abspath(os.path.dirname(__file__))
HANDLER_TEMPLATE_JOB_CONFIG_FILE = os.path.join(SCRIPT_DIRECTORY, "handler_template_job_conf.xml")


class WritesConfig(object):

def _with_handlers_config(self, assign_with=None, default=None, handlers=None):
handlers = handlers or []
template = {
'assign_with': ' assign_with="%s"' % assign_with if assign_with is not None else '',
'default': ' default="%s"' % default if default is not None else '',
'handlers': '\n'.join([
'<handler id="{id}"{tags}/>'.format(
id=x['id'],
tags=' tags="%s"' % x['tags'] if 'tags' in x else ''
) for x in handlers]),
}
self.__write_config_from(HANDLER_TEMPLATE_JOB_CONFIG_FILE, template=template)

def __write_config_from(self, path, template=None):
template = template or {}
self.__write_config(open(path, "r").read().format(**template))

def __write_config(self, contents):
with open(self._app.config.job_config_file, "w") as f:
f.write(contents)


class BaseHandlerAssignmentMethodIntegrationTestCase(integration_util.IntegrationTestCase, WritesConfig):

framework_tool_and_types = True

@classmethod
def handle_galaxy_config_kwds(cls, config):
cls.jobs_directory = cls._test_driver.mkdtemp()
config["jobs_directory"] = cls.jobs_directory
config["job_config_file"] = os.path.join(cls.jobs_directory, "job_conf.xml")
# Disable tool dependency resolution.
config["tool_dependency_dir"] = "none"
config["enable_beta_mulled_containers"] = "true"


class DBPreassignHandlerAssignmentMethodIntegrationTestCase(BaseHandlerAssignmentMethodIntegrationTestCase):

def setUp(self):
self._with_handlers_config(assign_with='db-preassign', handlers=[{'id': 'main'}])
super(DBPreassignHandlerAssignmentMethodIntegrationTestCase, self).setUp()

def test_handler_assignment(self):
tool_id = 'config_vars'
self._run_tool_test(tool_id)


class DBTransactionIsolationHandlerAssignmentMethodIntegrationTestCase(BaseHandlerAssignmentMethodIntegrationTestCase):

def setUp(self):
self._with_handlers_config(assign_with='db-transaction-isolation', handlers=[{'id': 'main'}])
super(DBTransactionIsolationHandlerAssignmentMethodIntegrationTestCase, self).setUp()

def test_handler_assignment(self):
self._skip_unless_postgres()
tool_id = 'config_vars'
self._run_tool_test(tool_id)


class DBSkipLockedHandlerAssignmentMethodIntegrationTestCase(BaseHandlerAssignmentMethodIntegrationTestCase):

def setUp(self):
self._with_handlers_config(assign_with='db-skip-locked', handlers=[{'id': 'main'}])
super(DBSkipLockedHandlerAssignmentMethodIntegrationTestCase, self).setUp()

def test_handler_assignment(self):
self._skip_unless_postgres()
tool_id = 'config_vars'
self._run_tool_test(tool_id)
8 changes: 2 additions & 6 deletions test/integration/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_cleanup(self):
assert history_response.json()["purged"] is True, history_response.json()

def test_pgcleanup(self):
self._skip_if_not_postgres()
self._skip_unless_postgres()

script = "cleanup_datasets/pgcleanup.py"
self._scripts_check_argparse_help(script)
Expand Down Expand Up @@ -164,13 +164,9 @@ def test_galaxy_main(self):
self._scripts_check_argparse_help("galaxy-main")

def test_runtime_stats(self):
self._skip_if_not_postgres()
self._skip_unless_postgres()
self._scripts_check_argparse_help("runtime_stats.py")

def _skip_if_not_postgres(self):
if not self._app.config.database_connection.startswith("post"):
raise unittest.SkipTest("Test only valid for postgres")

def _scripts_check_argparse_help(self, script):
# Test imports and argparse response to --help with 0 exit code.
output = self._scripts_check_output(script, ["--help"])
Expand Down

0 comments on commit df7f8b4

Please sign in to comment.