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

Allow to keep quota's default value #478

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions bioblend/_tests/TestGalaxyQuotas.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,31 @@ def test_update_quota(self):
assert quota["operation"] == "-"
assert quota["description"] == "asdf"

def test_update_quota_nondefault(self):
"""
try to update a non-default quota (and leave it non-default)
"""
# 1st make it non-default
response = self.gi.quotas.update_quota(
self.quota["id"],
name=self.quota_name,
description="testing",
default="no",
operation="=",
amount="100 GB",
)
assert f"has been renamed to '{self.quota_name}'" in response
assert f"Quota '{self.quota_name}' is no longer the default for registered users." in response

# update it leaving it non-default
response = self.gi.quotas.update_quota(
self.quota["id"],
name=self.quota_name + "-updated",
)
bernt-matthias marked this conversation as resolved.
Show resolved Hide resolved
assert f"""Quota '{self.quota_name}' has been renamed to '{self.quota_name}-updated'""" in response
quota = self.gi.quotas.show_quota(self.quota["id"])
assert quota["default"] == [] # non-default quotas have []

def test_delete_undelete_quota(self):
self.gi.quotas.update_quota(self.quota["id"], default="no")
response = self.gi.quotas.delete_quota(self.quota["id"])
Expand Down
15 changes: 10 additions & 5 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["+", "-", "="]
QuotaDefault = 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[QuotaDefault] = "no",
in_users: Optional[List[str]] = None,
in_groups: Optional[List[str]] = None,
) -> Dict[str, Any]:
Expand Down Expand Up @@ -142,7 +143,7 @@ def update_quota(
description: Optional[str] = None,
amount: Optional[str] = None,
operation: Optional[QuotaOperations] = None,
default: str = "no",
default: Optional[QuotaDefault] = None,
in_users: Optional[List[str]] = None,
in_groups: Optional[List[str]] = None,
) -> str:
Expand Down Expand Up @@ -171,8 +172,8 @@ def update_quota(
:param default: Whether or not this is a default quota. Valid values
are ``no``, ``unregistered``, ``registered``.
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. None
will leave the default state as it is.

:type in_users: list of str
:param in_users: A list of user IDs or user emails.
Expand All @@ -186,7 +187,11 @@ def update_quota(

"Quota 'Testing-A' has been renamed to 'Testing-B'; Quota 'Testing-e' is now '-100.0 GB'; Quota 'Testing-B' is now the default for unregistered users"
"""
payload: Dict[str, Any] = {"default": default}
payload: Dict[str, Any] = {}

if default:
payload["default"] = default

if name:
payload["name"] = name

Expand Down