Skip to content

Commit

Permalink
Restore GET /api/categories/<encoded_id> in ToolShed 2.0
Browse files Browse the repository at this point in the history
and the deleted field in the response.

Rationale: it is not particularly useful, but both:
GET /api/categories
GET /api/categories/<encoded_id>/repositories
work on TS 2.0, so it's weird that this one is missing.

Also, it was breaking BioBlend's
https://bioblend.readthedocs.io/en/latest/api_docs/toolshed/all.html#bioblend.toolshed.categories.ToolShedCategoryClient.show_category
  • Loading branch information
nsoranzo committed Oct 18, 2023
1 parent 8288078 commit f11b566
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/tool_shed/managers/categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class CategoryManager:
def __init__(self, app: ToolShedApp):
self.app = app

def get(self, encoded_category_id: str) -> Category:
return suc.get_category(self.app, encoded_category_id)

def create(self, trans: ProvidesUserContext, category_request: CreateCategoryRequest) -> Category:
name = category_request.name
description = category_request.description or name
Expand Down Expand Up @@ -71,6 +74,7 @@ def to_model(self, category: Category) -> CategoryResponse:
name=as_dict["name"],
description=as_dict["description"],
repositories=as_dict["repositories"],
deleted=as_dict["deleted"],
)


Expand Down
7 changes: 5 additions & 2 deletions lib/tool_shed/test/base/populators.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,12 @@ def get_categories(self) -> List[Category]:
response.raise_for_status()
return [Category(**c) for c in response.json()]

def get_category_with_name(self, name: str) -> Optional[Category]:
response = self._api_interactor.get("categories")
def get_category_with_id(self, category_id: str) -> Category:
response = self._api_interactor.get(f"categories/{category_id}")
response.raise_for_status()
return Category(**response.json())

def get_category_with_name(self, name: str) -> Optional[Category]:
categories = [c for c in self.get_categories() if c.name == name]
return categories[0] if categories else None

Expand Down
13 changes: 12 additions & 1 deletion lib/tool_shed/test/functional/test_shed_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ def test_create_requires_name(self):

def test_create_okay(self):
name = random_name(prefix="createokay")
body = {"name": name, "description": "testcreateokaydescript"}
description = "testcreateokaydescript"
body = {"name": name, "description": description}
response = self.admin_api_interactor.post("categories", json=body)
assert response.status_code == 200
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

category_id = category.id
category = self.populator.get_category_with_id(category_id)
assert category.name == name
assert category.description == description
12 changes: 12 additions & 0 deletions lib/tool_shed/webapp/api2/categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ def index(self, trans: SessionRequestContext = DependsOnTrans) -> List[CategoryR
categories = self.category_manager.index_db(trans, deleted)
return [self.category_manager.to_model(c) for c in categories]

@router.get(
"/api/categories/{encoded_category_id}",
description="show category",
operation_id="categories__show",
)
def show(self, encoded_category_id: str = CategoryIdPathParam) -> CategoryResponse:
"""
Return a list of dictionaries that contain information about each Category.
"""
category = self.category_manager.get(encoded_category_id)
return self.category_manager.to_model(category)

@router.get(
"/api/categories/{encoded_category_id}/repositories",
description="display repositories by category",
Expand Down
1 change: 1 addition & 0 deletions lib/tool_shed_client/schema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class Category(BaseModel):
id: str
name: str
description: str
deleted: bool
repositories: int


Expand Down

0 comments on commit f11b566

Please sign in to comment.