mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-01 15:37:32 +08:00
Keep galaxy.files off galaxy.managers
ProvidesFileSourcesUserContext took an untyped trans; annotating it as ProvidesUserContext pointed galaxy.files at galaxy.managers, and the drs test then imported that name at runtime for a cast. galaxy-files depends on galaxy-util alone, so the package's own test run could not find galaxy.managers and failed to collect. Describe the transaction where it is used instead: the adapter reads user, anonymous, user_is_admin, user_ftp_dir, user_vault and app, so state that as a protocol in galaxy.files. Transactions satisfy it structurally, and the test casts to something its package actually ships.
This commit is contained in:
@@ -7,7 +7,6 @@ from typing import (
|
||||
Any,
|
||||
NamedTuple,
|
||||
Protocol,
|
||||
TYPE_CHECKING,
|
||||
)
|
||||
|
||||
from galaxy import exceptions
|
||||
@@ -27,8 +26,28 @@ from .plugins import (
|
||||
FileSourcePluginsConfig,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from galaxy.managers.context import ProvidesUserContext
|
||||
|
||||
class ProvidesFileSourcesTransaction(Protocol):
|
||||
"""The slice of a Galaxy transaction ProvidesFileSourcesUserContext reads."""
|
||||
|
||||
@property
|
||||
def anonymous(self) -> bool: ...
|
||||
|
||||
@property
|
||||
def user(self) -> Any: ...
|
||||
|
||||
@property
|
||||
def user_ftp_dir(self) -> str | None: ...
|
||||
|
||||
@property
|
||||
def user_is_admin(self) -> bool: ...
|
||||
|
||||
@property
|
||||
def user_vault(self) -> Any: ...
|
||||
|
||||
@property
|
||||
def app(self) -> Any: ...
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -375,7 +394,7 @@ OptionalUserContext = FileSourcesUserContext | None
|
||||
class ProvidesFileSourcesUserContext(FileSourcesUserContext, FileSourceDictifiable):
|
||||
"""Implement a FileSourcesUserContext from a Galaxy ProvidesUserContext (e.g. trans)."""
|
||||
|
||||
def __init__(self, trans: "ProvidesUserContext", **kwargs):
|
||||
def __init__(self, trans: ProvidesFileSourcesTransaction, **kwargs):
|
||||
self.trans = trans
|
||||
|
||||
@property
|
||||
|
||||
@@ -13,9 +13,9 @@ import responses
|
||||
|
||||
from galaxy.files import (
|
||||
DictFileSourcesUserContext,
|
||||
ProvidesFileSourcesTransaction,
|
||||
ProvidesFileSourcesUserContext,
|
||||
)
|
||||
from galaxy.managers.context import ProvidesUserContext
|
||||
from ._util import (
|
||||
assert_realizes_as,
|
||||
assert_realizes_contains,
|
||||
@@ -46,7 +46,7 @@ def test_provides_file_sources_user_context_oidc_access_tokens():
|
||||
class DummyTrans:
|
||||
user = DummyUser()
|
||||
|
||||
tokens = ProvidesFileSourcesUserContext(cast(ProvidesUserContext, DummyTrans())).oidc_access_tokens
|
||||
tokens = ProvidesFileSourcesUserContext(cast(ProvidesFileSourcesTransaction, DummyTrans())).oidc_access_tokens
|
||||
assert tokens == {"oidc": "oidc-token", "keycloak": "keycloak-token"}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ def test_provides_file_sources_user_context_oidc_access_tokens_anonymous():
|
||||
class DummyTrans:
|
||||
user = None
|
||||
|
||||
assert ProvidesFileSourcesUserContext(cast(ProvidesUserContext, DummyTrans())).oidc_access_tokens is None
|
||||
assert ProvidesFileSourcesUserContext(cast(ProvidesFileSourcesTransaction, DummyTrans())).oidc_access_tokens is None
|
||||
|
||||
|
||||
def test_drs_http_headers_template_expansion():
|
||||
|
||||
Reference in New Issue
Block a user