Commit 2a3bde03 authored by davelopez's avatar davelopez
Browse files

Add test to import history from file source using tasks

Currently the test will fail because the imported datasets are in the "discarded" state.
parent fa21013d
Loading
Loading
Loading
Loading
+33 −4
Original line number Diff line number Diff line
@@ -436,17 +436,23 @@ class BaseDatasetPopulator(BasePopulator):
        return create_response

    def create_from_store(
        self, store_dict: Optional[Dict[str, Any]] = None, store_path: Optional[str] = None
        self,
        store_dict: Optional[Dict[str, Any]] = None,
        store_path: Optional[str] = None,
        model_store_format: Optional[str] = None,
    ) -> Dict[str, Any]:
        payload = _store_payload(store_dict=store_dict, store_path=store_path)
        payload = _store_payload(store_dict=store_dict, store_path=store_path, model_store_format=model_store_format)
        create_response = self.create_from_store_raw(payload)
        api_asserts.assert_status_code_is_ok(create_response)
        return create_response.json()

    def create_from_store_async(
        self, store_dict: Optional[Dict[str, Any]] = None, store_path: Optional[str] = None
        self,
        store_dict: Optional[Dict[str, Any]] = None,
        store_path: Optional[str] = None,
        model_store_format: Optional[str] = None,
    ) -> Dict[str, Any]:
        payload = _store_payload(store_dict=store_dict, store_path=store_path)
        payload = _store_payload(store_dict=store_dict, store_path=store_path, model_store_format=model_store_format)
        create_response = self.create_from_store_raw_async(payload)
        create_response.raise_for_status()
        return create_response.json()
@@ -1161,7 +1167,9 @@ class BaseDatasetPopulator(BasePopulator):

    def wait_on_task(self, async_task_response: Response):
        task_id = async_task_response.json()["id"]
        return self.wait_on_task_id(task_id)

    def wait_on_task_id(self, task_id: str):
        def state():
            state_response = self._get(f"tasks/{task_id}/state")
            state_response.raise_for_status()
@@ -1267,6 +1275,27 @@ class BaseDatasetPopulator(BasePopulator):
        )
        return request

    def export_history_to_uri_async(
        self, history_id: str, target_uri: str, model_store_format: str = "tgz", include_files: bool = True
    ):
        url = f"histories/{history_id}/write_store"
        download_response = self._post(
            url,
            dict(target_uri=target_uri, include_files=include_files, model_store_format=model_store_format),
            json=True,
        )
        api_asserts.assert_status_code_is_ok(download_response)
        task_ok = self.wait_on_task(download_response)
        assert task_ok, f"Task: Writing history to {target_uri} task failed"

    def import_history_from_uri_async(self, target_uri: str, model_store_format: str):
        import_async_response = self.create_from_store_async(
            store_path=target_uri, model_store_format=model_store_format
        )
        task_id = import_async_response["id"]
        task_ok = self.wait_on_task_id(task_id)
        assert task_ok, f"Task: Import history from {target_uri} failed"


class GalaxyInteractorHttpMixin:
    galaxy_interactor: ApiTestInteractor
+30 −1
Original line number Diff line number Diff line
import tarfile
from uuid import uuid4

from galaxy.model.unittest_utils.store_fixtures import (
    deferred_hda_model_store_dict,
@@ -12,6 +13,7 @@ from galaxy_test.base.populators import (
    DatasetCollectionPopulator,
    DatasetPopulator,
)
from galaxy_test.driver.integration_setup import PosixFileSourceSetup
from galaxy_test.driver.integration_util import IntegrationTestCase


@@ -29,10 +31,17 @@ class ImportExportHistoryOutputsToWorkingDirIntegrationTestCase(ImportExportTest
        self._set_up_populators()


class ImportExportHistoryViaTasksIntegrationTestCase(ImportExportTests, IntegrationTestCase, UsesCeleryTasks):
class ImportExportHistoryViaTasksIntegrationTestCase(
    ImportExportTests, IntegrationTestCase, UsesCeleryTasks, PosixFileSourceSetup
):
    task_based = True
    framework_tool_and_types = True

    @classmethod
    def handle_galaxy_config_kwds(cls, config):
        PosixFileSourceSetup.handle_galaxy_config_kwds(config, cls)
        UsesCeleryTasks.handle_galaxy_config_kwds(config)

    def setUp(self):
        super().setUp()
        self._set_up_populators()
@@ -48,6 +57,26 @@ class ImportExportHistoryViaTasksIntegrationTestCase(ImportExportTests, Integrat
            "task based import history",
        )

    def test_import_model_store_from_file_source_async_with_format(self):
        history_name = f"for_export_format_async_{uuid4()}"
        history_id = self.dataset_populator.setup_history_for_export_testing(history_name)
        model_store_format = "rocrate.zip"
        target_uri = f"gxfiles://posix_test/history.{model_store_format}"

        self.dataset_populator.export_history_to_uri_async(history_id, target_uri, model_store_format)
        self.dataset_populator.import_history_from_uri_async(target_uri, model_store_format)

        last_history = self._get("histories?limit=1").json()
        assert len(last_history) == 1
        imported_history = last_history[0]
        imported_history_id = imported_history["id"]
        assert imported_history_id != history_id
        assert imported_history["name"] == history_name
        history_contents = self.dataset_populator.get_history_contents(imported_history_id)
        assert len(history_contents) == 2
        for dataset in history_contents:
            assert dataset["state"] == "ok"


class ImportExportHistoryContentsViaTasksIntegrationTestCase(IntegrationTestCase, UsesCeleryTasks):
    task_based = True