mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-25 10:24:38 +08:00
53 lines
2.1 KiB
Python
53 lines
2.1 KiB
Python
import random
|
|
from typing import List
|
|
|
|
from ._framework import ApiTestCase
|
|
|
|
|
|
class DisplayApplicationsApiTestCase(ApiTestCase):
|
|
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")
|
|
|
|
def test_reload_as_admin(self):
|
|
response = self._post("display_applications/reload", admin=True)
|
|
self._assert_status_code_is(response, 200)
|
|
|
|
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)
|
|
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)
|
|
|
|
def test_reload_unknow_returns_as_failed(self):
|
|
unknown_id = "unknown"
|
|
payload = {"ids": [unknown_id]}
|
|
response = self._post("display_applications/reload", payload, admin=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
|
|
|
|
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
|