From 6eb7e1d41f768b1ae848210188251c47156c77aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B4natas=20Santos?= Date: Thu, 17 Aug 2023 11:30:12 -0300 Subject: [PATCH] Get user. (#192) --- tests/test_users.py | 8 ++++++++ workos/users.py | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/tests/test_users.py b/tests/test_users.py index 4b975b77..1c342e1a 100644 --- a/tests/test_users.py +++ b/tests/test_users.py @@ -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" diff --git a/workos/users.py b/workos/users.py index d08c7272..5748e846 100644 --- a/workos/users.py +++ b/workos/users.py @@ -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 @@ -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()