Warning
This document is for an in-development version of Galaxy. You can alternatively view this page in the latest release if it exists or view the top of the latest release's documentation.
Source code for galaxy_test.api.test_display_applications
import random
from typing import List
from galaxy.util import UNKNOWN
from galaxy_test.base.decorators import requires_admin
from ._framework import ApiTestCase
[docs]class TestDisplayApplicationsApi(ApiTestCase):
[docs] def test_index(self):
response = self._get("display_applications")
self._assert_status_code_is(response, 200)
as_list = response.json()
assert isinstance(as_list, list)
assert len(as_list) > 0
for display_app in as_list:
self._assert_has_keys(display_app, "id", "name", "version", "filename_", "links")
[docs] @requires_admin
def test_reload_as_admin(self):
response = self._post("display_applications/reload", admin=True)
self._assert_status_code_is(response, 200)
[docs] @requires_admin
def test_reload_with_some_ids(self):
response = self._get("display_applications")
self._assert_status_code_is(response, 200)
display_apps = response.json()
all_ids = [display_app["id"] for display_app in display_apps]
input_ids = self._get_half_random_items(all_ids)
payload = {"ids": input_ids}
response = self._post("display_applications/reload", payload, admin=True, json=True)
self._assert_status_code_is(response, 200)
reloaded = response.json()["reloaded"]
assert len(reloaded) == len(input_ids)
assert all(elem in reloaded for elem in input_ids)
[docs] @requires_admin
def test_reload_unknown_returns_as_failed(self):
unknown_id = UNKNOWN
payload = {"ids": [unknown_id]}
response = self._post("display_applications/reload", payload, admin=True, json=True)
self._assert_status_code_is(response, 200)
reloaded = response.json()["reloaded"]
failed = response.json()["failed"]
assert len(reloaded) == 0
assert len(failed) == 1
assert unknown_id in failed
[docs] def test_reload_as_non_admin_returns_403(self):
response = self._post("display_applications/reload")
self._assert_status_code_is(response, 403)
def _get_half_random_items(self, collection: List[str]) -> List[str]:
half_num_items = int(len(collection) / 2)
rval = random.sample(collection, half_num_items)
return rval