From 32065d123a0c22eb8e45e2775f98b0352b577c26 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Wed, 6 Oct 2021 17:37:17 +0200 Subject: [PATCH] Add simple API test for tus endpoint --- lib/galaxy/dependencies/dev-requirements.txt | 1 + lib/galaxy_test/api/test_tools_upload.py | 32 ++++++++++++++++++++ pyproject.toml | 1 + 3 files changed, 34 insertions(+) diff --git a/lib/galaxy/dependencies/dev-requirements.txt b/lib/galaxy/dependencies/dev-requirements.txt index fdbc5621b27..cab8c7cabe5 100644 --- a/lib/galaxy/dependencies/dev-requirements.txt +++ b/lib/galaxy/dependencies/dev-requirements.txt @@ -2,6 +2,7 @@ adal==1.2.7 aiofiles==0.6.0 +aiotus==0.1.10 alabaster==0.7.12; python_version >= "3.5" amqp==5.0.6; python_version >= "3.6" appdirs==1.4.4; python_version >= "3.6" diff --git a/lib/galaxy_test/api/test_tools_upload.py b/lib/galaxy_test/api/test_tools_upload.py index 1a22fa4cc16..aea3df50e7f 100644 --- a/lib/galaxy_test/api/test_tools_upload.py +++ b/lib/galaxy_test/api/test_tools_upload.py @@ -1,5 +1,8 @@ +import asyncio import json +import os +import aiotus import pytest from galaxy.tool_util.verify.test_data import TestDataResolver @@ -906,3 +909,32 @@ class ToolsUploadTestCase(ApiTestCase): new_dataset = self.dataset_populator.fetch(payload, assert_ok=assert_ok).json()["outputs"][0] self.dataset_populator.wait_for_history(history_id, assert_ok=assert_ok) return history_id, new_dataset + + def test_upload_dataset_resumable(self): + + async def upload_file(url, path, api_key, history_id, ): + filename = os.path.basename(path) + metadata = { + 'filename': filename.encode(), + 'history_id': history_id.encode(), + } + headers = {'x-api-key': api_key} + + # Upload a file to a tus server. + with open(path, "rb") as f: + location = await aiotus.upload(url, f, metadata, headers=headers) + # 'location' is the URL where the file was uploaded to. + + # Read back the metadata from the server. + return await aiotus.metadata(location, headers=headers) + + loop = asyncio.get_event_loop() + with self.dataset_populator.test_history() as history_id: + future = upload_file(url=f"{self.url}/api/upload/resumable_upload", path=TestDataResolver().get_filename("1.fastqsanger.gz"), api_key=self.galaxy_interactor.api_key, history_id=history_id) + result = loop.run_until_complete(future) + assert result['filename'] + assert result['history_id'] + self.dataset_populator.wait_for_history(history_id, assert_ok=True) + dataset = self.dataset_populator.get_history_dataset_details(history_id) + assert dataset['name'] == '1.fastqsanger.gz' + assert dataset['file_ext'] == 'fastqsanger.gz' diff --git a/pyproject.toml b/pyproject.toml index 4282e1ef714..07d544f6f85 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -87,6 +87,7 @@ Whoosh = "*" zipstream-new = "*" [tool.poetry.dev-dependencies] +aiotus = "*" fluent-logger = "*" httpx = "*" gunicorn = "*"