Skip to content

Commit

Permalink
updates id to username and typeerror location
Browse files Browse the repository at this point in the history
  • Loading branch information
BWMac committed Nov 20, 2023
1 parent 833b460 commit 6176131
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
23 changes: 11 additions & 12 deletions synapseclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,31 +624,30 @@ 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.
Example::
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}"
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/synapseclient/unit_test_get_user_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 6176131

Please sign in to comment.