From 6176131a3d46099e135baae059e71301937d554f Mon Sep 17 00:00:00 2001 From: Brad Macdonald Date: Mon, 20 Nov 2023 12:17:45 -0700 Subject: [PATCH] updates id to username and typeerror location --- synapseclient/client.py | 23 +++++++++---------- .../unit_test_get_user_profile.py | 2 +- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/synapseclient/client.py b/synapseclient/client.py index 089ff377e..d0483b576 100644 --- a/synapseclient/client.py +++ b/synapseclient/client.py @@ -624,13 +624,13 @@ def invalidateAPIKey(self): @functools.lru_cache() def get_user_profile_by_username( self, - id: str = None, + username: str = None, sessionToken: str = None, ) -> UserProfile: """ Get the details about a Synapse user. Retrieves information on the current user if 'id' is omitted or is empty string. - :param id: The userName of a user + :param username: The userName of a user :param sessionToken: The session token to use to find the user profile :returns: The user profile for the user of interest. @@ -638,17 +638,16 @@ def get_user_profile_by_username( my_profile = syn.get_user_name_profile() freds_profile = syn.get_user_name_profile('fredcommo') """ - if id: - if isinstance(id, str): - principals = self._findPrincipals(id) - for principal in principals: - if principal.get("userName", None).lower() == id.lower(): - id = principal["ownerId"] - break - else: - raise ValueError(f"Can't find user '{id}'") + if not isinstance(username, str) and username is not None: + raise TypeError("username must be string or None") + if isinstance(username, str): + principals = self._findPrincipals(username) + for principal in principals: + if principal.get("userName", None).lower() == username.lower(): + id = principal["ownerId"] + break else: - raise TypeError("id must be a 'userName' string") + raise ValueError(f"Can't find user '{username}'") else: id = "" uri = f"/userProfile/{id}" diff --git a/tests/unit/synapseclient/unit_test_get_user_profile.py b/tests/unit/synapseclient/unit_test_get_user_profile.py index 9854257cd..f83d9681e 100644 --- a/tests/unit/synapseclient/unit_test_get_user_profile.py +++ b/tests/unit/synapseclient/unit_test_get_user_profile.py @@ -70,7 +70,7 @@ def test_that_get_user_profile_raises_value_error_when_user_does_not_exist(self) self.syn.get_user_profile_by_username("not_a_user") def test_that_get_user_profile_raises_type_error_when_id_is_not_allowed_type(self): - with pytest.raises(TypeError, match="id must be a 'userName' string"): + with pytest.raises(TypeError, match="username must be string or None"): self.syn.get_user_profile_by_username(1234567)