From 3a9596a66fd9f959387e19cf37843383114ca414 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Sat, 16 Jan 2021 14:45:14 -0500 Subject: [PATCH] Cleanup galaxy_test.base.api_util. - Rename get_master_api_key to get_admin_api_key - less offesnive and more accurate since it doesn't need to be the bootstrap key. - Add types and cleanup docstrings. --- lib/galaxy/selenium/context.py | 3 ++- lib/galaxy_test/base/api.py | 4 ++-- lib/galaxy_test/base/api_util.py | 19 +++++++++++-------- lib/galaxy_test/driver/driver_util.py | 8 ++++---- lib/tool_shed/test/base/twilltestcase.py | 12 ++++++------ scripts/functional_tests.py | 4 ++-- 6 files changed, 27 insertions(+), 23 deletions(-) diff --git a/lib/galaxy/selenium/context.py b/lib/galaxy/selenium/context.py index 1b759128a1c..9119269427b 100644 --- a/lib/galaxy/selenium/context.py +++ b/lib/galaxy/selenium/context.py @@ -1,3 +1,4 @@ +from typing import Optional from six.moves.urllib.parse import urljoin from .driver_factory import ConfiguredDriver @@ -36,7 +37,7 @@ class GalaxySeleniumContext(NavigatesGalaxy): class GalaxySeleniumContextImpl(GalaxySeleniumContext): """Minimal, simplified GalaxySeleniumContext useful outside the context of test cases.""" - def __init__(self, from_dict=None): + def __init__(self, from_dict: Optional[dict] = None) -> None: from_dict = from_dict or {} self.configured_driver = ConfiguredDriver(**from_dict.get("driver", {})) self.url = from_dict.get("local_galaxy_url", "http://localhost:8080") diff --git a/lib/galaxy_test/base/api.py b/lib/galaxy_test/base/api.py index a9c4fdbcd5d..f7c47ba7844 100644 --- a/lib/galaxy_test/base/api.py +++ b/lib/galaxy_test/base/api.py @@ -11,7 +11,7 @@ from .api_asserts import ( ) from .api_util import ( ADMIN_TEST_USER, - get_master_api_key, + get_admin_api_key, get_user_api_key, OTHER_USER, TEST_USER, @@ -42,7 +42,7 @@ class UsesApiTestCaseMixin: def _setup_interactor(self): self.user_api_key = get_user_api_key() - self.master_api_key = get_master_api_key() + self.master_api_key = get_admin_api_key() self.galaxy_interactor = self._get_interactor() def _get_interactor(self, api_key=None): diff --git a/lib/galaxy_test/base/api_util.py b/lib/galaxy_test/base/api_util.py index d97377d1374..ace95c9b9d4 100644 --- a/lib/galaxy_test/base/api_util.py +++ b/lib/galaxy_test/base/api_util.py @@ -1,4 +1,5 @@ import os +from typing import Optional DEFAULT_GALAXY_MASTER_API_KEY = "TEST123" DEFAULT_GALAXY_USER_API_KEY = None @@ -12,10 +13,11 @@ ADMIN_TEST_USER = os.environ.get("GALAXY_TEST_ADMIN_USER_EMAIL", DEFAULT_ADMIN_T OTHER_USER = os.environ.get("GALAXY_TEST_OTHER_USER_EMAIL", DEFAULT_OTHER_USER) -def get_master_api_key(): - """ Test master API key to use for functional test. This key should be - configured as a master API key and should be able to create additional - users and keys. +def get_admin_api_key() -> str: + """Test admin API key to use for functional tests. + + This key should be configured as a admin API key and should be able + to create additional users and keys. """ for key in ["GALAXY_CONFIG_MASTER_API_KEY", "GALAXY_CONFIG_OVERRIDE_MASTER_API_KEY"]: value = os.environ.get(key, None) @@ -24,9 +26,10 @@ def get_master_api_key(): return DEFAULT_GALAXY_MASTER_API_KEY -def get_user_api_key(): - """ Test user API key to use for functional tests. If set, this should drive - API based testing - if not set master API key should be used to create a new - user and API key for tests. +def get_user_api_key() -> Optional[str]: + """Test user API key to use for functional tests. + + If set, this should drive API based testing - if not set an admin API key will + be used to create a new user and API key for tests. """ return os.environ.get("GALAXY_TEST_USER_API_KEY", DEFAULT_GALAXY_USER_API_KEY) diff --git a/lib/galaxy_test/driver/driver_util.py b/lib/galaxy_test/driver/driver_util.py index 98751f28ab0..c61922bccb0 100644 --- a/lib/galaxy_test/driver/driver_util.py +++ b/lib/galaxy_test/driver/driver_util.py @@ -35,7 +35,7 @@ from galaxy.tool_util.verify.interactor import GalaxyInteractorApi, verify_tool from galaxy.util import asbool, download_to_file, galaxy_directory from galaxy.util.properties import load_app_properties from galaxy.web import buildapp -from galaxy_test.base.api_util import get_master_api_key, get_user_api_key +from galaxy_test.base.api_util import get_admin_api_key, get_user_api_key from galaxy_test.base.env import ( DEFAULT_WEB_HOST, target_url_parts, @@ -188,7 +188,7 @@ def setup_galaxy_config( data_manager_config_file = 'test/functional/tools/sample_data_manager_conf.xml' if default_data_manager_config is not None: data_manager_config_file = f"{default_data_manager_config},{data_manager_config_file}" - master_api_key = get_master_api_key() + master_api_key = get_admin_api_key() cleanup_job = 'never' if ("GALAXY_TEST_NO_CLEANUP" in os.environ or "TOOL_SHED_TEST_NO_CLEANUP" in os.environ) else 'onsuccess' @@ -1126,7 +1126,7 @@ class GalaxyTestDriver(TestDriver): test_classes = functional.test_toolbox.build_tests( app=self.app, testing_shed_tools=testing_shed_tools, - master_api_key=get_master_api_key(), + master_api_key=get_admin_api_key(), user_api_key=get_user_api_key(), ) if return_test_classes: @@ -1139,7 +1139,7 @@ class GalaxyTestDriver(TestDriver): host, port, url = target_url_parts() galaxy_interactor_kwds = { "galaxy_url": url, - "master_api_key": get_master_api_key(), + "master_api_key": get_admin_api_key(), "api_key": get_user_api_key(), "keep_outputs_dir": None, } diff --git a/lib/tool_shed/test/base/twilltestcase.py b/lib/tool_shed/test/base/twilltestcase.py index 2da7a490bb5..35008207c3d 100644 --- a/lib/tool_shed/test/base/twilltestcase.py +++ b/lib/tool_shed/test/base/twilltestcase.py @@ -20,7 +20,7 @@ import galaxy.model.tool_shed_install as galaxy_model import galaxy.util from galaxy.security import idencoding from galaxy.util import smart_str, unicodify -from galaxy_test.base.api_util import get_master_api_key +from galaxy_test.base.api_util import get_admin_api_key from galaxy_test.driver.testcase import DrivenFunctionalTestCase from tool_shed.util import ( hg_util, @@ -529,7 +529,7 @@ class ShedTwillTestCase(DrivenFunctionalTestCase): def deactivate_repository(self, installed_repository, strings_displayed=None, strings_not_displayed=None): encoded_id = self.security.encode_id(installed_repository.id) - api_key = get_master_api_key() + api_key = get_admin_api_key() response = requests.delete(self.galaxy_url + "/api/tool_shed_repositories/" + encoded_id, data={'remove_from_disk': False, 'key': api_key}) assert response.status_code != 403, response.content @@ -1258,7 +1258,7 @@ class ShedTwillTestCase(DrivenFunctionalTestCase): def reset_installed_repository_metadata(self, repository): encoded_id = self.security.encode_id(repository.id) - api_key = get_master_api_key() + api_key = get_admin_api_key() response = requests.post(self.galaxy_url + "/api/tool_shed_repositories/reset_metadata_on_selected_installed_repositories", data={'repository_ids': [encoded_id], 'key': api_key}) assert response.status_code != 403, response.content @@ -1268,7 +1268,7 @@ class ShedTwillTestCase(DrivenFunctionalTestCase): self.submit_form(button="reset_metadata_on_selected_repositories_button", **kwd) def reset_metadata_on_selected_installed_repositories(self, repository_ids): - api_key = get_master_api_key() + api_key = get_admin_api_key() response = requests.post(self.galaxy_url + "/api/tool_shed_repositories/reset_metadata_on_selected_installed_repositories", data={'repository_ids': repository_ids, 'key': api_key}) assert response.status_code != 403, response.content @@ -1375,7 +1375,7 @@ class ShedTwillTestCase(DrivenFunctionalTestCase): def uninstall_repository(self, installed_repository, strings_displayed=None, strings_not_displayed=None): encoded_id = self.security.encode_id(installed_repository.id) - api_key = get_master_api_key() + api_key = get_admin_api_key() response = requests.delete(self.galaxy_url + "/api/tool_shed_repositories/" + encoded_id, data={'remove_from_disk': True, 'key': api_key}) assert response.status_code != 403, response.content @@ -1390,7 +1390,7 @@ class ShedTwillTestCase(DrivenFunctionalTestCase): self.check_for_strings(strings_displayed, strings_not_displayed) def update_tool_shed_status(self): - api_key = get_master_api_key() + api_key = get_admin_api_key() response = requests.get(self.galaxy_url + "/api/tool_shed_repositories/check_for_updates?key=" + api_key) assert response.status_code != 403, response.content diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 6fb9a7f09de..18ad65c8ff6 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -13,7 +13,7 @@ galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pa sys.path[1:1] = [os.path.join(galaxy_root, "lib"), os.path.join(galaxy_root, "test")] from galaxy.util import classproperty -from galaxy_test.base.api_util import get_master_api_key, get_user_api_key +from galaxy_test.base.api_util import get_admin_api_key, get_user_api_key from galaxy_test.driver import driver_util log = driver_util.build_logger() @@ -86,7 +86,7 @@ class DataManagersGalaxyTestDriver(driver_util.GalaxyTestDriver): functional.test_data_managers.build_tests( tmp_dir=self.galaxy_test_tmp_dir, testing_shed_tools=self.testing_shed_tools, - master_api_key=get_master_api_key(), + master_api_key=get_admin_api_key(), user_api_key=get_user_api_key(), user_email=self.app.config.admin_users_list[0], create_admin=True,