Skip to content

Commit

Permalink
Merge pull request #3 from jmchilton/webhooks_reorg
Browse files Browse the repository at this point in the history
Improve abstraction in webhook API tests.
  • Loading branch information
anatskiy authored Jan 24, 2017
2 parents 809c087 + 8b30d87 commit a9ba71c
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 21 deletions.
5 changes: 3 additions & 2 deletions config/galaxy.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,9 @@ paste.app_factory = galaxy.web.buildapp:app_factory
# Webhooks directory: where to store webhooks - plugins to extend the Galaxy UI.
# By default none will be loaded. Set to config/plugins/webhooks/demo to load Galaxy's
# demo webhooks. To use an absolute path begin the path with '/'. This is a comma
# separated list.
# webhooks_dir = config/plugins/webhooks
# separated list. Add test/functional/webhooks to this list to include the demo webhooks
# used to test the webhook framework.
#webhooks_dir = config/plugins/webhooks

# Each job is given a unique empty directory as its current working directory.
# This option defines in what parent directory those directories will be
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/webhooks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, webhooks_dirs):
for webhook_dir in config_directories_from_setting(webhooks_dirs):
for plugin_dir in os.listdir(webhook_dir):
path = os.path.join(webhook_dir, plugin_dir)
if os.path.isdir(path) and plugin_dir != 'demo':
if os.path.isdir(path):
self.webhooks_directories.append(path)

self.load_webhooks()
Expand Down
1 change: 1 addition & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ then
export GALAXY_CONFIG_OVERRIDE_TOOL_CONFIG_FILE="test/functional/tools/samples_tool_conf.xml"
export GALAXY_CONFIG_ENABLE_BETA_WORKFLOW_MODULES="true"
export GALAXY_CONFIG_OVERRIDE_ENABLE_BETA_TOOL_FORMATS="true"
export GALAXY_CONFIG_OVERRIDE_WEBHOOKS_DIR="test/functional/webhooks"
fi

if [ -n "$GALAXY_UNIVERSE_CONFIG_DIR" ]; then
Expand Down
48 changes: 30 additions & 18 deletions test/api/test_webhooks.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,56 @@
import os

from base import api
from galaxy.app import app
from galaxy.util import galaxy_root_path
from base.driver_util import TEST_WEBHOOKS_DIR
from galaxy.webhooks import WebhooksRegistry

WEBHOOKS_DEMO_DIRECTORY = os.path.join(
galaxy_root_path, 'config', 'plugins', 'webhooks', 'demo',
)


class WebhooksApiTestCase(api.ApiTestCase):

def setUp(self):
super(WebhooksApiTestCase, self).setUp()
app.webhooks_registry = WebhooksRegistry(WEBHOOKS_DEMO_DIRECTORY)
self.webhooks_registry = WebhooksRegistry(TEST_WEBHOOKS_DIR)

def test_get_all(self):
response = self._get('webhooks')
webhooks = [wh.to_dict() for wh in app.webhooks_registry.webhooks]

self._assert_status_code_is(response, 200)
self.assertEqual(response.json(), webhooks)
webhook_objs = self._assert_are_webhooks(response)
names = self._get_webhook_names(webhook_objs)
for expected_name in ["history_test1", "history_test2", "masthead_test", "phdcomics", "trans_object", "xkcd"]:
assert expected_name in names

def test_get_random(self):
response = self._get('webhooks/tool')
self._assert_status_code_is(response, 200)
self._assert_is_webhook(response.json())

def test_get_all_by_type(self):
webhook_type = 'tool'
response = self._get('webhooks/%s/all' % webhook_type)
webhooks = [
wh.to_dict()
for wh in app.webhooks_registry.webhooks
if webhook_type in wh.type
]
# Ensure tool type filtering include a valid webhook of type tool and excludes a webhook
# that isn't of type tool.
response = self._get('webhooks/tool/all')

self._assert_status_code_is(response, 200)
self.assertEqual(response.json(), webhooks)
webhook_objs = self._assert_are_webhooks(response)
names = self._get_webhook_names(webhook_objs)
assert "phdcomics" in names
assert "trans_object" not in names # properly filtered out by type

def test_get_data(self):
response = self._get('webhooks/trans_object/get_data')
self._assert_status_code_is(response, 200)
self._assert_has_keys(response.json(), 'username')

def _assert_are_webhooks(self, response):
response_list = response.json()
assert isinstance(response_list, list)
for obj in response_list:
self._assert_is_webhook(obj)
return response_list

def _assert_is_webhook(self, obj):
assert isinstance(obj, dict)
self._assert_has_keys(obj, 'styles', 'activate', 'name', 'script', 'type', 'config')

def _get_webhook_names(self, webhook_objs):
names = [w.get("name") for w in webhook_objs]
return names
2 changes: 2 additions & 0 deletions test/base/driver_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
GALAXY_TEST_DIRECTORY = os.path.join(galaxy_root, "test")
GALAXY_TEST_FILE_DIR = "test-data,https://github.com/galaxyproject/galaxy-test-data.git"
TOOL_SHED_TEST_DATA = os.path.join(GALAXY_TEST_DIRECTORY, "shed_functional", "test_data")
TEST_WEBHOOKS_DIR = os.path.join(galaxy_root, "test", "functional", "webhooks")
FRAMEWORK_TOOLS_DIR = os.path.join(GALAXY_TEST_DIRECTORY, "functional", "tools")
FRAMEWORK_UPLOAD_TOOL_CONF = os.path.join(FRAMEWORK_TOOLS_DIR, "upload_tool_conf.xml")
FRAMEWORK_SAMPLE_TOOLS_CONF = os.path.join(FRAMEWORK_TOOLS_DIR, "samples_tool_conf.xml")
Expand Down Expand Up @@ -197,6 +198,7 @@ def setup_galaxy_config(
use_tasked_jobs=True,
use_heartbeat=False,
user_library_import_dir=user_library_import_dir,
webhooks_dir=TEST_WEBHOOKS_DIR,
)
config.update(database_conf(tmpdir))
config.update(install_database_conf(tmpdir, default_merged=default_install_db_merged))
Expand Down

0 comments on commit a9ba71c

Please sign in to comment.