From 2edb301654346c08dea73ac73c9256060675e05b Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Mon, 3 May 2021 16:06:26 +0200 Subject: [PATCH] Move shared test setup to lib/galaxy_test/driver/integration_setup.py --- lib/galaxy_test/driver/integration_setup.py | 68 +++++++++++++++++++ test/__init__.py | 0 test/integration/test_remote_files_posix.py | 64 +---------------- .../test_upload_file_sources.py | 6 +- 4 files changed, 72 insertions(+), 66 deletions(-) create mode 100644 lib/galaxy_test/driver/integration_setup.py delete mode 100644 test/__init__.py diff --git a/lib/galaxy_test/driver/integration_setup.py b/lib/galaxy_test/driver/integration_setup.py new file mode 100644 index 00000000000..21cc0060224 --- /dev/null +++ b/lib/galaxy_test/driver/integration_setup.py @@ -0,0 +1,68 @@ +""" +Test classes that should be shared between test scenarios. +""" +import os +import shutil +from tempfile import mkdtemp + +REQUIRED_ROLE = "user@bx.psu.edu" +REQUIRED_GROUP = "fs_test_group" + + +def get_posix_file_source_config(root_dir: str, roles: str, groups: str) -> str: + return f""" +- type: posix + id: posix_test + label: Posix + doc: Files from local path + root: {root_dir} + writable: true + requires_roles: {roles} + requires_groups: {groups} + +""" + + +def create_file_source_config_file_on(temp_dir, root_dir): + file_contents = get_posix_file_source_config(root_dir, REQUIRED_ROLE, REQUIRED_GROUP) + file_path = os.path.join(temp_dir, "file_sources_conf_posix.yml") + with open(file_path, "w") as f: + f.write(file_contents) + return file_path + + +class PosixFileSourceSetup: + + @classmethod + def handle_galaxy_config_kwds(cls, config): + temp_dir = os.path.realpath(mkdtemp()) + cls._test_driver.temp_directories.append(temp_dir) + cls.root_dir = os.path.join(temp_dir, "root") + + file_sources_config_file = create_file_source_config_file_on(temp_dir, cls.root_dir) + config["file_sources_config_file"] = file_sources_config_file + + # Disable all stock plugins + config["ftp_upload_dir"] = None + config["library_import_dir"] = None + config["user_library_import_dir"] = None + + def _write_file_fixtures(self): + root = self.root_dir + if os.path.exists(root): + shutil.rmtree(root) + os.mkdir(root) + + with open(os.path.join(root, "a"), "w") as f: + f.write("a\n") + + subdir1 = os.path.join(root, "subdir1") + os.mkdir(subdir1) + with open(os.path.join(subdir1, "b"), "w") as f: + f.write("b\n") + + return root + + def setUp(self): + super().setUp() + self._write_file_fixtures() diff --git a/test/__init__.py b/test/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/test/integration/test_remote_files_posix.py b/test/integration/test_remote_files_posix.py index 7cbffb74876..9dc8e16dd97 100644 --- a/test/integration/test_remote_files_posix.py +++ b/test/integration/test_remote_files_posix.py @@ -3,77 +3,15 @@ # Apache Docker host (shown next) doesn't work because displayname not set in response. # docker run -v `pwd`/test/integration/webdav:/var/lib/dav -e AUTH_TYPE=Basic -e USERNAME=alice -e PASSWORD=secret1234 -e LOCATION=/ -p 7083:80 bytemark/webdav -import os -import shutil -from tempfile import mkdtemp - from galaxy_test.base import api_asserts from galaxy_test.base.populators import DatasetPopulator from galaxy_test.driver import integration_util +from galaxy_test.driver.integration_setup import PosixFileSourceSetup REQUIRED_ROLE = "user@bx.psu.edu" REQUIRED_GROUP = "fs_test_group" -def get_posix_file_source_config(root_dir: str, roles: str, groups: str) -> str: - return f""" -- type: posix - id: posix_test - label: Posix - doc: Files from local path - root: {root_dir} - writable: true - requires_roles: {roles} - requires_groups: {groups} - -""" - - -def create_file_source_config_file_on(temp_dir, root_dir): - file_contents = get_posix_file_source_config(root_dir, REQUIRED_ROLE, REQUIRED_GROUP) - file_path = os.path.join(temp_dir, "file_sources_conf_posix.yml") - with open(file_path, "w") as f: - f.write(file_contents) - return file_path - - -class PosixFileSourceSetup: - - @classmethod - def handle_galaxy_config_kwds(cls, config): - temp_dir = os.path.realpath(mkdtemp()) - cls._test_driver.temp_directories.append(temp_dir) - cls.root_dir = os.path.join(temp_dir, "root") - - file_sources_config_file = create_file_source_config_file_on(temp_dir, cls.root_dir) - config["file_sources_config_file"] = file_sources_config_file - - # Disable all stock plugins - config["ftp_upload_dir"] = None - config["library_import_dir"] = None - config["user_library_import_dir"] = None - - def _write_file_fixtures(self): - root = self.root_dir - if os.path.exists(root): - shutil.rmtree(root) - os.mkdir(root) - - with open(os.path.join(root, "a"), "w") as f: - f.write("a\n") - - subdir1 = os.path.join(root, "subdir1") - os.mkdir(subdir1) - with open(os.path.join(subdir1, "b"), "w") as f: - f.write("b\n") - - return root - - def setUp(self): - super().setUp() - self._write_file_fixtures() - - class PosixFileSourceIntegrationTestCase(PosixFileSourceSetup, integration_util.IntegrationTestCase): def setUp(self): diff --git a/test/integration_selenium/test_upload_file_sources.py b/test/integration_selenium/test_upload_file_sources.py index 2b4f34e2b4f..f44c90f3a13 100644 --- a/test/integration_selenium/test_upload_file_sources.py +++ b/test/integration_selenium/test_upload_file_sources.py @@ -1,10 +1,10 @@ +from galaxy_test.driver.integration_setup import ( + PosixFileSourceSetup, +) from .framework import ( selenium_test, SeleniumIntegrationTestCase, ) -from ..integration.test_remote_files_posix import ( - PosixFileSourceSetup, -) class PosixFileSourceSeleniumIntegrationTestCase(PosixFileSourceSetup, SeleniumIntegrationTestCase):