From 809c087a8a50e30c7606b7b09e8c989d2b3ed6c8 Mon Sep 17 00:00:00 2001 From: Evgeny Anatskiy Date: Tue, 24 Jan 2017 01:20:28 +0100 Subject: [PATCH] - add Webhooks tests - small code improvements --- lib/galaxy/webhooks/__init__.py | 11 ++++----- test/api/test_webhooks.py | 44 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 test/api/test_webhooks.py diff --git a/lib/galaxy/webhooks/__init__.py b/lib/galaxy/webhooks/__init__.py index 9aaa2b80a1a5..34da897bf6e7 100644 --- a/lib/galaxy/webhooks/__init__.py +++ b/lib/galaxy/webhooks/__init__.py @@ -34,16 +34,15 @@ def to_dict(self): class WebhooksRegistry(object): - def __init__(self, webhooks_directories): + def __init__(self, webhooks_dirs): self.webhooks = [] self.webhooks_directories = [] - for webhook_dir in config_directories_from_setting( - webhooks_directories): + for webhook_dir in config_directories_from_setting(webhooks_dirs): for plugin_dir in os.listdir(webhook_dir): - self.webhooks_directories.append( - os.path.join(webhook_dir, plugin_dir) - ) + path = os.path.join(webhook_dir, plugin_dir) + if os.path.isdir(path) and plugin_dir != 'demo': + self.webhooks_directories.append(path) self.load_webhooks() diff --git a/test/api/test_webhooks.py b/test/api/test_webhooks.py new file mode 100644 index 000000000000..424f01e8e94b --- /dev/null +++ b/test/api/test_webhooks.py @@ -0,0 +1,44 @@ +import os + +from base import api +from galaxy.app import app +from galaxy.util import galaxy_root_path +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) + + 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) + + def test_get_random(self): + response = self._get('webhooks/tool') + self._assert_status_code_is(response, 200) + + 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 + ] + + self._assert_status_code_is(response, 200) + self.assertEqual(response.json(), webhooks) + + 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')