Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type annotation of lib/tool_shed/test/functional/ #16901

Merged
merged 10 commits into from
Oct 24, 2023
13 changes: 6 additions & 7 deletions lib/tool_shed/test/base/populators.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def repo_tars(test_data_path: str) -> List[Path]:

class HostsTestToolShed(Protocol):
host: str
port: int
port: Optional[str]


class ToolShedPopulator:
Expand Down Expand Up @@ -271,18 +271,17 @@ def get_category_with_id(self, category_id: str) -> Category:
response.raise_for_status()
return Category(**response.json())

def get_category_with_name(self, name: str) -> Optional[Category]:
def get_category_with_name(self, name: str) -> Category:
categories = [c for c in self.get_categories() if c.name == name]
return categories[0] if categories else None
if not categories:
raise ValueError(f"No category with name {name} found.")
return categories[0]

def repositories_by_category(self, category_id: str) -> RepositoriesByCategory:
response = self._api_interactor.get(f"categories/{category_id}/repositories")
response.raise_for_status()
return RepositoriesByCategory(**response.json())

def has_category_with_name(self, name: str) -> bool:
return self.get_category_with_name(name) is not None

def get_ordered_installable_revisions(self, owner: str, name: str) -> OrderedInstallableRevisions:
request = GetOrderedInstallableRevisionsRequest(owner=owner, name=name)
revisions_response = self._api_interactor.get(
Expand Down Expand Up @@ -397,7 +396,7 @@ def tool_guid(
owner = repository.owner
name = repository.name
port = shed_host.port
if port in [None, 80, 443]:
if port in [None, "80", "443"]:
host_and_port = shed_host.host
else:
host_and_port = f"{shed_host.host}:{shed_host.port}"
Expand Down
30 changes: 22 additions & 8 deletions lib/tool_shed/test/base/twilltestcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
Iterator,
List,
Optional,
Tuple,
)
from urllib.parse import (
quote_plus,
Expand Down Expand Up @@ -694,7 +695,14 @@ def _submit_register_form(self, email: str, password: str, username: str, redire
def invalid_tools_labels(self) -> str:
return "Invalid Tools" if self.is_v2 else "Invalid tools"

def create(self, cntrller="user", email="test@bx.psu.edu", password="testuser", username="admin-user", redirect=""):
def create(
self,
cntrller: str = "user",
email: str = "test@bx.psu.edu",
password: str = "testuser",
username: str = "admin-user",
redirect: Optional[str] = None,
) -> Tuple[bool, bool, bool]:
# HACK: don't use panels because late_javascripts() messes up the twill browser and it
# can't find form fields (and hence user can't be logged in).
params = dict(cntrller=cntrller, use_panels=False)
Expand Down Expand Up @@ -747,7 +755,7 @@ def login(
email: str = "test@bx.psu.edu",
password: str = "testuser",
username: str = "admin-user",
redirect: str = "",
redirect: Optional[str] = None,
logout_first: bool = True,
):
if self.is_v2:
Expand Down Expand Up @@ -905,7 +913,11 @@ def check_repository_changelog(self, repository: Repository, strings_displayed=N
self.check_for_strings(strings_displayed, strings_not_displayed)

def check_repository_dependency(
self, repository: Repository, depends_on_repository, depends_on_changeset_revision=None, changeset_revision=None
self,
repository: Repository,
depends_on_repository: Repository,
depends_on_changeset_revision=None,
changeset_revision=None,
):
if not self.is_v2:
# v2 doesn't display repository repository dependencies, they are deprecated
Expand Down Expand Up @@ -1031,8 +1043,9 @@ def commit_and_push(self, repository, hgrepo, options, username, password):

def create_category(self, **kwd) -> Category:
category_name = kwd["name"]
category = self.populator.get_category_with_name(category_name)
if category is None:
try:
category = self.populator.get_category_with_name(category_name)
except ValueError:
# not recreating this functionality in the UI I don't think?
category = self.populator.new_category(category_name)
return category
Expand Down Expand Up @@ -1402,7 +1415,7 @@ def get_repositories_category_api(

def get_or_create_repository(
self, category: Category, owner: str, name: str, strings_displayed=None, strings_not_displayed=None, **kwd
) -> Optional[Repository]:
) -> Repository:
# If not checking for a specific string, it should be safe to assume that
# we expect repository creation to be successful.
if strings_displayed is None:
Expand All @@ -1417,6 +1430,7 @@ def get_or_create_repository(
self.submit_form(button="create_repository_button", name=name, category_id=category_id, **kwd)
self.check_for_strings(strings_displayed, strings_not_displayed)
repository = self.populator.get_repository_for(owner, name)
assert repository
return repository

def get_repo_path(self, repository: Repository) -> str:
Expand Down Expand Up @@ -1495,10 +1509,11 @@ def get_repository_metadata_revisions(self, repository: Repository) -> List[str]
for repository_metadata in self._db_repository(repository).metadata_revisions
]

def _get_repository_by_name_and_owner(self, name: str, owner: str) -> Optional[Repository]:
def _get_repository_by_name_and_owner(self, name: str, owner: str) -> Repository:
repo = self.populator.get_repository_for(owner, name)
if repo is None:
repo = self.populator.get_repository_for(owner, name, deleted="true")
assert repo
return repo

def get_repository_tip(self, repository: Repository) -> str:
Expand Down Expand Up @@ -1585,7 +1600,6 @@ def _install_repository(
) -> None:
self.browse_tool_shed(url=self.url)
category = self.populator.get_category_with_name(category_name)
assert category
self.browse_category(category)
self.preview_repository_in_tool_shed(name, owner, strings_displayed=preview_strings_displayed)
repository = self._get_repository_by_name_and_owner(name, owner)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import logging

import pytest

from ..base import common
from ..base.api import skip_if_api_v2
from ..base.twilltestcase import (
common,
ShedTwillTestCase,
)
from ..base.twilltestcase import ShedTwillTestCase

repository_name = "filtering_0000"
repository_description = "Galaxy's filtering tool for test 0000"
Expand Down Expand Up @@ -159,7 +159,6 @@ def test_0045_alter_repository_states(self):
def test_0050_display_repository_tip_file(self):
"""Display the contents of filtering.xml in the repository tip revision"""
repository = self._get_repository_by_name_and_owner(repository_name, common.test_user_1_name)
assert repository
if self._browser.is_twill:
self.display_repository_file_contents(
repository=repository,
Expand Down Expand Up @@ -270,14 +269,15 @@ def test_0095_verify_reserved_repository_name_handling(self):
error_message = (
"The term 'repos' is a reserved word in the Tool Shed, so it cannot be used as a repository name."
)
self.get_or_create_repository(
name="repos",
description=repository_description,
long_description=repository_long_description,
owner=common.test_user_1_name,
category=category,
strings_displayed=[error_message],
)
with pytest.raises(AssertionError):
self.get_or_create_repository(
name="repos",
description=repository_description,
long_description=repository_long_description,
owner=common.test_user_1_name,
category=category,
strings_displayed=[error_message],
)

def test_0100_verify_reserved_username_handling(self):
"""Check that reserved usernames are handled correctly."""
Expand All @@ -303,7 +303,7 @@ def test_0110_delete_filtering_repository(self):
repository = self._get_repository_by_name_and_owner(repository_name, common.test_user_1_name)
self.login(email=common.admin_email, username=common.admin_username)
self.delete_repository(repository)
metadata = self._populator.get_metadata(repository, downloadable_only=False)
metadata = self.populator.get_metadata(repository, downloadable_only=False)
for _, value in metadata.__root__.items():
assert not value.downloadable
# Explicitly reload all metadata revisions from the database, to ensure that we have the current status of the downloadable flag.
Expand Down Expand Up @@ -373,9 +373,10 @@ def test_0130_verify_handling_of_invalid_characters(self):

def test_0135_api_get_repositories_in_category(self):
"""Load the api endpoint for repositories in a category."""
categories = []
categories.append(self.populator.get_category_with_name("Test 0000 Basic Repository Features 1"))
categories.append(self.populator.get_category_with_name("Test 0000 Basic Repository Features 2"))
categories = [
self.populator.get_category_with_name(name)
for name in ("Test 0000 Basic Repository Features 1", "Test 0000 Basic Repository Features 2")
]
self.get_repositories_category_api(categories)

def test_0140_view_invalid_changeset(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import os

from ..base import common
from ..base.api import skip_if_api_v2
from ..base.twilltestcase import (
common,
ShedTwillTestCase,
)
from ..base.twilltestcase import ShedTwillTestCase

repository_name = "freebayes_0010"
repository_description = "Galaxy's freebayes tool"
Expand Down Expand Up @@ -53,7 +51,6 @@ def test_0010_create_freebayes_repository_and_upload_tool_xml(self):
category=category,
strings_displayed=[],
)
assert repository
strings_displayed = ["Metadata may have been defined", "This file requires an entry", "tool_data_table_conf"]
self.add_file_to_repository(repository, "freebayes/freebayes.xml", strings_displayed=strings_displayed)
if self.is_v2:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from ..base import common
from ..base.api import skip_if_api_v2
from ..base.twilltestcase import (
common,
ShedTwillTestCase,
)
from ..base.twilltestcase import ShedTwillTestCase

column_maker_repository_name = "column_maker_0020"
column_maker_repository_description = "A flexible aligner."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from ..base import common
from ..base.api import skip_if_api_v2
from ..base.twilltestcase import (
common,
ShedTwillTestCase,
)
from ..base.twilltestcase import ShedTwillTestCase

column_maker_repository_name = "column_maker_0030"
column_maker_repository_description = "Add column"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from ..base import common
from ..base.api import skip_if_api_v2
from ..base.twilltestcase import (
common,
ShedTwillTestCase,
)
from ..base.twilltestcase import ShedTwillTestCase

freebayes_repository_name = "freebayes_0040"
freebayes_repository_description = "Galaxy's freebayes tool for test 0040"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from ..base import common
from ..base.api import skip_if_api_v2
from ..base.twilltestcase import (
common,
ShedTwillTestCase,
)
from ..base.twilltestcase import ShedTwillTestCase

emboss_repository_name = "emboss_0050"
emboss_repository_description = "Galaxy's emboss tool"
Expand Down Expand Up @@ -69,8 +67,6 @@ def test_0010_create_column_repository(self):
category=category,
strings_displayed=[],
)
assert repository
assert repository.id
self.commit_tar_to_repository(
repository,
"column_maker/column_maker.tar",
Expand Down
6 changes: 2 additions & 4 deletions lib/tool_shed/test/functional/test_0070_invalid_tool.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from ..base.twilltestcase import (
common,
ShedTwillTestCase,
)
from ..base import common
from ..base.twilltestcase import ShedTwillTestCase

repository_name = "bismark_0070"
repository_description = "Galaxy's bismark wrapper"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from ..base.twilltestcase import (
common,
ShedTwillTestCase,
)
from ..base import common
from ..base.twilltestcase import ShedTwillTestCase

column_repository_name = "column_maker_0080"
column_repository_description = "Add column"
Expand Down
6 changes: 2 additions & 4 deletions lib/tool_shed/test/functional/test_0090_tool_search.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from ..base.twilltestcase import (
common,
ShedTwillTestCase,
)
from ..base import common
from ..base.twilltestcase import ShedTwillTestCase

emboss_repository_name = "emboss_0090"
emboss_repository_description = "Galaxy's emboss tool"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import logging
import os

from ..base import common
from ..base.api import skip_if_api_v2
from ..base.twilltestcase import (
common,
ShedTwillTestCase,
)
from ..base.twilltestcase import ShedTwillTestCase

log = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from ..base.twilltestcase import (
common,
ShedTwillTestCase,
)
from ..base import common
from ..base.twilltestcase import ShedTwillTestCase

column_maker_repository_name = "column_maker_0110"
column_maker_repository_description = "A flexible aligner."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from ..base.twilltestcase import (
common,
ShedTwillTestCase,
)
from ..base import common
from ..base.twilltestcase import ShedTwillTestCase

datatypes_repository_name = "blast_datatypes_0120"
datatypes_repository_description = "Galaxy applicable datatypes for BLAST"
Expand Down
6 changes: 2 additions & 4 deletions lib/tool_shed/test/functional/test_0140_tool_help_images.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import logging

from ..base import common
from ..base.api import skip_if_api_v2
from ..base.twilltestcase import (
common,
ShedTwillTestCase,
)
from ..base.twilltestcase import ShedTwillTestCase

log = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from ..base.twilltestcase import (
common,
ShedTwillTestCase,
)
from ..base import common
from ..base.twilltestcase import ShedTwillTestCase

column_repository_name = "column_maker_0150"
column_repository_description = "Add column"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from ..base.twilltestcase import (
common,
ShedTwillTestCase,
)
from ..base import common
from ..base.twilltestcase import ShedTwillTestCase

filter_repository_name = "filtering_0160"
filter_repository_description = "Galaxy's filtering tool for test 0160"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import os

from ..base.twilltestcase import (
common,
ShedTwillTestCase,
)
from ..base import common
from ..base.twilltestcase import ShedTwillTestCase

matplotlib_repository_name = "package_matplotlib_1_2_0170"
matplotlib_repository_description = (
Expand Down
Loading
Loading