From d5ba358bb6fcfbcdfef9c6d5cd3f2e21865912ee Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Wed, 24 Jul 2024 16:18:41 +0200 Subject: [PATCH 01/10] add test for updating nondefault quotas --- bioblend/_tests/TestGalaxyQuotas.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bioblend/_tests/TestGalaxyQuotas.py b/bioblend/_tests/TestGalaxyQuotas.py index 4d523f273..43620c8a9 100644 --- a/bioblend/_tests/TestGalaxyQuotas.py +++ b/bioblend/_tests/TestGalaxyQuotas.py @@ -52,3 +52,14 @@ 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 + + + def test_update_non_default_quote(self): + user = self.gi.users.create_remote_user("test@test.test") + print(user) + quota = self.gi.quotas.create_quota(name="non_default_quota", description="testing", + amount="100 GB", + operation="+", + in_users=[user['username']], + ) + self.gi.quotas.update_quota(quota["id"], default="no", amount="200 GB") \ No newline at end of file From 57caf7044ecdeab2f6c82e9c7928fbe3b40c09ff Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Wed, 24 Jul 2024 17:19:37 +0200 Subject: [PATCH 02/10] try to fix --- bioblend/_tests/TestGalaxyQuotas.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/bioblend/_tests/TestGalaxyQuotas.py b/bioblend/_tests/TestGalaxyQuotas.py index 43620c8a9..0c5da9055 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): @@ -53,13 +56,21 @@ def test_delete_undelete_quota(self): 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_quote(self): - user = self.gi.users.create_remote_user("test@test.test") - print(user) + 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) + print(new_user) + quota = self.gi.quotas.create_quota(name="non_default_quota", description="testing", amount="100 GB", operation="+", - in_users=[user['username']], + in_users=[new_user['username']], ) - self.gi.quotas.update_quota(quota["id"], default="no", amount="200 GB") \ No newline at end of file + self.gi.quotas.update_quota(quota["id"], default="no", amount="200 GB") + + if self.gi.config.get_config()["allow_user_deletion"]: + deleted_user = self.gi.users.delete_user(new_user["id"]) + purged_user = self.gi.users.delete_user(new_user["id"], purge=True) \ No newline at end of file From 57a0a6d95fb905b4fa7e7be71e60e44849864784 Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Wed, 24 Jul 2024 21:55:07 +0200 Subject: [PATCH 03/10] quota creation needs user id --- bioblend/_tests/TestGalaxyQuotas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bioblend/_tests/TestGalaxyQuotas.py b/bioblend/_tests/TestGalaxyQuotas.py index 0c5da9055..b662b2348 100644 --- a/bioblend/_tests/TestGalaxyQuotas.py +++ b/bioblend/_tests/TestGalaxyQuotas.py @@ -67,7 +67,7 @@ def test_update_non_default_quote(self): quota = self.gi.quotas.create_quota(name="non_default_quota", description="testing", amount="100 GB", operation="+", - in_users=[new_user['username']], + in_users=[new_user['id']], ) self.gi.quotas.update_quota(quota["id"], default="no", amount="200 GB") From 1998f18213a2b43beb6490755689d592857c63da Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Wed, 24 Jul 2024 22:28:55 +0200 Subject: [PATCH 04/10] is this the intended usage --- bioblend/_tests/TestGalaxyQuotas.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bioblend/_tests/TestGalaxyQuotas.py b/bioblend/_tests/TestGalaxyQuotas.py index b662b2348..26e8b33f7 100644 --- a/bioblend/_tests/TestGalaxyQuotas.py +++ b/bioblend/_tests/TestGalaxyQuotas.py @@ -69,7 +69,8 @@ def test_update_non_default_quote(self): operation="+", in_users=[new_user['id']], ) - self.gi.quotas.update_quota(quota["id"], default="no", amount="200 GB") + print(quota) + self.gi.quotas.update_quota(quota["id"], default=None, amount="200 GB") if self.gi.config.get_config()["allow_user_deletion"]: deleted_user = self.gi.users.delete_user(new_user["id"]) From 4bf4843ea2c967acc1f6237963387794f02838d4 Mon Sep 17 00:00:00 2001 From: M Bernt Date: Wed, 24 Jul 2024 21:56:22 +0200 Subject: [PATCH 05/10] Apply suggestions from code review Co-authored-by: Nicola Soranzo --- bioblend/_tests/TestGalaxyQuotas.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bioblend/_tests/TestGalaxyQuotas.py b/bioblend/_tests/TestGalaxyQuotas.py index 26e8b33f7..3b27755a6 100644 --- a/bioblend/_tests/TestGalaxyQuotas.py +++ b/bioblend/_tests/TestGalaxyQuotas.py @@ -57,7 +57,9 @@ def test_delete_undelete_quota(self): assert response == "Undeleted 1 quotas: " + self.quota_name @test_util.skip_unless_galaxy("release_19.09") # for user purging - def test_update_non_default_quote(self): + def test_update_non_default_quota(self): + 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) @@ -73,5 +75,5 @@ def test_update_non_default_quote(self): self.gi.quotas.update_quota(quota["id"], default=None, amount="200 GB") if self.gi.config.get_config()["allow_user_deletion"]: - deleted_user = self.gi.users.delete_user(new_user["id"]) - purged_user = self.gi.users.delete_user(new_user["id"], purge=True) \ No newline at end of file + self.gi.users.delete_user(new_user["id"]) + self.gi.users.delete_user(new_user["id"], purge=True) \ No newline at end of file From 3086d3b3df46929c843b702138e6308da67f750f Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Thu, 25 Jul 2024 11:42:35 +0200 Subject: [PATCH 06/10] fix linting --- bioblend/_tests/TestGalaxyQuotas.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/bioblend/_tests/TestGalaxyQuotas.py b/bioblend/_tests/TestGalaxyQuotas.py index 3b27755a6..26276c366 100644 --- a/bioblend/_tests/TestGalaxyQuotas.py +++ b/bioblend/_tests/TestGalaxyQuotas.py @@ -58,22 +58,26 @@ def test_delete_undelete_quota(self): @test_util.skip_unless_galaxy("release_19.09") # for user purging def test_update_non_default_quota(self): + """ + test if a non default quota can be updated (needs to use default=None, + 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) - print(new_user) - quota = self.gi.quotas.create_quota(name="non_default_quota", description="testing", - amount="100 GB", - operation="+", - in_users=[new_user['id']], - ) - print(quota) + 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"], default=None, 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) \ No newline at end of file + self.gi.users.delete_user(new_user["id"], purge=True) From 904ad43250d7960d54d776d6172db2116424f8a0 Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Thu, 25 Jul 2024 16:19:56 +0100 Subject: [PATCH 07/10] Change default value of ``default`` parameter of ``QuotaClient.update_quota()`` to None --- bioblend/galaxy/quotas/__init__.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/bioblend/galaxy/quotas/__init__.py b/bioblend/galaxy/quotas/__init__.py index c0659e785..0732003c6 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. @@ -142,7 +143,7 @@ def update_quota( description: Optional[str] = None, amount: Optional[str] = None, operation: Optional[QuotaOperations] = None, - default: str = "no", + 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. From 2da218ade83e1810567a4c7062a57bc2170115d6 Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Thu, 25 Jul 2024 16:57:27 +0100 Subject: [PATCH 08/10] 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. --- bioblend/galaxy/quotas/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bioblend/galaxy/quotas/__init__.py b/bioblend/galaxy/quotas/__init__.py index 0732003c6..74d6fd69a 100644 --- a/bioblend/galaxy/quotas/__init__.py +++ b/bioblend/galaxy/quotas/__init__.py @@ -142,7 +142,7 @@ def update_quota( name: Optional[str] = None, description: Optional[str] = None, amount: Optional[str] = None, - operation: Optional[QuotaOperations] = None, + operation: Optional[QuotaOperations] = "=", default: Optional[DefaultQuotaValues] = None, in_users: Optional[List[str]] = None, in_groups: Optional[List[str]] = None, From 9ee0dc1b4f2359818759d9ebdeb458625689cd7a Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Sat, 27 Jul 2024 04:09:41 +0100 Subject: [PATCH 09/10] Update test docstring Co-authored-by: M Bernt --- bioblend/_tests/TestGalaxyQuotas.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bioblend/_tests/TestGalaxyQuotas.py b/bioblend/_tests/TestGalaxyQuotas.py index 26276c366..391c7e36d 100644 --- a/bioblend/_tests/TestGalaxyQuotas.py +++ b/bioblend/_tests/TestGalaxyQuotas.py @@ -59,8 +59,8 @@ def test_delete_undelete_quota(self): @test_util.skip_unless_galaxy("release_19.09") # for user purging def test_update_non_default_quota(self): """ - test if a non default quota can be updated (needs to use default=None, - default="no" will fail) + 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") From ea361441923448d73a449c2e9beb1dfa8486f231 Mon Sep 17 00:00:00 2001 From: M Bernt Date: Sat, 27 Jul 2024 11:10:46 +0200 Subject: [PATCH 10/10] Apply suggestions from code review --- bioblend/_tests/TestGalaxyQuotas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bioblend/_tests/TestGalaxyQuotas.py b/bioblend/_tests/TestGalaxyQuotas.py index 391c7e36d..701465735 100644 --- a/bioblend/_tests/TestGalaxyQuotas.py +++ b/bioblend/_tests/TestGalaxyQuotas.py @@ -76,7 +76,7 @@ def test_update_non_default_quota(self): operation="+", in_users=[new_user["id"]], ) - self.gi.quotas.update_quota(quota["id"], default=None, amount="200 GB") + 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"])