Skip to content

Commit

Permalink
Get user. (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatascastro12 committed Aug 17, 2023
1 parent b83034c commit acf5cea
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@ def test_create_user(self, mock_user, mock_request_method):
user = self.users.create_user(payload)

assert user["id"] == "user_01H7ZGXFP5C6BBQY6Z7277ZCT0"

def test_get_user(self, mock_user, capture_and_mock_request):
url, request_kwargs = capture_and_mock_request("get", mock_user, 201)

user = self.users.get_user("user_01H7ZGXFP5C6BBQY6Z7277ZCT0")

assert url[0].endswith("users/user_01H7ZGXFP5C6BBQY6Z7277ZCT0")
assert user["id"] == "user_01H7ZGXFP5C6BBQY6Z7277ZCT0"
20 changes: 20 additions & 0 deletions workos/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from workos.utils.request import (
RequestHelper,
REQUEST_METHOD_POST,
REQUEST_METHOD_GET,
)
from workos.utils.validation import validate_settings, USERS_MODULE

Expand Down Expand Up @@ -52,3 +53,22 @@ def create_user(self, user):
)

return WorkOSUser.construct_from_response(response).to_dict()

def get_user(self, user):
"""Get the details of an existing user.
Args:
user (str) - User unique identifier
Returns:
dict: User response from WorkOS.
"""
headers = {}

response = self.request_helper.request(
f"{USER_PATH}/{user}",
method=REQUEST_METHOD_GET,
headers=headers,
token=workos.api_key,
)

return WorkOSUser.construct_from_response(response).to_dict()

0 comments on commit acf5cea

Please sign in to comment.