From 406b32ce8cf13931f741b35762ec0c6b9abe4462 Mon Sep 17 00:00:00 2001 From: M Bernt Date: Tue, 9 Jul 2024 13:46:28 +0200 Subject: [PATCH] Test purging user without prior deletion (#488) Co-authored-by: Nicola Soranzo --- bioblend/_tests/TestGalaxyUsers.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/bioblend/_tests/TestGalaxyUsers.py b/bioblend/_tests/TestGalaxyUsers.py index c58e75f41..7296e8fff 100644 --- a/bioblend/_tests/TestGalaxyUsers.py +++ b/bioblend/_tests/TestGalaxyUsers.py @@ -1,4 +1,7 @@ -import bioblend.galaxy +import pytest + +from bioblend import ConnectionError +from bioblend.galaxy import GalaxyInstance from . import ( GalaxyTestBase, test_util, @@ -56,7 +59,7 @@ def test_create_local_user(self): assert new_user["username"] == new_username assert new_user["email"] == new_user_email # test a BioBlend GalaxyInstance can be created using username+password - user_gi = bioblend.galaxy.GalaxyInstance(url=self.gi.base_url, email=new_user_email, password=password) + user_gi = GalaxyInstance(url=self.gi.base_url, email=new_user_email, password=password) assert user_gi.users.get_current_user()["email"] == new_user_email # test deletion and purging if self.gi.config.get_config()["allow_user_deletion"]: @@ -105,6 +108,24 @@ def test_update_user(self): assert purged_user["deleted"] assert purged_user["purged"] + @test_util.skip_unless_galaxy("release_19.09") # for user purging + def test_direct_purge(self): + """ + Test purging without prior deletion + """ + # WARNING: only admins can create users! + if self.gi.config.get_config()["use_remote_user"]: + self.skipTest("This Galaxy instance is not configured to use local users") + if not self.gi.config.get_config()["allow_user_deletion"]: + self.skipTest("This Galaxy instance is not configured to allow user deletion") + new_username = test_util.random_string() + new_user = self.gi.users.create_local_user( + new_username, f"{new_username}@example.org", test_util.random_string(20) + ) + # Purging a user fails if it's not deleted beforehand + with pytest.raises(ConnectionError): + self.gi.users.delete_user(new_user["id"], purge=True) + def test_get_user_apikey(self): # Test getting the API key of the current user, which surely has one user_id = self.gi.users.get_current_user()["id"]