From c387a39cc324aa518d6be4b78d36007604ed4c6c Mon Sep 17 00:00:00 2001 From: cat-bro Date: Thu, 4 May 2023 20:18:02 +1000 Subject: [PATCH 1/2] Add id to mock_galaxy.User --- tpv/commands/test/mock_galaxy.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tpv/commands/test/mock_galaxy.py b/tpv/commands/test/mock_galaxy.py index 565678a..2097afc 100644 --- a/tpv/commands/test/mock_galaxy.py +++ b/tpv/commands/test/mock_galaxy.py @@ -1,3 +1,5 @@ +import random + from galaxy.model import mapping from galaxy.job_metrics import JobMetrics from galaxy.jobs import JobConfiguration @@ -76,10 +78,11 @@ def __init__(self, job_conf=None, create_model=False): class User: - def __init__(self, username, email, roles=[]): + def __init__(self, username, email, roles=[], id=None): self.username = username self.email = email self.roles = [Role(name) for name in roles] + self.id = id or random.randint(1, 1000000) def all_roles(self): """ From f981ee56f5357cbc2f358f08f527eb470cfe7531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Manuel=20Dom=C3=ADnguez?= Date: Thu, 4 May 2023 12:51:10 +0200 Subject: [PATCH 2/2] Derive id from username whenever not given. --- tpv/commands/test/mock_galaxy.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tpv/commands/test/mock_galaxy.py b/tpv/commands/test/mock_galaxy.py index 2097afc..6f021e9 100644 --- a/tpv/commands/test/mock_galaxy.py +++ b/tpv/commands/test/mock_galaxy.py @@ -1,4 +1,4 @@ -import random +import hashlib from galaxy.model import mapping from galaxy.job_metrics import JobMetrics @@ -82,7 +82,9 @@ def __init__(self, username, email, roles=[], id=None): self.username = username self.email = email self.roles = [Role(name) for name in roles] - self.id = id or random.randint(1, 1000000) + self.id = id or int( + hashlib.sha256(f"{self.username}".encode("utf-8")).hexdigest(), 16 + ) % 1000000 def all_roles(self): """