diff --git a/bioblend/_tests/TestGalaxyQuotas.py b/bioblend/_tests/TestGalaxyQuotas.py index 4d523f273..701465735 100644 --- a/bioblend/_tests/TestGalaxyQuotas.py +++ b/bioblend/_tests/TestGalaxyQuotas.py @@ -1,6 +1,9 @@ import uuid -from . import GalaxyTestBase +from . import ( + GalaxyTestBase, + test_util, +) class TestGalaxyQuotas(GalaxyTestBase.GalaxyTestBase): @@ -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) diff --git a/bioblend/galaxy/quotas/__init__.py b/bioblend/galaxy/quotas/__init__.py index c0659e785..74d6fd69a 100644 --- a/bioblend/galaxy/quotas/__init__.py +++ b/bioblend/galaxy/quotas/__init__.py @@ -17,6 +17,7 @@ from bioblend.galaxy import GalaxyInstance QuotaOperations = Literal["+", "-", "="] +DefaultQuotaValues = Literal["no", "registered", "unregistered"] class QuotaClient(Client): @@ -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]: @@ -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. @@ -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: @@ -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.