Skip to content

Commit

Permalink
Make sure get_category_with_name() returns a Category or raise `V…
Browse files Browse the repository at this point in the history
…alueError`
  • Loading branch information
nsoranzo committed Oct 24, 2023
1 parent 5a90f2d commit 37a5aa2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
9 changes: 4 additions & 5 deletions lib/tool_shed/test/base/populators.py
Original file line number Diff line number Diff line change
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
6 changes: 3 additions & 3 deletions lib/tool_shed/test/base/twilltestcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,8 +1035,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 @@ -1591,7 +1592,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
Expand Up @@ -370,9 +370,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
5 changes: 3 additions & 2 deletions lib/tool_shed/test/functional/test_shed_categories.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from typing import Dict

from galaxy_test.base.api_util import random_name
from ..base.api import ShedApiTestCase


class TestShedCategoriesApi(ShedApiTestCase):
def test_create_requires_name(self):
body = {}
body: Dict = {}
response = self.admin_api_interactor.post("categories", json=body)
assert response.status_code == 400

Expand All @@ -17,7 +19,6 @@ def test_create_okay(self):
assert response.json()["name"] == name

category = self.populator.get_category_with_name(name)
assert category is not None
assert category.name == name
assert category.description == description

Expand Down

0 comments on commit 37a5aa2

Please sign in to comment.