diff --git a/lib/tool_shed/test/base/populators.py b/lib/tool_shed/test/base/populators.py index 8bc6af506e08..dc7aeb881014 100644 --- a/lib/tool_shed/test/base/populators.py +++ b/lib/tool_shed/test/base/populators.py @@ -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) @@ -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( diff --git a/lib/tool_shed/test/functional/test_shed_repositories.py b/lib/tool_shed/test/functional/test_shed_repositories.py index ac58f44d07d6..ffa7e94b52b8 100644 --- a/lib/tool_shed/test/functional/test_shed_repositories.py +++ b/lib/tool_shed/test/functional/test_shed_repositories.py @@ -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 diff --git a/lib/tool_shed/util/repository_util.py b/lib/tool_shed/util/repository_util.py index 0828e1652247..ea8b33d0e372 100644 --- a/lib/tool_shed/util/repository_util.py +++ b/lib/tool_shed/util/repository_util.py @@ -3,6 +3,7 @@ import os import re from typing import ( + List, Optional, Tuple, TYPE_CHECKING, @@ -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]: diff --git a/lib/tool_shed/webapp/frontend/src/schema/schema.ts b/lib/tool_shed/webapp/frontend/src/schema/schema.ts index c49abf299742..b7633938aedb 100644 --- a/lib/tool_shed/webapp/frontend/src/schema/schema.ts +++ b/lib/tool_shed/webapp/frontend/src/schema/schema.ts @@ -305,7 +305,7 @@ export interface components { /** CreateRepositoryRequest */ CreateRepositoryRequest: { /** Category IDs */ - "category_ids[]": string + "category_ids[]": string[] | string /** Description */ description?: string /** Homepage Url */ diff --git a/lib/tool_shed_client/schema/__init__.py b/lib/tool_shed_client/schema/__init__.py index 2f4de2cc198f..7a1912bcf017 100644 --- a/lib/tool_shed_client/schema/__init__.py +++ b/lib/tool_shed_client/schema/__init__.py @@ -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",