Skip to content

Commit

Permalink
- add Webhooks tests
Browse files Browse the repository at this point in the history
- small code improvements
  • Loading branch information
anatskiy committed Jan 24, 2017
1 parent 36895d1 commit 809c087
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/galaxy/webhooks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
44 changes: 44 additions & 0 deletions test/api/test_webhooks.py
Original file line number Diff line number Diff line change
@@ -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')

0 comments on commit 809c087

Please sign in to comment.