Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update parameter defaults for QuotaClient.update_quota() #489

Merged
merged 10 commits into from
Jul 27, 2024
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