mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
In API tests, replace no more working `uses_test_history` decorator (because the `history_id` method parameter is interpreted as a fixture) with a real class-level pytest fixture. As a consequence, replace use of `self.history_id` in API tests because it interferes with the class-level `history_id` fixture. Also: - Some type annotations
64 lines
2.0 KiB
Python
64 lines
2.0 KiB
Python
import logging
|
|
import os
|
|
from typing import (
|
|
Any,
|
|
Optional,
|
|
)
|
|
|
|
from galaxy.tool_util.verify.test_data import TestDataResolver
|
|
from galaxy.util.unittest import TestCase
|
|
from galaxy_test.base.env import (
|
|
setup_keep_outdir,
|
|
target_url_parts,
|
|
)
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
class FunctionalTestCase(TestCase):
|
|
"""Base class for tests targetting actual Galaxy servers.
|
|
|
|
Subclass should override galaxy_driver_class if a Galaxy server
|
|
needs to be launched to run the test, this base class assumes a
|
|
server is already running.
|
|
"""
|
|
|
|
galaxy_driver_class: Optional[type] = None
|
|
host: str
|
|
port: Optional[str]
|
|
url: str
|
|
keepOutdir: str
|
|
test_data_resolver: TestDataResolver
|
|
_test_driver: Optional[Any]
|
|
|
|
def setUp(self) -> None:
|
|
self.host, self.port, self.url = target_url_parts()
|
|
server_wrapper = (
|
|
self._test_driver and self._test_driver.server_wrappers and self._test_driver.server_wrappers[0]
|
|
)
|
|
if server_wrapper:
|
|
self.host = server_wrapper.host
|
|
self.port = server_wrapper.port
|
|
self.url = f"http://{self.host}:{self.port}{server_wrapper.prefix.rstrip('/')}/"
|
|
self.test_data_resolver = TestDataResolver()
|
|
self.keepOutdir = setup_keep_outdir()
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
"""Configure and start Galaxy for a test."""
|
|
cls._test_driver = None
|
|
|
|
if cls.galaxy_driver_class is not None and not os.environ.get("GALAXY_TEST_ENVIRONMENT_CONFIGURED"):
|
|
cls._test_driver = cls.galaxy_driver_class()
|
|
cls._test_driver.setup(config_object=cls)
|
|
|
|
@classmethod
|
|
def tearDownClass(cls):
|
|
"""Shutdown Galaxy server and cleanup temp directory."""
|
|
if cls._test_driver:
|
|
cls._test_driver.tear_down()
|
|
|
|
def get_filename(self, filename: str) -> str:
|
|
# No longer used by tool tests - drop if isn't used else where.
|
|
return self.test_data_resolver.get_filename(filename)
|