Skip to content

Commit

Permalink
Update parameter defaults for QuotaClient.update_quota() (galaxyp…
Browse files Browse the repository at this point in the history
…roject#489)

* add test for updating nondefault quotas

* try to fix

* quota creation needs user id

* is this the intended usage

* Apply suggestions from code review

Co-authored-by: Nicola Soranzo <[email protected]>

* fix linting

* Change default value of ``default`` parameter of ``QuotaClient.update_quota()`` to None

* Change default value of ``operation`` parameter of ``QuotaClient.update_quota()`` to "="

which is the same of the Galaxy API since 21.09 and makes the
``test_update_non_default_quota`` pass for Galaxy <21.09 without
having to specify the ``operation`` parameter.

* Update test docstring

Co-authored-by: M Bernt <[email protected]>

* Apply suggestions from code review

---------

Co-authored-by: Nicola Soranzo <[email protected]>
Co-authored-by: Nicola Soranzo <[email protected]>
  • Loading branch information
3 people authored Jul 27, 2024
1 parent 1cdb330 commit 5b6cb7a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
31 changes: 30 additions & 1 deletion bioblend/_tests/TestGalaxyQuotas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import uuid

from . import GalaxyTestBase
from . import (
GalaxyTestBase,
test_util,
)


class TestGalaxyQuotas(GalaxyTestBase.GalaxyTestBase):
Expand Down Expand Up @@ -52,3 +55,29 @@ def test_delete_undelete_quota(self):
assert response == "Deleted 1 quotas: " + self.quota_name
response = self.gi.quotas.undelete_quota(self.quota["id"])
assert response == "Undeleted 1 quotas: " + self.quota_name

@test_util.skip_unless_galaxy("release_19.09") # for user purging
def test_update_non_default_quota(self):
"""
Test updating a non default quota.
Needs to use `default=None` (which is the default), `default="no"` will fail.
"""
if self.gi.config.get_config()["use_remote_user"]:
self.skipTest("This Galaxy instance is not configured to use local users")
new_username = test_util.random_string()
new_user_email = f"{new_username}@example.org"
password = test_util.random_string(20)
new_user = self.gi.users.create_local_user(new_username, new_user_email, password)

quota = self.gi.quotas.create_quota(
name="non_default_quota",
description="testing",
amount="100 GB",
operation="+",
in_users=[new_user["id"]],
)
self.gi.quotas.update_quota(quota["id"], amount="200 GB")

if self.gi.config.get_config()["allow_user_deletion"]:
self.gi.users.delete_user(new_user["id"])
self.gi.users.delete_user(new_user["id"], purge=True)
17 changes: 9 additions & 8 deletions bioblend/galaxy/quotas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from bioblend.galaxy import GalaxyInstance

QuotaOperations = Literal["+", "-", "="]
DefaultQuotaValues = Literal["no", "registered", "unregistered"]


class QuotaClient(Client):
Expand Down Expand Up @@ -80,7 +81,7 @@ def create_quota(
description: str,
amount: str,
operation: QuotaOperations,
default: Optional[Literal["no", "registered", "unregistered"]] = "no",
default: Optional[DefaultQuotaValues] = "no",
in_users: Optional[List[str]] = None,
in_groups: Optional[List[str]] = None,
) -> Dict[str, Any]:
Expand All @@ -101,8 +102,8 @@ def create_quota(
:type default: str
:param default: Whether or not this is a default quota. Valid values
are ``no``, ``unregistered``, ``registered``. None is
equivalent to ``no``.
are "no", "unregistered", "registered" and None. None is
equivalent to "no".
:type in_users: list of str
:param in_users: A list of user IDs or user emails.
Expand Down Expand Up @@ -141,8 +142,8 @@ def update_quota(
name: Optional[str] = None,
description: Optional[str] = None,
amount: Optional[str] = None,
operation: Optional[QuotaOperations] = None,
default: str = "no",
operation: Optional[QuotaOperations] = "=",
default: Optional[DefaultQuotaValues] = None,
in_users: Optional[List[str]] = None,
in_groups: Optional[List[str]] = None,
) -> str:
Expand All @@ -169,10 +170,10 @@ def update_quota(
:type default: str
:param default: Whether or not this is a default quota. Valid values
are ``no``, ``unregistered``, ``registered``.
are "no", "unregistered", "registered" and None.
Calling this method with ``default="no"`` on a
non-default quota will throw an error. Not
passing this parameter is equivalent to passing ``no``.
non-default quota will throw an error. Passing None is
equivalent to not changing the current status.
:type in_users: list of str
:param in_users: A list of user IDs or user emails.
Expand Down

0 comments on commit 5b6cb7a

Please sign in to comment.