-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from jmchilton/webhooks_reorg
Improve abstraction in webhook API tests.
- Loading branch information
Showing
17 changed files
with
37 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.