Skip to content

Commit

Permalink
Merge pull request galaxyproject#17218 from nsoranzo/release_23.2_fix…
Browse files Browse the repository at this point in the history
…_TS_API_create_repo_categories

[23.2] Fix categories in ToolShed repo create API
  • Loading branch information
jmchilton authored Dec 20, 2023
2 parents 04f1bde + a8e96c9 commit 0887ec9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
9 changes: 7 additions & 2 deletions lib/tool_shed/test/base/populators.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,13 @@ def upload_revision(
api_asserts.assert_status_code_is_ok(response)
return RepositoryUpdate(__root__=response.json())

def new_repository(self, category_id, prefix=DEFAULT_PREFIX) -> Repository:
def new_repository(self, category_ids: Union[List[str], str], prefix: str = DEFAULT_PREFIX) -> Repository:
name = random_name(prefix=prefix)
synopsis = random_name(prefix=prefix)
request = CreateRepositoryRequest(
name=name,
synopsis=synopsis,
category_ids=category_id,
category_ids=category_ids,
)
return self.create_repository(request)

Expand Down Expand Up @@ -282,6 +282,11 @@ def repositories_by_category(self, category_id: str) -> RepositoriesByCategory:
response.raise_for_status()
return RepositoriesByCategory(**response.json())

def assert_category_has_n_repositories(self, category_id: str, n: int):
category_repos = self.repositories_by_category(category_id)
assert category_repos.repository_count == n
assert len(category_repos.repositories) == n

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
18 changes: 10 additions & 8 deletions lib/tool_shed/test/functional/test_shed_repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@
class TestShedRepositoriesApi(ShedApiTestCase):
def test_create(self):
populator = self.populator
category_id = populator.new_category(prefix="testcreate").id
category1_id = populator.new_category(prefix="testcreate").id
populator.assert_category_has_n_repositories(category1_id, 0)

repos_by_category = populator.repositories_by_category(category_id)
repos = repos_by_category.repositories
assert len(repos) == 0
populator.new_repository(category1_id)
populator.assert_category_has_n_repositories(category1_id, 1)

populator.new_repository(category_id)
repos_by_category = populator.repositories_by_category(category_id)
repos = repos_by_category.repositories
assert len(repos) == 1
# Test creating repository with multiple categories
category2_id = populator.new_category(prefix="testcreate").id
populator.assert_category_has_n_repositories(category2_id, 0)
populator.new_repository([category1_id, category2_id])
populator.assert_category_has_n_repositories(category1_id, 2)
populator.assert_category_has_n_repositories(category2_id, 1)

def test_update_repository(self):
populator = self.populator
Expand Down
3 changes: 2 additions & 1 deletion lib/tool_shed/util/repository_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import re
from typing import (
List,
Optional,
Tuple,
TYPE_CHECKING,
Expand Down Expand Up @@ -190,7 +191,7 @@ def create_repository(
description,
long_description,
user_id,
category_ids=None,
category_ids: Optional[List[str]] = None,
remote_repository_url=None,
homepage_url=None,
) -> Tuple["Repository", str]:
Expand Down
2 changes: 1 addition & 1 deletion lib/tool_shed/webapp/frontend/src/schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export interface components {
/** CreateRepositoryRequest */
CreateRepositoryRequest: {
/** Category IDs */
"category_ids[]": string
"category_ids[]": string[] | string
/** Description */
description?: string
/** Homepage Url */
Expand Down
2 changes: 1 addition & 1 deletion lib/tool_shed_client/schema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class CreateRepositoryRequest(BaseModel):
alias="type",
title="Type",
)
category_ids: str = Field(
category_ids: Optional[Union[List[str], str]] = Field(
...,
alias="category_ids[]",
title="Category IDs",
Expand Down

0 comments on commit 0887ec9

Please sign in to comment.