Files
galaxy/test/unit/webapps/test_service_base.py
T
davelopez 6f2b4ff559 Move short_term_storage related classes to its own path
The ShortTermStorageManager and related classes should live in their own package eventually and not within galaxy.web nor galaxy.managers as the short term storage microservices it's fairly independent and has way less dependencies than those other packages.
2023-11-30 17:01:29 +01:00

42 lines
2.0 KiB
Python

from typing import Tuple
import pytest
from galaxy.schema.schema import ModelStoreFormat
from galaxy.short_term_storage import ShortTermStorageAllocator
from galaxy.webapps.galaxy.services.base import model_store_storage_target
class MockShortTermStorageAllocator(ShortTermStorageAllocator):
def __init__(self, expected_filename: str, expected_mime_type: str) -> None:
super().__init__()
self.expected_filename = expected_filename
self.expected_mime_type = expected_mime_type
def new_target(self, filename, mime_type):
assert filename == self.expected_filename
assert mime_type == self.expected_mime_type
@pytest.mark.parametrize(
"file_name, model_store_format, expected",
[
("My Cool Object", "txt", ("My-Cool-Object.txt", "text/plain")),
("!My Cool Object!", "json", ("My-Cool-Object.json", "application/json")),
("Hello₩◎ґʟⅾ", "xml", ("Hello.xml", "application/xml")),
("test", ModelStoreFormat.ROCRATE_ZIP.value, ("test.rocrate.zip", "application/zip")),
("test", ModelStoreFormat.TAR.value, ("test.tar", "application/x-tar")),
("test", ModelStoreFormat.TGZ.value, ("test.tgz", "application/x-tar")),
("test", ModelStoreFormat.TAR_DOT_GZ.value, ("test.tar.gz", "application/x-tar")),
("test", ModelStoreFormat.BAG_DOT_ZIP.value, ("test.bag.zip", "application/zip")),
("test", ModelStoreFormat.BAG_DOT_TAR.value, ("test.bag.tar", "application/x-tar")),
("test", ModelStoreFormat.BAG_DOT_TGZ.value, ("test.bag.tgz", "application/x-tar")),
("test", ModelStoreFormat.BCO_JSON.value, ("test.bco.json", "application/json")),
],
)
def test_model_store_storage_target(file_name: str, model_store_format: str, expected: Tuple[str, str]):
mock_sts_allocator = MockShortTermStorageAllocator(*expected)
model_store_storage_target(
short_term_storage_allocator=mock_sts_allocator, file_name=file_name, model_store_format=model_store_format
)